mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-23 09:59:12 +00:00
Compare commits
89 Commits
@now/pytho
...
@vercel/no
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b626f3fe57 | ||
|
|
96bc0c9bee | ||
|
|
f4ff8c0268 | ||
|
|
1a5681f287 | ||
|
|
88b66ae646 | ||
|
|
db0124782a | ||
|
|
a7a5d4d169 | ||
|
|
4b39e96c28 | ||
|
|
f459db9f83 | ||
|
|
ad19021969 | ||
|
|
95e41874e4 | ||
|
|
4d20a1d77b | ||
|
|
325ee261cb | ||
|
|
2e0cee490d | ||
|
|
8a9b67a3f3 | ||
|
|
f1d9a5da96 | ||
|
|
8d9c463e1f | ||
|
|
e07e8f841a | ||
|
|
0b8a2c0dab | ||
|
|
9c2b7132fa | ||
|
|
d4639a5108 | ||
|
|
ba25004ea8 | ||
|
|
639a9b03d2 | ||
|
|
28ffdfbeef | ||
|
|
5e222d3c03 | ||
|
|
94c8464728 | ||
|
|
898478d1e1 | ||
|
|
8a68211cad | ||
|
|
2765207c93 | ||
|
|
6b52cfdbc7 | ||
|
|
f474fa1b8c | ||
|
|
2cdee19804 | ||
|
|
e9066a3ead | ||
|
|
1461fbe331 | ||
|
|
099bc6dbf6 | ||
|
|
fe0d762aca | ||
|
|
07c9c0bb6e | ||
|
|
243018b736 | ||
|
|
99436b986a | ||
|
|
dfdef0f6fd | ||
|
|
921327d878 | ||
|
|
c48fd3e891 | ||
|
|
5142e32bed | ||
|
|
d360169b06 | ||
|
|
7b1893b9f7 | ||
|
|
fb07360b71 | ||
|
|
3a00aed989 | ||
|
|
64944f8926 | ||
|
|
5e4eee4db1 | ||
|
|
a1a5e0ef0d | ||
|
|
91b9b7f880 | ||
|
|
8e29924165 | ||
|
|
9083b558f0 | ||
|
|
0bf8c3751b | ||
|
|
3ef832fdbe | ||
|
|
4bc6ebe286 | ||
|
|
5660474739 | ||
|
|
e85a62703c | ||
|
|
3a3cfd4d7b | ||
|
|
9570d64b67 | ||
|
|
e77ea00e9d | ||
|
|
aebe77d222 | ||
|
|
53cb2cc4c5 | ||
|
|
4d75ed5117 | ||
|
|
e6c84dd70b | ||
|
|
d51f0d0f06 | ||
|
|
4cd35c48a2 | ||
|
|
69ac4f3eb8 | ||
|
|
2c9cbe20f3 | ||
|
|
4ddd2f016c | ||
|
|
76f61cbbf0 | ||
|
|
23fe8affec | ||
|
|
5334caad54 | ||
|
|
103e4117c3 | ||
|
|
3e774d0531 | ||
|
|
5e2139f408 | ||
|
|
55e4bffcd2 | ||
|
|
de3a066934 | ||
|
|
257b0ca5b6 | ||
|
|
e826d48814 | ||
|
|
d4ecfb04bb | ||
|
|
cad10e1918 | ||
|
|
1e221c48f9 | ||
|
|
15221bf19c | ||
|
|
2513fecaf4 | ||
|
|
d723d985e3 | ||
|
|
2d0a71946b | ||
|
|
4b7af4d7d3 | ||
|
|
8e3f4a1ca2 |
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@@ -92,7 +92,7 @@ Sometimes you want to test changes to a Builder against an existing project, may
|
||||
2. Run `yarn build` to compile typescript and other build steps
|
||||
3. Run `npm pack` to create a tarball file
|
||||
4. Run `now *.tgz` to upload the tarball file and get a URL
|
||||
5. Edit any existing `now.json` project and replace `use` with the URL
|
||||
5. Edit any existing `vercel.json` project and replace `use` with the URL
|
||||
6. Run `now` or `now dev` to deploy with the experimental Builder
|
||||
|
||||
## Add a New Framework
|
||||
|
||||
2
.github/workflows/cancel.yml
vendored
2
.github/workflows/cancel.yml
vendored
@@ -2,7 +2,7 @@ name: Cancel
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
- '**'
|
||||
- '!master'
|
||||
|
||||
jobs:
|
||||
|
||||
3
.github/workflows/test-integration-cli.yml
vendored
3
.github/workflows/test-integration-cli.yml
vendored
@@ -22,9 +22,6 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- run: git fetch origin master --depth=10
|
||||
- run: git fetch origin ${{ github.ref }} --depth=10
|
||||
- name: Install Hugo
|
||||
if: matrix.os == 'macos-latest'
|
||||
run: curl -L -O https://github.com/gohugoio/hugo/releases/download/v0.56.0/hugo_0.56.0_macOS-64bit.tar.gz && tar -xzf hugo_0.56.0_macOS-64bit.tar.gz && mv ./hugo packages/now-cli/test/dev/fixtures/08-hugo/
|
||||
- run: yarn install
|
||||
- run: yarn run build
|
||||
- uses: actions/setup-node@v1
|
||||
|
||||
5
.github/workflows/test-integration-dev.yml
vendored
5
.github/workflows/test-integration-dev.yml
vendored
@@ -11,7 +11,7 @@ on:
|
||||
jobs:
|
||||
test:
|
||||
name: Dev
|
||||
timeout-minutes: 30
|
||||
timeout-minutes: 45
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -31,3 +31,6 @@ jobs:
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
- run: yarn test-integration-dev --clean false
|
||||
env:
|
||||
ZEIT_TEAM_TOKEN: ${{ secrets.ZEIT_TEAM_TOKEN }}
|
||||
ZEIT_REGISTRATION_URL: ${{ secrets.ZEIT_REGISTRATION_URL }}
|
||||
|
||||
7
.github/workflows/test-unit.yml
vendored
7
.github/workflows/test-unit.yml
vendored
@@ -25,9 +25,10 @@ jobs:
|
||||
- uses: actions/setup-node@v1
|
||||
- run: yarn install
|
||||
- run: yarn run build
|
||||
- run: yarn run test-lint
|
||||
- run: yarn run lint
|
||||
if: matrix.os == 'ubuntu-latest' && matrix.node == 12 # only run lint once
|
||||
- run: yarn run test-unit --clean false
|
||||
- run: yarn workspace now run coverage
|
||||
if: matrix.os == 'ubuntu-latest' && matrix.node == 12 # only run once
|
||||
- run: yarn workspace vercel run coverage
|
||||
if: matrix.os == 'ubuntu-latest' && matrix.node == 12 # only run coverage once
|
||||
env:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,6 +6,7 @@ npm-debug.log
|
||||
yarn-error.log
|
||||
.nyc_output
|
||||
coverage
|
||||
coverage.lcov
|
||||
*.swp
|
||||
*.bak
|
||||
*.tgz
|
||||
@@ -19,6 +20,8 @@ packages/now-cli/test/**/node_modules
|
||||
packages/now-cli/test/dev/fixtures/08-hugo/hugo
|
||||
packages/now-cli/test/dev/fixtures/**/dist
|
||||
packages/now-cli/test/dev/fixtures/**/public
|
||||
packages/now-cli/test/dev/fixtures/**/.now
|
||||
packages/now-cli/test/dev/fixtures/**/.vercel
|
||||
packages/now-cli/test/fixtures/integration
|
||||
test/lib/deployment/failed-page.txt
|
||||
.DS_Store
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
The following page is a reference for how to create a Runtime using the available Runtime API.
|
||||
|
||||
A Runtime is an npm module that exposes a `build` function and optionally an `analyze` function and `prepareCache` function.
|
||||
Official Runtimes are published to [npmjs.com](https://npmjs.com) as a package and referenced in the `use` property of the `now.json` configuration file.
|
||||
Official Runtimes are published to [npmjs.com](https://npmjs.com) as a package and referenced in the `use` property of the `vercel.json` configuration file.
|
||||
However, the `use` property will work with any [npm install argument](https://docs.npmjs.com/cli/install) such as a git repo url which is useful for testing your Runtime.
|
||||
|
||||
See the [Runtimes Documentation](https://vercel.com/docs/runtimes) to view example usage.
|
||||
@@ -143,7 +143,7 @@ The exported functions [`analyze`](#analyze), [`build`](#build), and [`prepareCa
|
||||
- `entrypoint`: Name of entrypoint file for this particular build job. Value `files[entrypoint]` is guaranteed to exist and be a valid [File](#files) reference. `entrypoint` is always a discrete file and never a glob, since globs are expanded into separate builds at deployment time.
|
||||
- `workPath`: A writable temporary directory where you are encouraged to perform your build process. This directory will be populated with the restored cache from the previous run (if any) for [`analyze`](#analyze) and [`build`](#build).
|
||||
- `cachePath`: A writable temporary directory where you can build a cache for the next run. This is only passed to `prepareCache`.
|
||||
- `config`: An arbitrary object passed from by the user in the [Build definition](#defining-the-build-step) in `now.json`.
|
||||
- `config`: An arbitrary object passed from by the user in the [Build definition](#defining-the-build-step) in `vercel.json`.
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
10
README.md
10
README.md
@@ -1,11 +1,15 @@
|
||||

|
||||
<p align="center">
|
||||
<img src="https://assets.vercel.com/image/upload/v1588805858/repositories/vercel/logo.png" height="96">
|
||||
<h3 align="center">Vercel</h3>
|
||||
<p align="center">Develop. Preview. Ship.</p>
|
||||
</p>
|
||||
|
||||
[](https://github.com/zeit/now/actions?workflow=CI)
|
||||
[](https://github.com/zeit/now/discussions)
|
||||
|
||||
## Usage
|
||||
|
||||
Get started by [Importing a Git Project](https://vercel.com/import) and use `git push` to deploy. Alternatively, you can [install Now CLI](https://vercel.com/download).
|
||||
Get started by [Importing a Git Project](https://vercel.com/import) and use `git push` to deploy. Alternatively, you can [install Vercel CLI](https://vercel.com/download).
|
||||
|
||||
## Documentation
|
||||
|
||||
@@ -17,7 +21,7 @@ For details on how to use Vercel, check out our [documentation](https://vercel.c
|
||||
2. Install dependencies with `yarn install`
|
||||
3. Compile the code: `yarn build`
|
||||
4. Link the package to the global module directory: `cd ./packages/now-cli && yarn link`
|
||||
5. You can now start using `now` anywhere inside the command line
|
||||
5. You can start using `vercel` anywhere inside the command line
|
||||
|
||||
As always, you should use `yarn test-unit` to run the tests and see if your changes have broken anything.
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ export function withApiHandler(handler: Handler): Handler {
|
||||
}
|
||||
|
||||
if (req.method !== 'GET') {
|
||||
return res.status(404).json({
|
||||
return res.status(405).json({
|
||||
error: {
|
||||
code: 'not_found',
|
||||
code: 'method_not_allowed',
|
||||
message: 'Only GET requests are supported for this endpoint.',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -19,5 +19,8 @@ export default withApiHandler(async function(
|
||||
req: NowRequest,
|
||||
res: NowResponse
|
||||
) {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET');
|
||||
res.setHeader('Access-Control-Allow-Headers', 'Authorization, Accept, Content-Type');
|
||||
return res.status(200).json(frameworks);
|
||||
});
|
||||
|
||||
@@ -7,9 +7,9 @@ used an unknown or invalid dc identifier.
|
||||
|
||||
#### Possible Ways to Fix It
|
||||
|
||||
Check your `now.json` or `--regions` flag and
|
||||
Check your `vercel.json` or `--regions` flag and
|
||||
make sure you are using a valid string. Regions
|
||||
and DCs have to be in *lowercase*.
|
||||
and DCs have to be in _lowercase_.
|
||||
|
||||
**Valid region identifiers**:
|
||||
|
||||
@@ -19,7 +19,7 @@ and DCs have to be in *lowercase*.
|
||||
- `gru`
|
||||
- `iad`
|
||||
|
||||
In `now-cli`, they currently are transformed to
|
||||
In `now-cli`, they currently are transformed to
|
||||
DC identifiers before being sent to our APIs.
|
||||
|
||||
**Valid DC identifiers**:
|
||||
|
||||
@@ -8,4 +8,4 @@ The `--token` flag was specified, but its contents are invalid.
|
||||
|
||||
The `--token` flag must only contain numbers (0-9) and letters from the alphabet (a-z and A-Z). This needs to be the token of the user account as which you'd like to act.
|
||||
|
||||
You can either get the token from the `./now/auth.json` file located in your user directory or [from the dashboard](https://vercel.com/account/tokens).
|
||||
You can either get the token from the `./vercel/auth.json` file located in your user directory or [from the dashboard](https://vercel.com/account/tokens).
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#### Why This Error Occurred
|
||||
|
||||
You ran `now dev` inside a project that contains a `now.json` file with `env` or `build.env` properties that use [Now Secrets](https://vercel.com/docs/v2/build-step#environment-variables).
|
||||
You ran `now dev` inside a project that contains a `vercel.json` file with `env` or `build.env` properties that use [Now Secrets](https://vercel.com/docs/v2/build-step#environment-variables).
|
||||
|
||||
In order to use environment variables in your project locally that have values defined using the Now Secrets format (e.g. `@my-secret-value`), you will need to provide the value as an environment variable using a `.env` or `.env.build` file.
|
||||
|
||||
|
||||
@@ -8,4 +8,4 @@ The `--token` flag was specified, but there's no value for it available.
|
||||
|
||||
In order to make it work, you need to specify a value for the `--token` flag. This needs to be the token of the user account as which you'd like to act.
|
||||
|
||||
You can either get the token from the `./now/auth.json` file located in your user directory or [from the dashboard](https://vercel.com/account/tokens).
|
||||
You can either get the token from the `./vercel/auth.json` file located in your user directory or [from the dashboard](https://vercel.com/account/tokens).
|
||||
|
||||
@@ -6,5 +6,5 @@ You're running Now CLI in a non-terminal context and there are no credentials av
|
||||
|
||||
#### Possible Ways to Fix It
|
||||
|
||||
- Specify a value for the `--token` flag (this needs to be the token of the user account as which you'd like to act). You can either get the token from the `./now/auth.json` file located in your user directory or [from the dashboard](https://vercel.com/account/tokens).
|
||||
- Ensure that both `~/now/auth.json` and `~/now/config.json` exist
|
||||
- Specify a value for the `--token` flag (this needs to be the token of the user account as which you'd like to act). You can either get the token from the `./vercel/auth.json` file located in your user directory or [from the dashboard](https://vercel.com/account/tokens).
|
||||
- Ensure that both `~/vercel/auth.json` and `~/vercel/config.json` exist
|
||||
|
||||
11
errors/now-next-routes-manifest.md
Normal file
11
errors/now-next-routes-manifest.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Routes Manifest Could Not Be Found
|
||||
|
||||
#### Why This Error Occurred
|
||||
|
||||
This could be caused by a failure during the build or an incorrect output directory being configured for your Next.js project.
|
||||
|
||||
#### Possible Ways to Fix It
|
||||
|
||||
Check for any build errors in the logs and ensure that the output directory setting is either not changed or is pointing to the location of the `.next` output folder (`distDir`).
|
||||
|
||||
If you are running `next export` you should **not** need to customize the output directory to `out` since the builder automatically detects `next export` being run and uses the output from it.
|
||||
@@ -7,11 +7,10 @@ setting. This isn't supported yet.
|
||||
|
||||
#### Possible Ways to Fix It
|
||||
|
||||
Ensure your scale settings (in `now.json`, the command you're running
|
||||
Ensure your scale settings (in `vercel.json`, the command you're running
|
||||
or from a previous deployment who's alias you're trying to overwrite) has
|
||||
the `min` scale setting set to `0`. You can do this by running
|
||||
the `min` scale setting set to `0`. You can do this by running
|
||||
|
||||
```
|
||||
now scale <deployment> 0 10
|
||||
```
|
||||
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
<svg width="82" height="16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill="url(#prefix__paint0_linear)" d="M9.018 0l9.019 16H0L9.018 0z"/>
|
||||
<path fill="#333" fill-rule="evenodd" d="M51.634 12.028h-6.492V2.052h6.492v1.256H46.61v3.007h4.37V7.57h-4.37v3.202h5.024v1.255zm-14.063 0h-7.235v-1.096l5.342-7.624h-5.253V2.052h7.058v1.097l-5.342 7.623h5.43v1.256zm21.88 0h6.333v-1.256h-2.423V3.308h2.423V2.052h-6.332v1.256h2.441v7.465h-2.441v1.255zm18.22 0h-1.468v-8.72h-3.36V2.052h8.225v1.256H77.67v8.72z" clip-rule="evenodd"/>
|
||||
<defs>
|
||||
<linearGradient id="prefix__paint0_linear" x1="28.022" x2="16.189" y1="22.991" y2="8.569" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#fff"/>
|
||||
<stop offset="1"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<svg width="70" height="16" viewBox="0 0 70 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M9.255.05l9.108 15.753H.148L9.255.05zM39.434 8.418c0-2.535-1.87-4.307-4.554-4.307-2.683 0-4.554 1.772-4.554 4.307 0 2.487 2.019 4.308 4.8 4.308 1.526 0 2.905-.566 3.79-1.6l-1.673-.96c-.517.517-1.28.837-2.117.837-1.23 0-2.29-.665-2.658-1.674l-.074-.172h6.966a3.76 3.76 0 00.074-.739zm-7.065-.738l.05-.148c.32-1.058 1.255-1.698 2.436-1.698 1.207 0 2.117.64 2.437 1.698l.05.148h-4.973zM65.945 8.418c0-2.535-1.871-4.307-4.554-4.307-2.683 0-4.554 1.772-4.554 4.307 0 2.487 2.018 4.308 4.8 4.308 1.526 0 2.904-.566 3.79-1.6l-1.673-.96c-.517.517-1.28.837-2.117.837-1.23 0-2.29-.665-2.659-1.674l-.073-.172h6.966a3.76 3.76 0 00.074-.739zM58.88 7.68l.05-.148c.32-1.058 1.255-1.698 2.436-1.698 1.206 0 2.117.64 2.437 1.698l.05.148H58.88zM54.13 7.015l1.673-.96c-.788-1.23-2.19-1.92-3.89-1.92-2.682 0-4.553 1.773-4.553 4.308 0 2.536 1.87 4.308 4.554 4.308 1.698 0 3.101-.69 3.89-1.92l-1.675-.96c-.443.738-1.23 1.157-2.215 1.157-1.55 0-2.585-1.034-2.585-2.585 0-1.55 1.034-2.585 2.585-2.585.96 0 1.772.419 2.215 1.157zM69.637 1.428h-1.97v11.077h1.97V1.428zM31.779 1.428h-2.265L25.182 8.91l-4.333-7.483H18.56l6.622 11.421 6.597-11.421zM45.71 6.4c.222 0 .444.025.665.074V4.382c-1.673.049-3.249.984-3.249 2.141V4.382h-1.97v8.123h1.97v-3.52c0-1.527 1.059-2.585 2.585-2.585z" fill="#000"/>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 794 B After Width: | Height: | Size: 1.4 KiB |
25
lerna.json
25
lerna.json
@@ -1,14 +1,13 @@
|
||||
{
|
||||
"npmClient": "yarn",
|
||||
"useWorkspaces": true,
|
||||
"packages": ["packages/*"],
|
||||
"command": {
|
||||
"publish": {
|
||||
"npmClient": "npm",
|
||||
"allowBranch": ["master", "canary"],
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
}
|
||||
},
|
||||
"version": "independent"
|
||||
}
|
||||
|
||||
"npmClient": "yarn",
|
||||
"useWorkspaces": true,
|
||||
"packages": ["packages/*"],
|
||||
"command": {
|
||||
"publish": {
|
||||
"npmClient": "npm",
|
||||
"allowBranch": ["master"],
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
}
|
||||
},
|
||||
"version": "independent"
|
||||
}
|
||||
|
||||
15
package.json
15
package.json
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "now-builders",
|
||||
"name": "vercel-monorepo",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
@@ -22,10 +22,12 @@
|
||||
"buffer-replace": "1.0.0",
|
||||
"eslint": "6.2.2",
|
||||
"eslint-config-prettier": "6.1.0",
|
||||
"eslint-plugin-jest": "23.8.2",
|
||||
"husky": "3.0.4",
|
||||
"json5": "2.1.1",
|
||||
"lint-staged": "9.2.5",
|
||||
"node-fetch": "2.6.0",
|
||||
"npm-package-arg": "6.1.0",
|
||||
"prettier": "1.18.2"
|
||||
},
|
||||
"scripts": {
|
||||
@@ -36,7 +38,7 @@
|
||||
"publish-from-github": "./utils/publish.sh",
|
||||
"changelog": "node utils/changelog.js",
|
||||
"build": "node utils/run.js build all",
|
||||
"test-lint": "node utils/run.js test-lint",
|
||||
"now-build": "mkdir -p public && echo '<a href=\"https://vercel.com/import\">Import</a>' > public/output.html",
|
||||
"test-unit": "node utils/run.js test-unit",
|
||||
"test-integration-cli": "node utils/run.js test-integration-cli",
|
||||
"test-integration-once": "node utils/run.js test-integration-once",
|
||||
@@ -71,6 +73,9 @@
|
||||
"sourceType": "module",
|
||||
"modules": true
|
||||
},
|
||||
"plugins": [
|
||||
"jest"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
@@ -89,8 +94,12 @@
|
||||
"@typescript-eslint/camelcase": 0,
|
||||
"@typescript-eslint/explicit-function-return-type": 0,
|
||||
"@typescript-eslint/no-empty-function": 0,
|
||||
"@typescript-eslint/no-explicit-any": 0,
|
||||
"@typescript-eslint/no-non-null-assertion": 0,
|
||||
"@typescript-eslint/no-unused-vars": 2,
|
||||
"@typescript-eslint/no-use-before-define": 0
|
||||
"@typescript-eslint/no-use-before-define": 0,
|
||||
"jest/no-disabled-tests": 2,
|
||||
"jest/no-focused-tests": 2
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/frameworks",
|
||||
"version": "0.0.13",
|
||||
"name": "@vercel/frameworks",
|
||||
"version": "0.0.14",
|
||||
"main": "frameworks.json",
|
||||
"license": "UNLICENSED"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/build-utils",
|
||||
"version": "2.2.2-canary.2",
|
||||
"name": "@vercel/build-utils",
|
||||
"version": "2.3.0",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.js",
|
||||
@@ -12,8 +12,8 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "./build.sh",
|
||||
"test-unit": "jest --env node --verbose --runInBand test/unit.*test.*",
|
||||
"test-integration-once": "jest --env node --verbose --runInBand test/integration.test.js",
|
||||
"test-unit": "jest --env node --verbose --runInBand --bail test/unit.*test.*",
|
||||
"test-integration-once": "jest --env node --verbose --runInBand --bail test/integration.test.js",
|
||||
"prepublishOnly": "./build.sh"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { getPlatformEnv } from './';
|
||||
|
||||
export default function debug(message: string, ...additional: any[]) {
|
||||
if (process.env.NOW_BUILDER_DEBUG) {
|
||||
if (getPlatformEnv('BUILDER_DEBUG')) {
|
||||
console.log(message, ...additional);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import minimatch from 'minimatch';
|
||||
import { valid as validSemver } from 'semver';
|
||||
import { parse as parsePath, extname } from 'path';
|
||||
import { Route, Source } from '@now/routing-utils';
|
||||
import { Route, Source } from '@vercel/routing-utils';
|
||||
import { PackageJson, Builder, Config, BuilderFunctions } from './types';
|
||||
import { isOfficialRuntime } from './';
|
||||
|
||||
interface ErrorResponse {
|
||||
code: string;
|
||||
@@ -55,7 +56,7 @@ export function detectApiDirectory(builders: Builder[]): string | null {
|
||||
function getPublicBuilder(builders: Builder[]): Builder | null {
|
||||
const builder = builders.find(
|
||||
builder =>
|
||||
builder.use === '@now/static' &&
|
||||
isOfficialRuntime('static', builder.use) &&
|
||||
/^.*\/\*\*\/\*$/.test(builder.src) &&
|
||||
builder.config &&
|
||||
builder.config.zeroConfig === true
|
||||
@@ -194,7 +195,8 @@ export async function detectBuilders(
|
||||
!fallbackEntrypoint &&
|
||||
buildCommand &&
|
||||
!fileName.includes('/') &&
|
||||
fileName !== 'now.json'
|
||||
fileName !== 'now.json' &&
|
||||
fileName !== 'vercel.json'
|
||||
) {
|
||||
fallbackEntrypoint = fileName;
|
||||
}
|
||||
@@ -593,7 +595,7 @@ function checkUnusedFunctions(
|
||||
}
|
||||
|
||||
// Next.js can use functions only for `src/pages` or `pages`
|
||||
if (frontendBuilder && frontendBuilder.use.startsWith('@now/next')) {
|
||||
if (frontendBuilder && isOfficialRuntime('next', frontendBuilder.use)) {
|
||||
for (const fnKey of unusedFunctions.values()) {
|
||||
if (fnKey.startsWith('pages/') || fnKey.startsWith('src/pages')) {
|
||||
unusedFunctions.delete(fnKey);
|
||||
@@ -958,7 +960,7 @@ function getRouteResult(
|
||||
outputDirectory &&
|
||||
frontendBuilder &&
|
||||
!options.featHandleMiss &&
|
||||
frontendBuilder.use === '@now/static'
|
||||
isOfficialRuntime('static', frontendBuilder.use)
|
||||
) {
|
||||
defaultRoutes.push({
|
||||
src: '/(.*)',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Framework, FrameworkDetectionItem } from '@now/frameworks';
|
||||
import { Framework, FrameworkDetectionItem } from '@vercel/frameworks';
|
||||
import { DetectorFilesystem } from './detectors/filesystem';
|
||||
|
||||
export interface DetectFrameworkOptions {
|
||||
|
||||
@@ -23,7 +23,7 @@ interface Props {
|
||||
message: string;
|
||||
/**
|
||||
* A unique error code for this particular error.
|
||||
* Should start with the builder name such as `NOW_NODE_`.
|
||||
* Should start with the builder name such as `NODE_`.
|
||||
*/
|
||||
code: string;
|
||||
/**
|
||||
|
||||
@@ -54,7 +54,7 @@ export async function getSupportedNodeVersion(
|
||||
engineRange +
|
||||
'".';
|
||||
throw new NowBuildError({
|
||||
code: 'NOW_BUILD_UTILS_NODE_VERSION_INVALID',
|
||||
code: 'BUILD_UTILS_NODE_VERSION_INVALID',
|
||||
link:
|
||||
'https://vercel.com/docs/runtimes#official-runtimes/node-js/node-js-version',
|
||||
message: intro + '\n' + pleaseSet,
|
||||
@@ -72,7 +72,7 @@ export async function getSupportedNodeVersion(
|
||||
engineRange +
|
||||
'".';
|
||||
throw new NowBuildError({
|
||||
code: 'NOW_BUILD_UTILS_NODE_VERSION_DISCONTINUED',
|
||||
code: 'BUILD_UTILS_NODE_VERSION_DISCONTINUED',
|
||||
link:
|
||||
'https://vercel.com/docs/runtimes#official-runtimes/node-js/node-js-version',
|
||||
message: intro + '\n' + pleaseSet + '\n' + upstreamProvider,
|
||||
|
||||
@@ -39,7 +39,7 @@ export function spawnAsync(
|
||||
: 'Command';
|
||||
reject(
|
||||
new NowBuildError({
|
||||
code: `NOW_BUILD_UTILS_SPAWN_${code || signal}`,
|
||||
code: `BUILD_UTILS_SPAWN_${code || signal}`,
|
||||
message:
|
||||
opts.stdio === 'inherit'
|
||||
? `${cmd} exited with ${code || signal}`
|
||||
@@ -81,7 +81,7 @@ export function execAsync(
|
||||
|
||||
return reject(
|
||||
new NowBuildError({
|
||||
code: `NOW_BUILD_UTILS_EXEC_${code || signal}`,
|
||||
code: `BUILD_UTILS_EXEC_${code || signal}`,
|
||||
message: `${cmd} exited with ${code || signal}`,
|
||||
})
|
||||
);
|
||||
|
||||
@@ -80,3 +80,29 @@ export { readConfigFile } from './fs/read-config-file';
|
||||
export * from './schemas';
|
||||
export * from './types';
|
||||
export * from './errors';
|
||||
|
||||
/**
|
||||
* Helper function to support both `@vercel` and legacy `@now` official Runtimes.
|
||||
*/
|
||||
export const isOfficialRuntime = (desired: string, name?: string): boolean => {
|
||||
if (typeof name !== 'string') {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
name === `@vercel/${desired}` ||
|
||||
name === `@now/${desired}` ||
|
||||
name.startsWith(`@vercel/${desired}@`) ||
|
||||
name.startsWith(`@now/${desired}@`)
|
||||
);
|
||||
};
|
||||
|
||||
export const isStaticRuntime = (name?: string): boolean => {
|
||||
return isOfficialRuntime('static', name);
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function to support both `VERCEL_` and legacy `NOW_` env vars.
|
||||
*/
|
||||
export const getPlatformEnv = (name: string): string | undefined => {
|
||||
return process.env[`VERCEL_${name}`] || process.env[`NOW_${name}`];
|
||||
};
|
||||
|
||||
@@ -49,6 +49,7 @@ export interface Config {
|
||||
|
||||
export interface Meta {
|
||||
isDev?: boolean;
|
||||
devCacheDir?: string;
|
||||
skipDownload?: boolean;
|
||||
requestPath?: string | null;
|
||||
filesChanged?: string[];
|
||||
@@ -81,7 +82,7 @@ export interface AnalyzeOptions {
|
||||
|
||||
/**
|
||||
* An arbitrary object passed by the user in the build definition defined
|
||||
* in `now.json`.
|
||||
* in `vercel.json`.
|
||||
*/
|
||||
config: Config;
|
||||
}
|
||||
@@ -108,7 +109,7 @@ export interface BuildOptions {
|
||||
|
||||
/**
|
||||
* An arbitrary object passed by the user in the build definition defined
|
||||
* in `now.json`.
|
||||
* in `vercel.json`.
|
||||
*/
|
||||
config: Config;
|
||||
|
||||
@@ -148,7 +149,7 @@ export interface PrepareCacheOptions {
|
||||
|
||||
/**
|
||||
* An arbitrary object passed by the user in the build definition defined
|
||||
* in `now.json`.
|
||||
* in `vercel.json`.
|
||||
*/
|
||||
config: Config;
|
||||
}
|
||||
@@ -182,27 +183,11 @@ export interface ShouldServeOptions {
|
||||
|
||||
/**
|
||||
* An arbitrary object passed by the user in the build definition defined
|
||||
* in `now.json`.
|
||||
* in `vercel.json`.
|
||||
*/
|
||||
config: Config;
|
||||
}
|
||||
|
||||
export interface StartDevServerOptions {
|
||||
/**
|
||||
* Name of entrypoint file for this particular build job. Value
|
||||
* `files[entrypoint]` is guaranteed to exist and be a valid File reference.
|
||||
* `entrypoint` is always a discrete file and never a glob, since globs are
|
||||
* expanded into separate builds at deployment time.
|
||||
*/
|
||||
entrypoint: string;
|
||||
|
||||
/**
|
||||
* A writable temporary directory where you are encouraged to perform your
|
||||
* build process. This directory will be populated with the restored cache.
|
||||
*/
|
||||
workPath: string;
|
||||
}
|
||||
|
||||
export interface StartDevServerSuccess {
|
||||
/**
|
||||
* Port number where the dev server can be connected to, assumed to be running
|
||||
@@ -228,7 +213,7 @@ export type StartDevServerResult = StartDevServerSuccess | null;
|
||||
* Source: https://gist.github.com/iainreid820/5c1cc527fe6b5b7dba41fec7fe54bf6e
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
export namespace PackageJson {
|
||||
namespace PackageJson {
|
||||
/**
|
||||
* An author or contributor
|
||||
*/
|
||||
@@ -351,24 +336,3 @@ export interface BuilderFunctions {
|
||||
excludeFiles?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface NowRewrite {
|
||||
source: string;
|
||||
destination: string;
|
||||
}
|
||||
|
||||
export interface NowRedirect {
|
||||
source: string;
|
||||
destination: string;
|
||||
statusCode?: number;
|
||||
}
|
||||
|
||||
export interface NowHeader {
|
||||
source: string;
|
||||
headers: NowHeaderKeyValue[];
|
||||
}
|
||||
|
||||
export interface NowHeaderKeyValue {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [{ "src": "api/index.js", "use": "@now/node" }],
|
||||
"builds": [{ "src": "api/index.js", "use": "@vercel/node" }],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/api/index.js",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{ "src": "with-npm/index.js", "use": "@now/node" },
|
||||
{ "src": "with-yarn/index.js", "use": "@now/node" },
|
||||
{ "src": "with-yarn-and-npm/index.js", "use": "@now/node" }
|
||||
{ "src": "with-npm/index.js", "use": "@vercel/node" },
|
||||
{ "src": "with-yarn/index.js", "use": "@vercel/node" },
|
||||
{ "src": "with-yarn-and-npm/index.js", "use": "@vercel/node" }
|
||||
],
|
||||
"probes": [
|
||||
{ "path": "/with-npm", "mustContain": "npm:RANDOMNESS_PLACEHOLDER" },
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"builds": [
|
||||
{
|
||||
"src": "index.js",
|
||||
"use": "@now/node"
|
||||
"use": "@vercel/node"
|
||||
}
|
||||
],
|
||||
"probes": [{ "path": "/", "mustContain": "found:RANDOMNESS_PLACEHOLDER" }]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [{ "src": "package.json", "use": "@now/static-build" }],
|
||||
"builds": [{ "src": "package.json", "use": "@vercel/static-build" }],
|
||||
"build": { "env": { "NODE_ENV": "production" } },
|
||||
"probes": [{ "path": "/", "mustContain": "node-env:RANDOMNESS_PLACEHOLDER" }]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [{ "src": "package.json", "use": "@now/static-build" }],
|
||||
"builds": [{ "src": "package.json", "use": "@vercel/static-build" }],
|
||||
"build": { "env": { "NODE_ENV": "custom-value:RANDOMNESS_PLACEHOLDER" } },
|
||||
"probes": [
|
||||
{ "path": "/", "mustContain": "custom-value:RANDOMNESS_PLACEHOLDER" }
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
"version": 2,
|
||||
"build": { "env": { "NPM_ONLY_PRODUCTION": "1" } },
|
||||
"builds": [
|
||||
{ "src": "npm/package.json", "use": "@now/static-build" },
|
||||
{ "src": "yarn/package.json", "use": "@now/static-build" }
|
||||
{ "src": "npm/package.json", "use": "@vercel/static-build" },
|
||||
{ "src": "yarn/package.json", "use": "@vercel/static-build" }
|
||||
],
|
||||
"probes": [
|
||||
{ "path": "/npm", "mustContain": "npm-prod:RANDOMNESS_PLACEHOLDER" },
|
||||
|
||||
@@ -27,7 +27,7 @@ for (const fixture of fs.readdirSync(fixturesPath)) {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-loop-func
|
||||
it(`should build ${fixture}`, async () => {
|
||||
it(`Should build "${fixture}"`, async () => {
|
||||
await expect(
|
||||
testDeployment(
|
||||
{ builderUrl, buildUtilsUrl },
|
||||
@@ -53,7 +53,7 @@ for (const builder of buildersToTestWith) {
|
||||
// don't run all foreign fixtures, just some
|
||||
if (['01-cowsay', '01-cache-headers', '03-env-vars'].includes(fixture)) {
|
||||
// eslint-disable-next-line no-loop-func
|
||||
it(`should build ${builder}/${fixture}`, async () => {
|
||||
it(`Should build "${builder}/${fixture}"`, async () => {
|
||||
await expect(
|
||||
testDeployment(
|
||||
{ builderUrl, buildUtilsUrl },
|
||||
@@ -113,15 +113,13 @@ it('Test `detectBuilders` and `detectRoutes`', async () => {
|
||||
const { builders, defaultRoutes } = await detectBuilders(files, pkg);
|
||||
|
||||
const nowConfig = { builds: builders, routes: defaultRoutes, probes };
|
||||
|
||||
await fs.writeFile(
|
||||
path.join(fixture, 'now.json'),
|
||||
JSON.stringify(nowConfig, null, 2)
|
||||
);
|
||||
|
||||
const deployment = await testDeployment(
|
||||
{ builderUrl, buildUtilsUrl },
|
||||
fixture
|
||||
);
|
||||
const deployment = await testDeployment({ builderUrl }, fixture);
|
||||
expect(deployment).toBeDefined();
|
||||
});
|
||||
|
||||
@@ -199,9 +197,6 @@ it('Test `detectBuilders` with `index` files', async () => {
|
||||
JSON.stringify(nowConfig, null, 2)
|
||||
);
|
||||
|
||||
const deployment = await testDeployment(
|
||||
{ builderUrl, buildUtilsUrl },
|
||||
fixture
|
||||
);
|
||||
const deployment = await testDeployment({ builderUrl }, fixture);
|
||||
expect(deployment).toBeDefined();
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Source, Route, Handler } from '@now/routing-utils';
|
||||
import { detectBuilders } from '../src';
|
||||
import { Source, Route, Handler } from '@vercel/routing-utils';
|
||||
import {
|
||||
detectBuilders,
|
||||
detectOutputDirectory,
|
||||
detectApiDirectory,
|
||||
detectApiExtensions,
|
||||
} from '../';
|
||||
} from '../src';
|
||||
|
||||
describe('Test `detectBuilders`', () => {
|
||||
it('should never select now.json src', async () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import path from 'path';
|
||||
import { readFileSync } from 'fs-extra';
|
||||
import { Framework } from '@now/frameworks';
|
||||
import { Framework } from '@vercel/frameworks';
|
||||
import { detectFramework, DetectorFilesystem } from '../src';
|
||||
|
||||
const frameworkList = JSON.parse(
|
||||
|
||||
40
packages/now-build-utils/test/unit.is-official-runtime.test.ts
vendored
Normal file
40
packages/now-build-utils/test/unit.is-official-runtime.test.ts
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import assert from 'assert';
|
||||
import { isOfficialRuntime, isStaticRuntime } from '../src';
|
||||
|
||||
describe('Test `isOfficialRuntime()`', () => {
|
||||
it('should be correct', () => {
|
||||
assert.equal(true, isOfficialRuntime('static', '@vercel/static'));
|
||||
assert.equal(true, isOfficialRuntime('static', '@now/static'));
|
||||
assert.equal(false, isOfficialRuntime('static', '@vercel/static-build'));
|
||||
assert.equal(false, isOfficialRuntime('static', '@now/static-build'));
|
||||
|
||||
assert.equal(true, isOfficialRuntime('node', '@vercel/node'));
|
||||
assert.equal(true, isOfficialRuntime('node', '@now/node'));
|
||||
assert.equal(true, isOfficialRuntime('node', '@vercel/node@1.0.0'));
|
||||
assert.equal(true, isOfficialRuntime('node', '@now/node@1.0.0'));
|
||||
assert.equal(false, isOfficialRuntime('node', '@my-fork/node'));
|
||||
assert.equal(false, isOfficialRuntime('node', '@now/node-server'));
|
||||
|
||||
assert.equal(
|
||||
true,
|
||||
isOfficialRuntime('static-build', '@vercel/static-build')
|
||||
);
|
||||
assert.equal(true, isOfficialRuntime('static-build', '@now/static-build'));
|
||||
assert.equal(
|
||||
true,
|
||||
isOfficialRuntime('static-build', '@vercel/static-build@1.0.0')
|
||||
);
|
||||
assert.equal(false, isOfficialRuntime('static-build', '@vercel/static'));
|
||||
assert.equal(false, isOfficialRuntime('static-build', '@now/static'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test `isStaticRuntime()`', () => {
|
||||
it('should be correct', () => {
|
||||
assert.equal(true, isStaticRuntime('@vercel/static'));
|
||||
assert.equal(true, isStaticRuntime('@now/static'));
|
||||
assert.equal(false, isStaticRuntime('@vercel/static-build'));
|
||||
assert.equal(false, isStaticRuntime('@now/static-build'));
|
||||
assert.equal(false, isStaticRuntime('@now/node'));
|
||||
});
|
||||
});
|
||||
22
packages/now-build-utils/test/unit.test.js
vendored
22
packages/now-build-utils/test/unit.test.js
vendored
@@ -134,21 +134,21 @@ it('should throw for discontinued versions', async () => {
|
||||
});
|
||||
|
||||
it('should support require by path for legacy builders', () => {
|
||||
const index = require('@now/build-utils');
|
||||
const index = require('@vercel/build-utils');
|
||||
|
||||
const download2 = require('@now/build-utils/fs/download.js');
|
||||
const getWriteableDirectory2 = require('@now/build-utils/fs/get-writable-directory.js');
|
||||
const glob2 = require('@now/build-utils/fs/glob.js');
|
||||
const rename2 = require('@now/build-utils/fs/rename.js');
|
||||
const download2 = require('@vercel/build-utils/fs/download.js');
|
||||
const getWriteableDirectory2 = require('@vercel/build-utils/fs/get-writable-directory.js');
|
||||
const glob2 = require('@vercel/build-utils/fs/glob.js');
|
||||
const rename2 = require('@vercel/build-utils/fs/rename.js');
|
||||
const {
|
||||
runNpmInstall: runNpmInstall2,
|
||||
} = require('@now/build-utils/fs/run-user-scripts.js');
|
||||
const streamToBuffer2 = require('@now/build-utils/fs/stream-to-buffer.js');
|
||||
} = require('@vercel/build-utils/fs/run-user-scripts.js');
|
||||
const streamToBuffer2 = require('@vercel/build-utils/fs/stream-to-buffer.js');
|
||||
|
||||
const FileBlob2 = require('@now/build-utils/file-blob.js');
|
||||
const FileFsRef2 = require('@now/build-utils/file-fs-ref.js');
|
||||
const FileRef2 = require('@now/build-utils/file-ref.js');
|
||||
const { Lambda: Lambda2 } = require('@now/build-utils/lambda.js');
|
||||
const FileBlob2 = require('@vercel/build-utils/file-blob.js');
|
||||
const FileFsRef2 = require('@vercel/build-utils/file-fs-ref.js');
|
||||
const FileRef2 = require('@vercel/build-utils/file-ref.js');
|
||||
const { Lambda: Lambda2 } = require('@vercel/build-utils/lambda.js');
|
||||
|
||||
expect(download2).toBe(index.download);
|
||||
expect(getWriteableDirectory2).toBe(index.getWriteableDirectory);
|
||||
|
||||
@@ -3,7 +3,6 @@ const { mkdirp, copyFile } = require('fs-extra');
|
||||
|
||||
const {
|
||||
glob,
|
||||
debug,
|
||||
download,
|
||||
shouldServe,
|
||||
createLambda,
|
||||
@@ -14,7 +13,7 @@ exports.analyze = ({ files, entrypoint }) => files[entrypoint].digest;
|
||||
|
||||
exports.version = 3;
|
||||
|
||||
exports.build = async ({ workPath, files, entrypoint, meta, config }) => {
|
||||
exports.build = async ({ workPath, files, entrypoint, meta }) => {
|
||||
const outDir = await getWritableDirectory();
|
||||
|
||||
await download(files, workPath, meta);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/cgi",
|
||||
"version": "1.0.4",
|
||||
"name": "@vercel/cgi",
|
||||
"version": "1.0.5",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||

|
||||
<p align="center">
|
||||
<img src="https://assets.vercel.com/image/upload/v1588805858/repositories/vercel/logo.png" height="96">
|
||||
<h3 align="center">Vercel</h3>
|
||||
<p align="center">Develop. Preview. Ship.</p>
|
||||
</p>
|
||||
|
||||
[](https://github.com/zeit/now/discussions)
|
||||
|
||||
## Usages
|
||||
|
||||
To install the latest version of Now CLI, visit [vercel.com/download](https://vercel.com/download) or run this command:
|
||||
To install the latest version of Vercel CLI, visit [vercel.com/download](https://vercel.com/download) or run this command:
|
||||
|
||||
```sh
|
||||
npm i -g now
|
||||
npm i -g vercel
|
||||
```
|
||||
|
||||
To quickly start a new project, run the following commands:
|
||||
|
||||
```
|
||||
now init # Pick an example project
|
||||
vercel init # Pick an example project
|
||||
cd <PROJECT> # Change directory to the new project
|
||||
now # Deploy to the cloud
|
||||
vercel # Deploy to the cloud
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
For details on how to use Now CLI, check out our [documentation](https://vercel.com/docs).
|
||||
For details on how to use Vercel CLI, check out our [documentation](https://vercel.com/docs).
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "now",
|
||||
"version": "18.0.1-canary.6",
|
||||
"name": "vercel",
|
||||
"version": "19.0.0",
|
||||
"preferGlobal": true,
|
||||
"license": "Apache-2.0",
|
||||
"description": "The command-line interface for Now",
|
||||
@@ -19,8 +19,7 @@
|
||||
"prepublishOnly": "yarn build",
|
||||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
||||
"build": "ts-node ./scripts/build.ts",
|
||||
"build-dev": "ts-node ./scripts/build.ts --dev",
|
||||
"test-lint": "eslint . --ext .ts,.js --ignore-path ../../.eslintignore"
|
||||
"build-dev": "ts-node ./scripts/build.ts --dev"
|
||||
},
|
||||
"nyc": {
|
||||
"include": [
|
||||
@@ -42,7 +41,8 @@
|
||||
"all": true
|
||||
},
|
||||
"bin": {
|
||||
"now": "./dist/index.js"
|
||||
"vc": "./dist/index.js",
|
||||
"vercel": "./dist/index.js"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
@@ -64,7 +64,6 @@
|
||||
"devDependencies": {
|
||||
"@sentry/node": "5.5.0",
|
||||
"@sindresorhus/slugify": "0.11.0",
|
||||
"@tootallnate/once": "1.1.2",
|
||||
"@types/ansi-escapes": "3.0.0",
|
||||
"@types/ansi-regex": "4.0.0",
|
||||
"@types/async-retry": "1.2.1",
|
||||
@@ -108,7 +107,7 @@
|
||||
"ava": "2.2.0",
|
||||
"bytes": "3.0.0",
|
||||
"chalk": "2.4.2",
|
||||
"chokidar": "2.1.6",
|
||||
"chokidar": "3.3.1",
|
||||
"clipboardy": "2.1.0",
|
||||
"codecov": "3.6.5",
|
||||
"cpy": "7.2.0",
|
||||
|
||||
@@ -39,14 +39,11 @@ async function createBuildersTarball() {
|
||||
}
|
||||
}
|
||||
|
||||
await execa(
|
||||
'npm',
|
||||
['install', '--save-exact', '--no-package-lock', ...builders],
|
||||
{
|
||||
cwd: buildersDir,
|
||||
stdio: 'inherit',
|
||||
}
|
||||
);
|
||||
const yarn = join(dirRoot, '../../node_modules/yarn/bin/yarn.js');
|
||||
await execa(process.execPath, [yarn, 'add', '--no-lockfile', ...builders], {
|
||||
cwd: buildersDir,
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
const packer = tar.pack(buildersDir);
|
||||
await pipe(
|
||||
@@ -104,13 +101,12 @@ async function main() {
|
||||
// Do the initial `ncc` build
|
||||
console.log();
|
||||
const src = join(dirRoot, 'src');
|
||||
const ncc = join(dirRoot, 'node_modules/@zeit/ncc/dist/ncc/cli.js');
|
||||
const args = [ncc, 'build', '--source-map'];
|
||||
const args = ['@zeit/ncc', 'build', '--source-map'];
|
||||
if (!isDev) {
|
||||
args.push('--minify');
|
||||
}
|
||||
args.push(src);
|
||||
await execa(process.execPath, args, { stdio: 'inherit' });
|
||||
await execa('npx', args, { stdio: 'inherit' });
|
||||
|
||||
// `ncc` has some issues with `@zeit/fun`'s runtime files:
|
||||
// - Executable bits on the `bootstrap` files appear to be lost:
|
||||
|
||||
@@ -1,15 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
const fs = require('fs');
|
||||
const { promisify } = require('util');
|
||||
const { join, delimiter } = require('path');
|
||||
const { homedir } = require('os');
|
||||
|
||||
const stat = promisify(fs.stat);
|
||||
const unlink = promisify(fs.unlink);
|
||||
|
||||
function cmd(command) {
|
||||
return `\`${command}\``;
|
||||
}
|
||||
|
||||
function error(command) {
|
||||
console.error('> Error!', command);
|
||||
@@ -36,51 +25,6 @@ function isGlobal() {
|
||||
: Boolean(process.env.npm_config_global);
|
||||
}
|
||||
|
||||
// Logic is from Now Desktop
|
||||
// See: https://git.io/fj4jD
|
||||
function getNowPath() {
|
||||
if (process.platform === 'win32') {
|
||||
const { LOCALAPPDATA, USERPROFILE, HOMEPATH } = process.env;
|
||||
const home = homedir() || USERPROFILE || HOMEPATH;
|
||||
let path;
|
||||
if (LOCALAPPDATA) {
|
||||
path = join(LOCALAPPDATA, 'now-cli', 'now.exe');
|
||||
} else if (home) {
|
||||
path = join(home, 'AppData', 'Local', 'now-cli', 'now.exe');
|
||||
} else {
|
||||
path = '';
|
||||
}
|
||||
return fs.existsSync(path) ? path : null;
|
||||
}
|
||||
|
||||
const pathEnv = (process.env.PATH || '').split(delimiter);
|
||||
|
||||
const paths = [
|
||||
join(process.env.HOME || '/', 'bin'),
|
||||
'/usr/local/bin',
|
||||
'/usr/bin',
|
||||
];
|
||||
|
||||
for (const basePath of paths) {
|
||||
if (!pathEnv.includes(basePath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const nowPath = join(basePath, 'now');
|
||||
|
||||
if (fs.existsSync(nowPath)) {
|
||||
return nowPath;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function isBinary(nowPath) {
|
||||
const stats = await stat(nowPath);
|
||||
return !stats.isDirectory();
|
||||
}
|
||||
|
||||
function validateNodeVersion() {
|
||||
let semver = '>= 0';
|
||||
let major = '1';
|
||||
@@ -113,46 +57,6 @@ async function main() {
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const nowPath = getNowPath();
|
||||
|
||||
if (nowPath === null) {
|
||||
debug(`No now binary found`);
|
||||
return;
|
||||
}
|
||||
|
||||
debug(`Located now binary at ${nowPath}`);
|
||||
|
||||
try {
|
||||
if ((await isBinary(nowPath)) === false) {
|
||||
debug(
|
||||
'Found file or directory named now but will not delete, ' +
|
||||
'as it seems unrelated to Now CLI'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await unlink(nowPath);
|
||||
|
||||
debug(`Removed ${nowPath}`);
|
||||
} catch (err) {
|
||||
if (process.platform !== 'win32') {
|
||||
error(
|
||||
`Could not remove your previous Now CLI installation.\n` +
|
||||
`Please use this command to remove it: ${cmd(
|
||||
`sudo rm ${nowPath}`
|
||||
)}.\n` +
|
||||
`Then try to install it again.`
|
||||
);
|
||||
} else {
|
||||
error(
|
||||
`Could not remove your previous Now CLI installation.\n` +
|
||||
`Please remove ${cmd(nowPath)} manually and try to install it again.`
|
||||
);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
process.on('unhandledRejection', err => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import createOutput from '../../util/output';
|
||||
import getArgs from '../../util/get-args';
|
||||
import getSubcommand from '../../util/get-subcommand';
|
||||
import logo from '../../util/output/logo';
|
||||
import { getPkgName } from '../../util/pkg-name.ts';
|
||||
|
||||
import ls from './ls';
|
||||
import rm from './rm';
|
||||
@@ -14,7 +15,7 @@ import set from './set';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now alias`)} [options] <command>
|
||||
${chalk.bold(`${logo} ${getPkgName()} alias`)} [options] <command>
|
||||
|
||||
${chalk.dim('Commands:')}
|
||||
|
||||
@@ -27,10 +28,10 @@ const help = () => {
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-r ${chalk.bold.underline('RULES_FILE')}, --rules=${chalk.bold.underline(
|
||||
'RULES_FILE'
|
||||
)} Rules file
|
||||
@@ -46,7 +47,7 @@ const help = () => {
|
||||
${chalk.gray('–')} Add a new alias to ${chalk.underline('my-api.now.sh')}
|
||||
|
||||
${chalk.cyan(
|
||||
`$ now alias set ${chalk.underline(
|
||||
`$ ${getPkgName()} alias set ${chalk.underline(
|
||||
'api-ownv3nc9f8.now.sh'
|
||||
)} ${chalk.underline('my-api.now.sh')}`
|
||||
)}
|
||||
@@ -54,7 +55,7 @@ const help = () => {
|
||||
Custom domains work as alias targets
|
||||
|
||||
${chalk.cyan(
|
||||
`$ now alias set ${chalk.underline(
|
||||
`$ ${getPkgName()} alias set ${chalk.underline(
|
||||
'api-ownv3nc9f8.now.sh'
|
||||
)} ${chalk.underline('my-api.com')}`
|
||||
)}
|
||||
@@ -67,26 +68,28 @@ const help = () => {
|
||||
)} in the URLs are unneeded and ignored.
|
||||
|
||||
${chalk.gray('–')} Add and modify path based aliases for ${chalk.underline(
|
||||
'zeit.ninja'
|
||||
'example.com'
|
||||
)}
|
||||
|
||||
${chalk.cyan(
|
||||
`$ now alias ${chalk.underline('zeit.ninja')} -r ${chalk.underline(
|
||||
'rules.json'
|
||||
)}`
|
||||
`$ ${getPkgName()} alias ${chalk.underline(
|
||||
'example.com'
|
||||
)} -r ${chalk.underline('rules.json')}`
|
||||
)}
|
||||
|
||||
Export effective routing rules
|
||||
|
||||
${chalk.cyan(
|
||||
`$ now alias ls aliasId --json > ${chalk.underline('rules.json')}`
|
||||
`$ ${getPkgName()} alias ls aliasId --json > ${chalk.underline(
|
||||
'rules.json'
|
||||
)}`
|
||||
)}
|
||||
|
||||
${chalk.gray('–')} Paginate results, where ${chalk.dim(
|
||||
'`1584722256178`'
|
||||
)} is the time in milliseconds since the UNIX epoch.
|
||||
|
||||
${chalk.cyan(`$ now alias ls --next 1584722256178`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} alias ls --next 1584722256178`)}
|
||||
`);
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import getScope from '../../util/get-scope.ts';
|
||||
import stamp from '../../util/output/stamp.ts';
|
||||
import strlen from '../../util/strlen.ts';
|
||||
import getCommandFlags from '../../util/get-command-flags';
|
||||
import cmd from '../../util/output/cmd.ts';
|
||||
import { getCommandName } from '../../util/pkg-name.ts';
|
||||
|
||||
export default async function ls(ctx, opts, args, output) {
|
||||
const {
|
||||
@@ -55,7 +55,7 @@ export default async function ls(ctx, opts, args, output) {
|
||||
if (args.length > 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now alias ls [alias]`'
|
||||
`${getCommandName('alias ls [alias]')}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
@@ -106,8 +106,8 @@ export default async function ls(ctx, opts, args, output) {
|
||||
if (pagination && pagination.count === 20) {
|
||||
const flags = getCommandFlags(opts, ['_', '--next']);
|
||||
output.log(
|
||||
`To display the next page run ${cmd(
|
||||
`now alias ls${flags} --next ${pagination.next}`
|
||||
`To display the next page run ${getCommandName(
|
||||
`alias ls${flags} --next ${pagination.next}`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import chalk from 'chalk';
|
||||
import ms from 'ms';
|
||||
import table from 'text-table';
|
||||
import Now from '../../util';
|
||||
import cmd from '../../util/output/cmd.ts';
|
||||
import Client from '../../util/client.ts';
|
||||
import getScope from '../../util/get-scope.ts';
|
||||
import removeAliasById from '../../util/alias/remove-alias-by-id';
|
||||
@@ -11,6 +10,7 @@ import strlen from '../../util/strlen.ts';
|
||||
import promptBool from '../../util/prompt-bool';
|
||||
import { isValidName } from '../../util/is-valid-name';
|
||||
import findAliasByAliasOrId from '../../util/alias/find-alias-by-alias-or-id';
|
||||
import { getCommandName } from '../../util/pkg-name.ts';
|
||||
|
||||
export default async function rm(ctx, opts, args, output) {
|
||||
const {
|
||||
@@ -46,14 +46,14 @@ export default async function rm(ctx, opts, args, output) {
|
||||
if (args.length !== 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now alias rm <alias>`'
|
||||
`${getCommandName('alias rm <alias>')}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!aliasOrId) {
|
||||
output.error(`${cmd('now alias rm <alias>')} expects one argument`);
|
||||
output.error(`${getCommandName('alias rm <alias>')} expects one argument`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ export default async function rm(ctx, opts, args, output) {
|
||||
output.error(
|
||||
`Alias not found by "${aliasOrId}" under ${chalk.bold(contextName)}`
|
||||
);
|
||||
output.log(`Run ${cmd('now alias ls')} to see your aliases.`);
|
||||
output.log(`Run ${getCommandName('alias ls')} to see your aliases.`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import { Output } from '../../util/output';
|
||||
import * as ERRORS from '../../util/errors-ts';
|
||||
import assignAlias from '../../util/alias/assign-alias';
|
||||
import Client from '../../util/client';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import formatDnsTable from '../../util/format-dns-table';
|
||||
import formatNSTable from '../../util/format-ns-table';
|
||||
import getDeploymentForAlias from '../../util/alias/get-deployment-for-alias';
|
||||
@@ -23,6 +22,7 @@ import handleCertError from '../../util/certs/handle-cert-error';
|
||||
import isWildcardAlias from '../../util/alias/is-wildcard-alias';
|
||||
import link from '../../util/output/link';
|
||||
import { User } from '../../types';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -77,7 +77,9 @@ export default async function set(
|
||||
// If there are more than two args we have to error
|
||||
if (args.length > 2) {
|
||||
output.error(
|
||||
`${cmd('now alias <deployment> <target>')} accepts at most two arguments`
|
||||
`${getCommandName(
|
||||
`alias <deployment> <target>`
|
||||
)} accepts at most two arguments`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
@@ -126,7 +128,7 @@ export default async function set(
|
||||
output.error(
|
||||
`To ship to production, optionally configure your domains (${link(
|
||||
'https://vercel.com/docs/v2/custom-domains'
|
||||
)}) and run ${cmd('now --prod')}.`
|
||||
)}) and run ${getCommandName(`--prod`)}.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
@@ -301,8 +303,8 @@ function handleSetupDomainError<T>(
|
||||
)}\n\n`
|
||||
);
|
||||
output.print(
|
||||
` Once your domain uses either the nameservers or the TXT DNS record from above, run again ${cmd(
|
||||
'now domains verify <domain>'
|
||||
` Once your domain uses either the nameservers or the TXT DNS record from above, run again ${getCommandName(
|
||||
'domains verify <domain>'
|
||||
)}.\n`
|
||||
);
|
||||
output.print(
|
||||
@@ -310,8 +312,8 @@ function handleSetupDomainError<T>(
|
||||
);
|
||||
} else {
|
||||
output.print(
|
||||
` Once your domain uses the nameservers from above, run again ${cmd(
|
||||
'now domains verify <domain>'
|
||||
` Once your domain uses the nameservers from above, run again ${getCommandName(
|
||||
'domains verify <domain>'
|
||||
)}.\n`
|
||||
);
|
||||
}
|
||||
@@ -474,7 +476,7 @@ function handleCreateAliasError<T>(
|
||||
output.log(
|
||||
`Update the scale settings on ${chalk.dim(
|
||||
error.meta.url
|
||||
)} with \`now scale\` and try again`
|
||||
)} with ${getCommandName('scale')} and try again`
|
||||
);
|
||||
output.log('Read more: https://err.sh/now/v2-no-min');
|
||||
return 1;
|
||||
@@ -490,7 +492,7 @@ function handleCreateAliasError<T>(
|
||||
output.log(
|
||||
`Update the scale settings on ${chalk.dim(
|
||||
error.meta.url
|
||||
)} with \`now scale\` and try again`
|
||||
)} with ${getCommandName('scale')} and try again`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
@@ -510,7 +512,7 @@ function handleCreateAliasError<T>(
|
||||
output.log(
|
||||
`Update the scale settings on ${chalk.dim(
|
||||
error.meta.url
|
||||
)} with \`now scale\` and try again`
|
||||
)} with ${getCommandName('scale')} and try again`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
@@ -520,8 +522,8 @@ function handleCreateAliasError<T>(
|
||||
`There is no certificate for the domain ${error.meta.domain} and it could not be created.`
|
||||
);
|
||||
output.log(
|
||||
`Please generate a new certificate manually with ${cmd(
|
||||
`now certs issue ${error.meta.domain}`
|
||||
`Please generate a new certificate manually with ${getCommandName(
|
||||
`certs issue ${error.meta.domain}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
|
||||
@@ -15,10 +15,11 @@ import exit from '../../util/exit';
|
||||
import Client from '../../util/client.ts';
|
||||
import getScope from '../../util/get-scope.ts';
|
||||
import createOutput from '../../util/output';
|
||||
import { getPkgName } from '../../util/pkg-name.ts';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now billing`)} [options] <command>
|
||||
${chalk.bold(`${logo} ${getPkgName()} billing`)} [options] <command>
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
@@ -32,10 +33,10 @@ const help = () => {
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
@@ -46,7 +47,7 @@ const help = () => {
|
||||
|
||||
${chalk.gray('–')} Add a new credit card (interactively)
|
||||
|
||||
${chalk.cyan(`$ now billing add`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} billing add`)}
|
||||
`);
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import createCertFromFile from '../../util/certs/create-cert-from-file';
|
||||
import createCertForCns from '../../util/certs/create-cert-for-cns';
|
||||
import { NowContext } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
interface Options {
|
||||
'--overwrite'?: boolean;
|
||||
@@ -61,7 +62,6 @@ async function add(
|
||||
throw err;
|
||||
}
|
||||
|
||||
// $FlowFixMe
|
||||
const now = new Now({ apiUrl, token, debug: debugEnabled, currentTeam });
|
||||
|
||||
if (overwite) {
|
||||
@@ -77,7 +77,9 @@ async function add(
|
||||
);
|
||||
output.print(
|
||||
` ${chalk.cyan(
|
||||
`now certs add --crt <domain.crt> --key <domain.key> --ca <ca.crt>`
|
||||
`${getCommandName(
|
||||
'certs add --crt <domain.crt> --key <domain.key> --ca <ca.crt>'
|
||||
)}`
|
||||
)}\n`
|
||||
);
|
||||
now.close();
|
||||
@@ -89,9 +91,9 @@ async function add(
|
||||
} else {
|
||||
output.warn(
|
||||
`${chalk.cyan(
|
||||
'now certs add'
|
||||
getCommandName('certs add')
|
||||
)} will be soon deprecated. Please use ${chalk.cyan(
|
||||
'now certs issue <cn> <cns>'
|
||||
getCommandName('certs issue <cn> <cns>')
|
||||
)} instead`
|
||||
);
|
||||
|
||||
@@ -99,7 +101,9 @@ async function add(
|
||||
output.error(
|
||||
`Invalid number of arguments to create a custom certificate entry. Usage:`
|
||||
);
|
||||
output.print(` ${chalk.cyan(`now certs add <cn>[, <cn>]`)}\n`);
|
||||
output.print(
|
||||
` ${chalk.cyan(getCommandName('certs add <cn>[, <cn>]'))}\n`
|
||||
);
|
||||
now.close();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -13,13 +13,14 @@ import issue from './issue';
|
||||
import ls from './ls';
|
||||
import rm from './rm';
|
||||
import { NowContext } from '../../types';
|
||||
import { getPkgName } from '../../util/pkg-name';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now certs`)} [options] <command>
|
||||
${chalk.bold(`${logo} ${getPkgName()} certs`)} [options] <command>
|
||||
|
||||
${chalk.yellow('NOTE:')} This command is intended for advanced use only.
|
||||
By default, Now manages your certificates automatically.
|
||||
By default, Vercel manages your certificates automatically.
|
||||
|
||||
${chalk.dim('Commands:')}
|
||||
|
||||
@@ -32,10 +33,10 @@ const help = () => {
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
@@ -57,17 +58,17 @@ const help = () => {
|
||||
'–'
|
||||
)} Generate a certificate with the cnames "acme.com" and "www.acme.com"
|
||||
|
||||
${chalk.cyan('$ now certs issue acme.com www.acme.com')}
|
||||
${chalk.cyan(`$ ${getPkgName()} certs issue acme.com www.acme.com`)}
|
||||
|
||||
${chalk.gray('–')} Remove a certificate
|
||||
|
||||
${chalk.cyan('$ now certs rm id')}
|
||||
${chalk.cyan(`$ ${getPkgName()} certs rm id`)}
|
||||
|
||||
${chalk.gray('–')} Paginate results, where ${chalk.dim(
|
||||
'`1584722256178`'
|
||||
)} is the time in milliseconds since the UNIX epoch.
|
||||
|
||||
${chalk.cyan(`$ now certs ls --next 1584722256178`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} certs ls --next 1584722256178`)}
|
||||
`);
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import getScope from '../../util/get-scope';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import startCertOrder from '../../util/certs/start-cert-order';
|
||||
import handleCertError from '../../util/certs/handle-cert-error';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--ca': string;
|
||||
@@ -80,7 +81,9 @@ export default async function issue(
|
||||
);
|
||||
output.print(
|
||||
` ${chalk.cyan(
|
||||
`now certs issue --crt <domain.crt> --key <domain.key> --ca <ca.crt>`
|
||||
getCommandName(
|
||||
'certs issue --crt <domain.crt> --key <domain.key> --ca <ca.crt>'
|
||||
)
|
||||
)}\n`
|
||||
);
|
||||
return 1;
|
||||
@@ -107,7 +110,9 @@ export default async function issue(
|
||||
output.error(
|
||||
`Invalid number of arguments to create a custom certificate entry. Usage:`
|
||||
);
|
||||
output.print(` ${chalk.cyan(`now certs issue <cn>[, <cn>]`)}\n`);
|
||||
output.print(
|
||||
` ${chalk.cyan(getCommandName('certs issue <cn>[, <cn>]'))}\n`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -189,7 +194,9 @@ async function runStartOrder(
|
||||
output.print(
|
||||
` There are no pending challenges. Finish the issuance by running: \n`
|
||||
);
|
||||
output.print(` ${chalk.cyan(`now certs issue ${cns.join(' ')}`)}\n`);
|
||||
output.print(
|
||||
` ${chalk.cyan(getCommandName(`certs issue ${cns.join(' ')}`))}\n`
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -220,7 +227,9 @@ async function runStartOrder(
|
||||
output.print(`${header}\n`);
|
||||
process.stdout.write(`${rows.join('\n')}\n\n`);
|
||||
output.log(`To issue the certificate once the records are added, run:`);
|
||||
output.print(` ${chalk.cyan(`now certs issue ${cns.join(' ')}`)}\n`);
|
||||
output.print(
|
||||
` ${chalk.cyan(getCommandName(`certs issue ${cns.join(' ')}`))}\n`
|
||||
);
|
||||
output.print(' Read more: https://err.sh/now/solve-challenges-manually\n');
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import ms from 'ms';
|
||||
import table from 'text-table';
|
||||
// @ts-ignore
|
||||
import Now from '../../util';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import Client from '../../util/client';
|
||||
import getScope from '../../util/get-scope';
|
||||
import stamp from '../../util/output/stamp';
|
||||
@@ -12,6 +11,7 @@ import strlen from '../../util/strlen';
|
||||
import { Output } from '../../util/output';
|
||||
import { NowContext, Cert } from '../../types';
|
||||
import getCommandFlags from '../../util/get-command-flags';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
interface Options {
|
||||
'--debug'?: boolean;
|
||||
@@ -53,7 +53,9 @@ async function ls(
|
||||
|
||||
if (args.length !== 0) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan('`now certs ls`')}`
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
`${getCommandName('certs ls')}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
@@ -76,8 +78,8 @@ async function ls(
|
||||
if (pagination && pagination.count === 20) {
|
||||
const flags = getCommandFlags(opts, ['_', '--next']);
|
||||
output.log(
|
||||
`To display the next page run ${cmd(
|
||||
`now certs ls${flags} --next ${pagination.next}`
|
||||
`To display the next page run ${getCommandName(
|
||||
`certs ls${flags} --next ${pagination.next}`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import Client from '../../util/client';
|
||||
import getScope from '../../util/get-scope';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import param from '../../util/output/param';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -49,7 +50,7 @@ async function rm(
|
||||
if (args.length !== 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now certs rm <id or cn>`'
|
||||
`${getCommandName('certs rm <id or cn>')}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
|
||||
@@ -2,9 +2,10 @@ import chalk from 'chalk';
|
||||
import logo from '../../util/output/logo';
|
||||
import code from '../../util/output/code';
|
||||
import note from '../../util/output/note';
|
||||
import { getPkgName } from '../../util/pkg-name.ts';
|
||||
|
||||
export const latestHelp = () => `
|
||||
${chalk.bold(`${logo} now`)} [options] <command | path>
|
||||
${chalk.bold(`${logo} ${getPkgName()}`)} [options] <command | path>
|
||||
|
||||
${chalk.dim('Commands:')}
|
||||
|
||||
@@ -41,10 +42,10 @@ export const latestHelp = () => `
|
||||
-V, --platform-version Set the platform version to deploy to
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-f, --force Force a new deployment even if nothing has changed
|
||||
--with-cache Retain build cache when using "--force"
|
||||
@@ -71,7 +72,7 @@ export const latestHelp = () => `
|
||||
|
||||
${note(
|
||||
`To view the usage information for Now 1.0, run ${code(
|
||||
'now help deploy-v1'
|
||||
`${getPkgName()} help deploy-v1`
|
||||
)}`
|
||||
)}
|
||||
|
||||
@@ -79,21 +80,23 @@ export const latestHelp = () => `
|
||||
|
||||
${chalk.gray('–')} Deploy the current directory
|
||||
|
||||
${chalk.cyan('$ now')}
|
||||
${chalk.cyan(`$ ${getPkgName()}`)}
|
||||
|
||||
${chalk.gray('–')} Deploy a custom path
|
||||
|
||||
${chalk.cyan('$ now /usr/src/project')}
|
||||
${chalk.cyan(`$ ${getPkgName()} /usr/src/project`)}
|
||||
|
||||
${chalk.gray('–')} Deploy with Environment Variables
|
||||
|
||||
${chalk.cyan('$ now -e NODE_ENV=production -e SECRET=@mysql-secret')}
|
||||
${chalk.cyan(
|
||||
`$ ${getPkgName()} -e NODE_ENV=production -e SECRET=@mysql-secret`
|
||||
)}
|
||||
|
||||
${chalk.gray('–')} Show the usage information for the sub command ${chalk.dim(
|
||||
'`list`'
|
||||
)}
|
||||
|
||||
${chalk.cyan('$ now help list')}
|
||||
${chalk.cyan(`$ ${getPkgName()} help list`)}
|
||||
|
||||
`;
|
||||
|
||||
@@ -237,10 +240,10 @@ export const legacyHelp = () => `
|
||||
-n, --name Set the project name of the deployment
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-f, --force Force a new deployment even if nothing has changed
|
||||
-t ${chalk.underline('TOKEN')}, --token=${chalk.underline(
|
||||
|
||||
@@ -112,7 +112,7 @@ export default async ctx => {
|
||||
}
|
||||
}
|
||||
|
||||
const file = highlight('now.json');
|
||||
const file = highlight('vercel.json');
|
||||
const prop = code('version');
|
||||
|
||||
if (localConfig) {
|
||||
|
||||
@@ -54,6 +54,7 @@ import validatePaths, {
|
||||
validateRootDirectory,
|
||||
} from '../../util/validate-paths';
|
||||
import { readLocalConfig } from '../../util/config/files';
|
||||
import { getCommandName } from '../../util/pkg-name.ts';
|
||||
|
||||
const addProcessEnv = async (log, env) => {
|
||||
let val;
|
||||
@@ -101,9 +102,7 @@ const printDeploymentStatus = async (
|
||||
|
||||
if (readyState !== 'READY') {
|
||||
output.error(
|
||||
`${chalk.red(
|
||||
'Error!'
|
||||
)} Your deployment failed. Please retry later. More: https://err.sh/now/deployment-error`
|
||||
`Your deployment failed. Please retry later. More: https://err.sh/now/deployment-error`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
@@ -123,7 +122,10 @@ const printDeploymentStatus = async (
|
||||
// but fallback to the first alias in the list
|
||||
const mainAlias =
|
||||
aliasList.find(
|
||||
alias => !alias.endsWith('.now.sh') && !isWildcardAlias(alias)
|
||||
alias =>
|
||||
!alias.endsWith('.now.sh') &&
|
||||
!alias.endsWith('.vercel.app') &&
|
||||
!isWildcardAlias(alias)
|
||||
) || aliasList[0];
|
||||
|
||||
isWildcard = isWildcardAlias(mainAlias);
|
||||
@@ -260,7 +262,7 @@ export default async function main(
|
||||
debug: debugEnabled,
|
||||
});
|
||||
|
||||
// retrieve `project` and `org` from .now
|
||||
// retrieve `project` and `org` from .vercel
|
||||
const link = await getLinkedProject(output, client, path);
|
||||
|
||||
if (link.status === 'error') {
|
||||
@@ -302,7 +304,7 @@ export default async function main(
|
||||
}
|
||||
|
||||
// We use `localConfig` here to read the name
|
||||
// even though the `now.json` file can change
|
||||
// even though the `vercel.json` file can change
|
||||
// afterwards, this is fine since the property
|
||||
// will be deprecated and can be replaced with
|
||||
// user input.
|
||||
@@ -371,7 +373,7 @@ export default async function main(
|
||||
output.print(
|
||||
`${prependEmoji(
|
||||
`The ${highlight(
|
||||
'now.json'
|
||||
'vercel.json'
|
||||
)} file should be inside of the provided root directory.`,
|
||||
emoji('warning')
|
||||
)}\n`
|
||||
@@ -385,7 +387,7 @@ export default async function main(
|
||||
output.print(
|
||||
`${prependEmoji(
|
||||
`The ${code('name')} property in ${highlight(
|
||||
'now.json'
|
||||
'vercel.json'
|
||||
)} is deprecated (https://zeit.ink/5F)`,
|
||||
emoji('warning')
|
||||
)}\n`
|
||||
@@ -402,7 +404,7 @@ export default async function main(
|
||||
if (typeof localConfig.env !== 'undefined' && !isObject(localConfig.env)) {
|
||||
error(
|
||||
`The ${code('env')} property in ${highlight(
|
||||
'now.json'
|
||||
'vercel.json'
|
||||
)} needs to be an object`
|
||||
);
|
||||
return 1;
|
||||
@@ -412,7 +414,7 @@ export default async function main(
|
||||
if (!isObject(localConfig.build)) {
|
||||
error(
|
||||
`The ${code('build')} property in ${highlight(
|
||||
'now.json'
|
||||
'vercel.json'
|
||||
)} needs to be an object`
|
||||
);
|
||||
return 1;
|
||||
@@ -424,7 +426,7 @@ export default async function main(
|
||||
) {
|
||||
error(
|
||||
`The ${code('build.env')} property in ${highlight(
|
||||
'now.json'
|
||||
'vercel.json'
|
||||
)} needs to be an object`
|
||||
);
|
||||
return 1;
|
||||
@@ -438,14 +440,14 @@ export default async function main(
|
||||
parseMeta(argv['--meta'])
|
||||
);
|
||||
|
||||
// Merge dotenv config, `env` from now.json, and `--env` / `-e` arguments
|
||||
// Merge dotenv config, `env` from vercel.json, and `--env` / `-e` arguments
|
||||
const deploymentEnv = Object.assign(
|
||||
{},
|
||||
parseEnv(localConfig.env),
|
||||
parseEnv(argv['--env'])
|
||||
);
|
||||
|
||||
// Merge build env out of `build.env` from now.json, and `--build-env` args
|
||||
// Merge build env out of `build.env` from vercel.json, and `--build-env` args
|
||||
const deploymentBuildEnv = Object.assign(
|
||||
{},
|
||||
parseEnv(localConfig.build && localConfig.build.env),
|
||||
@@ -666,8 +668,8 @@ export default async function main(
|
||||
if (err instanceof BuildError) {
|
||||
output.error('Build failed');
|
||||
output.error(
|
||||
`Check your logs at https://${now.url}/_logs or run ${code(
|
||||
`now logs ${now.url}`,
|
||||
`Check your logs at https://${now.url}/_logs or run ${getCommandName(
|
||||
`logs ${now.url}`,
|
||||
{
|
||||
// Backticks are interpreted as part of the URL, causing CMD+Click
|
||||
// behavior to fail in editors like VSCode.
|
||||
@@ -734,8 +736,8 @@ function handleCreateDeployError(output, error) {
|
||||
|
||||
output.error(
|
||||
`The property ${code(prop)} is not allowed in ${highlight(
|
||||
'now.json'
|
||||
)} when using Now 2.0 – please remove it.`
|
||||
'vercel.json'
|
||||
)} – please remove it.`
|
||||
);
|
||||
|
||||
if (prop === 'build.env' || prop === 'builds.env') {
|
||||
@@ -759,7 +761,7 @@ function handleCreateDeployError(output, error) {
|
||||
|
||||
output.error(
|
||||
`The property ${code(prop)} in ${highlight(
|
||||
'now.json'
|
||||
'vercel.json'
|
||||
)} can only be of type ${code(title(params.type))}.`
|
||||
);
|
||||
|
||||
@@ -770,7 +772,7 @@ function handleCreateDeployError(output, error) {
|
||||
|
||||
output.error(
|
||||
`Failed to validate ${highlight(
|
||||
'now.json'
|
||||
'vercel.json'
|
||||
)}: ${message}\nDocumentation: ${link}`
|
||||
);
|
||||
|
||||
@@ -797,7 +799,9 @@ function handleCreateDeployError(output, error) {
|
||||
}
|
||||
if (error instanceof BuildsRateLimited) {
|
||||
output.error(error.message);
|
||||
output.note(`Run ${code('now upgrade')} to increase your builds limit.`);
|
||||
output.note(
|
||||
`Run ${getCommandName('upgrade')} to increase your builds limit.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
if (
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import path from 'path';
|
||||
import chalk from 'chalk';
|
||||
import { resolve, join } from 'path';
|
||||
|
||||
import DevServer from '../../util/dev/server';
|
||||
import parseListen from '../../util/dev/parse-listen';
|
||||
@@ -9,7 +8,7 @@ import Client from '../../util/client';
|
||||
import { getLinkedProject } from '../../util/projects/link';
|
||||
import { getFrameworks } from '../../util/get-frameworks';
|
||||
import { isSettingValue } from '../../util/is-setting-value';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug'?: boolean;
|
||||
@@ -23,7 +22,7 @@ export default async function dev(
|
||||
output: Output
|
||||
) {
|
||||
const [dir = '.'] = args;
|
||||
let cwd = path.resolve(dir);
|
||||
let cwd = resolve(dir);
|
||||
const listen = parseListen(opts['--listen'] || '3000');
|
||||
const debug = opts['--debug'] || false;
|
||||
|
||||
@@ -44,13 +43,9 @@ export default async function dev(
|
||||
return link.exitCode;
|
||||
}
|
||||
|
||||
if (link.status === 'not_linked' && !process.env.__NOW_SKIP_DEV_COMMAND) {
|
||||
output.print(
|
||||
`${chalk.red(
|
||||
'Error!'
|
||||
)} Your codebase isn’t linked to a project on Vercel. Run ${cmd(
|
||||
'now'
|
||||
)} to link it.\n`
|
||||
if (link.status === 'not_linked' && !process.env.__VERCEL_SKIP_DEV_CMD) {
|
||||
output.error(
|
||||
`Your codebase isn’t linked to a project on Vercel. Run ${getCommandName()} to link it.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
@@ -58,7 +53,8 @@ export default async function dev(
|
||||
let devCommand: undefined | string;
|
||||
let frameworkSlug: null | string = null;
|
||||
if (link.status === 'linked') {
|
||||
const { project } = link;
|
||||
const { project, org } = link;
|
||||
client.currentTeam = org.type === 'team' ? org.id : undefined;
|
||||
|
||||
if (project.devCommand) {
|
||||
devCommand = project.devCommand;
|
||||
@@ -76,7 +72,7 @@ export default async function dev(
|
||||
}
|
||||
|
||||
if (project.rootDirectory) {
|
||||
cwd = path.join(cwd, project.rootDirectory);
|
||||
cwd = join(cwd, project.rootDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import path from 'path';
|
||||
import chalk from 'chalk';
|
||||
import { PackageJson } from '@now/build-utils';
|
||||
import { PackageJson } from '@vercel/build-utils';
|
||||
|
||||
import getArgs from '../../util/get-args';
|
||||
import getSubcommand from '../../util/get-subcommand';
|
||||
@@ -13,6 +13,7 @@ import cmd from '../../util/output/cmd';
|
||||
import dev from './dev';
|
||||
import readPackage from '../../util/read-package';
|
||||
import readConfig from '../../util/config/read-config';
|
||||
import { getPkgName, getCommandName } from '../../util/pkg-name';
|
||||
|
||||
const COMMAND_CONFIG = {
|
||||
dev: ['dev'],
|
||||
@@ -20,9 +21,9 @@ const COMMAND_CONFIG = {
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now dev`)} [options] <dir>
|
||||
${chalk.bold(`${logo} ${getPkgName()} dev`)} [options] <dir>
|
||||
|
||||
Starts the \`now dev\` server.
|
||||
Starts the \`${getPkgName()} dev\` server.
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
@@ -33,13 +34,13 @@ const help = () => {
|
||||
|
||||
${chalk.dim('Examples:')}
|
||||
|
||||
${chalk.gray('–')} Start the \`now dev\` server on port 8080
|
||||
${chalk.gray('–')} Start the \`${getPkgName()} dev\` server on port 8080
|
||||
|
||||
${chalk.cyan('$ now dev --listen 8080')}
|
||||
${chalk.cyan(`$ ${getPkgName()} dev --listen 8080`)}
|
||||
|
||||
${chalk.gray('–')} Make the \`now dev\` server bind to localhost on port 5000
|
||||
|
||||
${chalk.cyan('$ now dev --listen 127.0.0.1:5000')}
|
||||
${chalk.cyan(`$ ${getPkgName()} dev --listen 127.0.0.1:5000`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -77,7 +78,7 @@ export default async function main(ctx: NowContext) {
|
||||
|
||||
const [dir = '.'] = args;
|
||||
|
||||
const nowJson = await readConfig(path.join(dir, 'now.json'));
|
||||
const nowJson = await readConfig(dir);
|
||||
// @ts-ignore: Because `nowJson` could be one of three different types
|
||||
const hasBuilds = nowJson && nowJson.builds && nowJson.builds.length > 0;
|
||||
|
||||
@@ -96,11 +97,20 @@ export default async function main(ctx: NowContext) {
|
||||
output.error(`More details: http://err.sh/now/now-dev-as-dev-script`);
|
||||
return 1;
|
||||
}
|
||||
if (scripts && scripts.dev && /\bvercel\b\W+\bdev\b/.test(scripts.dev)) {
|
||||
output.error(
|
||||
`The ${cmd('dev')} script in ${cmd(
|
||||
'package.json'
|
||||
)} must not contain ${cmd('vercel dev')}`
|
||||
);
|
||||
output.error(`More details: http://err.sh/now/now-dev-as-dev-script`);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv._.length > 2) {
|
||||
output.error(`${cmd('now dev [dir]')} accepts at most one argument`);
|
||||
output.error(`${getCommandName(`dev [dir]`)} accepts at most one argument`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import getScope from '../../util/get-scope';
|
||||
import parseAddDNSRecordArgs from '../../util/dns/parse-add-dns-record-args';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import getDNSData from '../../util/dns/get-dns-data';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -49,7 +50,7 @@ export default async function add(
|
||||
if (!parsedParams) {
|
||||
output.error(
|
||||
`Invalid number of arguments. See: ${chalk.cyan(
|
||||
'`now dns --help`'
|
||||
`${getCommandName('dns --help')}`
|
||||
)} for usage.`
|
||||
);
|
||||
return 1;
|
||||
|
||||
@@ -6,6 +6,7 @@ import getScope from '../../util/get-scope';
|
||||
import { DomainNotFound, InvalidDomain } from '../../util/errors-ts';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import importZonefile from '../../util/dns/import-zonefile';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -41,7 +42,7 @@ export default async function add(
|
||||
if (args.length !== 2) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now dns import <domain> <zonefile>`'
|
||||
`${getCommandName('dns import <domain> <zonefile>')}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
|
||||
@@ -6,6 +6,7 @@ import getArgs from '../../util/get-args';
|
||||
import getSubcommand from '../../util/get-subcommand';
|
||||
import handleError from '../../util/handle-error';
|
||||
import logo from '../../util/output/logo';
|
||||
import { getPkgName } from '../../util/pkg-name';
|
||||
|
||||
import add from './add';
|
||||
import importZone from './import';
|
||||
@@ -14,7 +15,7 @@ import rm from './rm';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now dns`)} [options] <command>
|
||||
${chalk.bold(`${logo} ${getPkgName()} dns`)} [options] <command>
|
||||
|
||||
${chalk.dim('Commands:')}
|
||||
|
||||
@@ -28,50 +29,64 @@ const help = () => {
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
)} Login token
|
||||
-S, --scope Set a custom scope
|
||||
-N, --next Show next page of results
|
||||
|
||||
${chalk.dim('Examples:')}
|
||||
|
||||
${chalk.gray('–')} Add an A record for a subdomain
|
||||
|
||||
${chalk.cyan(
|
||||
'$ now dns add <DOMAIN> <SUBDOMAIN> <A | AAAA | ALIAS | CNAME | TXT> <VALUE>'
|
||||
`$ ${getPkgName()} dns add <DOMAIN> <SUBDOMAIN> <A | AAAA | ALIAS | CNAME | TXT> <VALUE>`
|
||||
)}
|
||||
${chalk.cyan('$ now dns add zeit.rocks api A 198.51.100.100')}
|
||||
${chalk.cyan(`$ ${getPkgName()} dns add zeit.rocks api A 198.51.100.100`)}
|
||||
|
||||
${chalk.gray('–')} Add an MX record (@ as a name refers to the domain)
|
||||
|
||||
${chalk.cyan(`$ now dns add <DOMAIN> '@' MX <RECORD VALUE> <PRIORITY>`)}
|
||||
${chalk.cyan(`$ now dns add zeit.rocks '@' MX mail.zeit.rocks 10`)}
|
||||
${chalk.cyan(
|
||||
`$ ${getPkgName()} dns add <DOMAIN> '@' MX <RECORD VALUE> <PRIORITY>`
|
||||
)}
|
||||
${chalk.cyan(
|
||||
`$ ${getPkgName()} dns add zeit.rocks '@' MX mail.zeit.rocks 10`
|
||||
)}
|
||||
|
||||
${chalk.gray('–')} Add an SRV record
|
||||
|
||||
${chalk.cyan(
|
||||
'$ now dns add <DOMAIN> <NAME> SRV <PRIORITY> <WEIGHT> <PORT> <TARGET>'
|
||||
`$ ${getPkgName()} dns add <DOMAIN> <NAME> SRV <PRIORITY> <WEIGHT> <PORT> <TARGET>`
|
||||
)}
|
||||
${chalk.cyan(
|
||||
`$ ${getPkgName()} dns add zeit.rocks '@' SRV 10 0 389 zeit.party`
|
||||
)}
|
||||
${chalk.cyan(`$ now dns add zeit.rocks '@' SRV 10 0 389 zeit.party`)}
|
||||
|
||||
${chalk.gray('–')} Add a CAA record
|
||||
|
||||
${chalk.cyan(
|
||||
`$ now dns add <DOMAIN> <NAME> CAA '<FLAGS> <TAG> "<VALUE>"'`
|
||||
`$ ${getPkgName()} dns add <DOMAIN> <NAME> CAA '<FLAGS> <TAG> "<VALUE>"'`
|
||||
)}
|
||||
${chalk.cyan(
|
||||
`$ ${getPkgName()} dns add zeit.rocks '@' CAA '0 issue "example.com"'`
|
||||
)}
|
||||
${chalk.cyan(`$ now dns add zeit.rocks '@' CAA '0 issue "example.com"'`)}
|
||||
|
||||
${chalk.gray('–')} Import a Zone file
|
||||
|
||||
${chalk.cyan('$ now dns import <DOMAIN> <FILE>')}
|
||||
${chalk.cyan(`$ now dns import zeit.rocks ./zonefile.txt`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} dns import <DOMAIN> <FILE>`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} dns import zeit.rocks ./zonefile.txt`)}
|
||||
|
||||
${chalk.gray('–')} Paginate results, where ${chalk.dim(
|
||||
'`1584722256178`'
|
||||
)} is the time in milliseconds since the UNIX epoch.
|
||||
|
||||
${chalk.cyan(`$ ${getPkgName()} dns ls --next 1584722256178`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} dns ls zeit.rocks --next 1584722256178`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -86,7 +101,7 @@ export default async function main(ctx: NowContext) {
|
||||
let argv;
|
||||
|
||||
try {
|
||||
argv = getArgs(ctx.argv.slice(2), {});
|
||||
argv = getArgs(ctx.argv.slice(2), { '--next': Number, '-N': '--next' });
|
||||
} catch (error) {
|
||||
handleError(error);
|
||||
return 1;
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
import chalk from 'chalk';
|
||||
import ms from 'ms';
|
||||
import plural from 'pluralize';
|
||||
import { Output } from '../../util/output';
|
||||
import { DomainNotFound } from '../../util/errors-ts';
|
||||
import { ThenArg, DNSRecord, NowContext } from '../../types';
|
||||
import { DNSRecord, NowContext } from '../../types';
|
||||
import Client from '../../util/client';
|
||||
import formatTable from '../../util/format-table';
|
||||
import getDNSRecords from '../../util/dns/get-dns-records';
|
||||
import getDNSRecords, {
|
||||
DomainRecordsItem,
|
||||
} from '../../util/dns/get-dns-records';
|
||||
import getDomainDNSRecords from '../../util/dns/get-domain-dns-records';
|
||||
import getScope from '../../util/get-scope';
|
||||
import stamp from '../../util/output/stamp';
|
||||
|
||||
type DNSRecords = ThenArg<ReturnType<typeof getDNSRecords>>;
|
||||
import getCommandFlags from '../../util/get-command-flags';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
'--next'?: number;
|
||||
};
|
||||
|
||||
export default async function ls(
|
||||
@@ -29,7 +31,7 @@ export default async function ls(
|
||||
} = ctx;
|
||||
const { currentTeam } = config;
|
||||
const { apiUrl } = ctx;
|
||||
const debug = opts['--debug'];
|
||||
const { '--debug': debug, '--next': nextTimestamp } = opts;
|
||||
const client = new Client({ apiUrl, token, currentTeam, debug });
|
||||
let contextName = null;
|
||||
|
||||
@@ -50,15 +52,26 @@ export default async function ls(
|
||||
if (args.length > 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now dns ls [domain]`'
|
||||
`${getCommandName('dns ls [domain]')}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (typeof nextTimestamp !== 'undefined' && Number.isNaN(nextTimestamp)) {
|
||||
output.error('Please provide a number for flag --next');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (domainName) {
|
||||
const records = await getDomainDNSRecords(output, client, domainName);
|
||||
if (records instanceof DomainNotFound) {
|
||||
const data = await getDomainDNSRecords(
|
||||
output,
|
||||
client,
|
||||
domainName,
|
||||
nextTimestamp,
|
||||
4
|
||||
);
|
||||
if (data instanceof DomainNotFound) {
|
||||
output.error(
|
||||
`The domain ${domainName} can't be found under ${chalk.bold(
|
||||
contextName
|
||||
@@ -67,27 +80,52 @@ export default async function ls(
|
||||
return 1;
|
||||
}
|
||||
|
||||
const { records, pagination } = data;
|
||||
|
||||
output.log(
|
||||
`${plural('Record', records.length, true)} found under ${chalk.bold(
|
||||
contextName
|
||||
)} ${chalk.gray(lsStamp())}`
|
||||
`${
|
||||
records.length > 0 ? 'Records' : 'No records'
|
||||
} found under ${chalk.bold(contextName)} ${chalk.gray(lsStamp())}`
|
||||
);
|
||||
console.log(getDNSRecordsTable([{ domainName, records }]));
|
||||
|
||||
if (pagination && pagination.count === 20) {
|
||||
const flags = getCommandFlags(opts, ['_', '--next']);
|
||||
output.log(
|
||||
`To display the next page run ${getCommandName(
|
||||
`dns ls ${domainName}${flags} --next ${pagination.next}`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const dnsRecords = await getDNSRecords(output, client, contextName);
|
||||
const { records: dnsRecords, pagination } = await getDNSRecords(
|
||||
output,
|
||||
client,
|
||||
contextName,
|
||||
nextTimestamp
|
||||
);
|
||||
const nRecords = dnsRecords.reduce((p, r) => r.records.length + p, 0);
|
||||
output.log(
|
||||
`${plural('Record', nRecords, true)} found under ${chalk.bold(
|
||||
`${nRecords > 0 ? 'Records' : 'No records'} found under ${chalk.bold(
|
||||
contextName
|
||||
)} ${chalk.gray(lsStamp())}`
|
||||
);
|
||||
console.log(getDNSRecordsTable(dnsRecords));
|
||||
if (pagination && pagination.count === 20) {
|
||||
const flags = getCommandFlags(opts, ['_', '--next']);
|
||||
output.log(
|
||||
`To display the next page run ${getCommandName(
|
||||
`dns ls${flags} --next ${pagination.next}`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getDNSRecordsTable(dnsRecords: DNSRecords) {
|
||||
function getDNSRecordsTable(dnsRecords: DomainRecordsItem[]) {
|
||||
return formatTable(
|
||||
['', 'id', 'name', 'type', 'value', 'created'],
|
||||
['l', 'r', 'l', 'l', 'l', 'l'],
|
||||
@@ -101,7 +139,7 @@ function getDNSRecordsTable(dnsRecords: DNSRecords) {
|
||||
function getDNSRecordRow(record: DNSRecord) {
|
||||
const isSystemRecord = record.creator === 'system';
|
||||
const createdAt = `${ms(
|
||||
Date.now() - new Date(Number(record.created)).getTime()
|
||||
Date.now() - new Date(Number(record.createdAt)).getTime()
|
||||
)} ago`;
|
||||
const priority = record.mxPriority || record.priority || null;
|
||||
return [
|
||||
|
||||
@@ -8,6 +8,7 @@ import deleteDNSRecordById from '../../util/dns/delete-dns-record-by-id';
|
||||
import getDNSRecordById from '../../util/dns/get-dns-record-by-id';
|
||||
import getScope from '../../util/get-scope';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -19,15 +20,17 @@ export default async function rm(
|
||||
args: string[],
|
||||
output: Output
|
||||
) {
|
||||
const { authConfig: { token }, config } = ctx;
|
||||
const {
|
||||
authConfig: { token },
|
||||
config,
|
||||
} = ctx;
|
||||
const { currentTeam } = config;
|
||||
const { apiUrl } = ctx;
|
||||
const debug = opts['--debug'];
|
||||
const client = new Client({ apiUrl, token, currentTeam, debug });
|
||||
let contextName = null;
|
||||
|
||||
try {
|
||||
({ contextName } = await getScope(client));
|
||||
await getScope(client);
|
||||
} catch (err) {
|
||||
if (err.code === 'NOT_AUTHORIZED' || err.code === 'TEAM_DELETED') {
|
||||
output.error(err.message);
|
||||
@@ -40,24 +43,21 @@ export default async function rm(
|
||||
const [recordId] = args;
|
||||
if (args.length !== 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan('`now dns rm <id>`')}`
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
`${getCommandName('dns rm <id>')}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const domainRecord = await getDNSRecordById(
|
||||
output,
|
||||
client,
|
||||
contextName,
|
||||
recordId
|
||||
);
|
||||
const record = await getDNSRecordById(client, recordId);
|
||||
|
||||
if (!domainRecord) {
|
||||
if (!record) {
|
||||
output.error('DNS record not found');
|
||||
return 1;
|
||||
}
|
||||
|
||||
const { domainName, record } = domainRecord;
|
||||
const { domain: domainName } = record;
|
||||
const yes = await readConfirmation(
|
||||
output,
|
||||
'The following record will be removed permanently',
|
||||
@@ -91,7 +91,7 @@ function readConfirmation(
|
||||
output.print(
|
||||
`${table([getDeleteTableRow(domainName, record)], {
|
||||
align: ['l', 'r', 'l'],
|
||||
hsep: ' '.repeat(6)
|
||||
hsep: ' '.repeat(6),
|
||||
}).replace(/^(.*)/gm, ' $1')}\n`
|
||||
);
|
||||
output.print(
|
||||
@@ -112,12 +112,16 @@ function readConfirmation(
|
||||
}
|
||||
|
||||
function getDeleteTableRow(domainName: string, record: DNSRecord) {
|
||||
const recordName = `${record.name.length > 0
|
||||
? `${record.name}.`
|
||||
: ''}${domainName}`;
|
||||
const recordName = `${
|
||||
record.name.length > 0 ? `${record.name}.` : ''
|
||||
}${domainName}`;
|
||||
return [
|
||||
record.id,
|
||||
chalk.bold(`${recordName} ${record.type} ${record.value} ${record.mxPriority || ''}`),
|
||||
chalk.gray(`${ms(Date.now() - new Date(Number(record.created)).getTime())} ago`)
|
||||
chalk.bold(
|
||||
`${recordName} ${record.type} ${record.value} ${record.mxPriority || ''}`
|
||||
),
|
||||
chalk.gray(
|
||||
`${ms(Date.now() - new Date(Number(record.createdAt)).getTime())} ago`
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import formatNSTable from '../../util/format-ns-table';
|
||||
import getScope from '../../util/get-scope';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import param from '../../util/output/param';
|
||||
import { getCommandName, getTitleName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--cdn': boolean;
|
||||
@@ -47,12 +48,14 @@ export default async function add(
|
||||
}
|
||||
|
||||
if (opts['--cdn'] !== undefined || opts['--no-cdn'] !== undefined) {
|
||||
output.error(`Toggling CF from Now CLI is deprecated.`);
|
||||
output.error(`Toggling CF from ${getTitleName()} CLI is deprecated.`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.length !== 1) {
|
||||
output.error(`${cmd('now domains add <domain>')} expects one argument`);
|
||||
output.error(
|
||||
`${getCommandName('domains add <domain>')} expects one argument`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -73,7 +76,7 @@ export default async function add(
|
||||
output.error(
|
||||
`You are adding '${domainName}' as a domain name containing a subdomain part '${subdomain}'\n` +
|
||||
` This feature is deprecated, please add just the root domain: ${chalk.cyan(
|
||||
`now domain add ${domain}`
|
||||
`${getCommandName(`domain add ${domain}`)}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
@@ -139,7 +142,7 @@ export default async function add(
|
||||
);
|
||||
output.print(
|
||||
` If you want to force running a verification, you can run ${cmd(
|
||||
'now domains verify <domain>'
|
||||
`${getCommandName('domains verify <domain>')}`
|
||||
)}\n`
|
||||
);
|
||||
output.print(' Read more: https://err.sh/now/domain-verification\n\n');
|
||||
|
||||
@@ -5,7 +5,6 @@ import { NowContext } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import * as ERRORS from '../../util/errors-ts';
|
||||
import Client from '../../util/client';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import getDomainPrice from '../../util/domains/get-domain-price';
|
||||
import getDomainStatus from '../../util/domains/get-domain-status';
|
||||
import getScope from '../../util/get-scope';
|
||||
@@ -13,6 +12,7 @@ import param from '../../util/output/param';
|
||||
import promptBool from '../../util/input/prompt-bool';
|
||||
import purchaseDomain from '../../util/domains/purchase-domain';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -47,7 +47,9 @@ export default async function buy(
|
||||
|
||||
const [domainName] = args;
|
||||
if (!domainName) {
|
||||
output.error(`Missing domain name. Run ${cmd('now domains --help')}`);
|
||||
output.error(
|
||||
`Missing domain name. Run ${getCommandName(`domains --help`)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -60,7 +62,9 @@ export default async function buy(
|
||||
const { domain: rootDomain, subdomain } = parsedDomain;
|
||||
if (subdomain || !rootDomain) {
|
||||
output.error(
|
||||
`Invalid domain name "${domainName}". Run ${cmd('now domains --help')}`
|
||||
`Invalid domain name "${domainName}". Run ${getCommandName(
|
||||
`domains --help`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
@@ -116,8 +120,8 @@ export default async function buy(
|
||||
|
||||
if (buyResult instanceof ERRORS.SourceNotFound) {
|
||||
output.error(
|
||||
`Could not purchase domain. Please add a payment method using ${cmd(
|
||||
'now billing add'
|
||||
`Could not purchase domain. Please add a payment method using ${getCommandName(
|
||||
`billing add`
|
||||
)}.`
|
||||
);
|
||||
return 1;
|
||||
@@ -184,8 +188,8 @@ export default async function buy(
|
||||
);
|
||||
} else {
|
||||
output.note(
|
||||
`You may now use your domain as an alias to your deployments. Run ${cmd(
|
||||
'now alias --help'
|
||||
`You may now use your domain as an alias to your deployments. Run ${getCommandName(
|
||||
`alias --help`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,10 +15,11 @@ import ls from './ls';
|
||||
import rm from './rm';
|
||||
import verify from './verify';
|
||||
import move from './move';
|
||||
import { getPkgName } from '../../util/pkg-name';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now domains`)} [options] <command>
|
||||
${chalk.bold(`${logo} ${getPkgName()} domains`)} [options] <command>
|
||||
|
||||
${chalk.dim('Commands:')}
|
||||
|
||||
@@ -28,7 +29,7 @@ const help = () => {
|
||||
rm [name] Remove a domain
|
||||
buy [name] Buy a domain that you don't yet own
|
||||
move [name] [destination] Move a domain to another user or team.
|
||||
transfer-in [name] Transfer in a domain to Zeit
|
||||
transfer-in [name] Transfer in a domain to Vercel
|
||||
verify [name] Run a verification for a domain
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
@@ -37,10 +38,10 @@ const help = () => {
|
||||
-d, --debug Debug mode [off]
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
)} Login token
|
||||
@@ -51,13 +52,15 @@ const help = () => {
|
||||
|
||||
${chalk.gray('–')} Add a domain that you already own
|
||||
|
||||
${chalk.cyan(`$ now domains add ${chalk.underline('domain-name.com')}`)}
|
||||
${chalk.cyan(
|
||||
`$ ${getPkgName()} domains add ${chalk.underline('domain-name.com')}`
|
||||
)}
|
||||
|
||||
Make sure the domain's DNS nameservers are at least 2 of the
|
||||
ones listed on ${chalk.underline('https://zeit.world')}.
|
||||
ones listed on ${chalk.underline('https://vercel.com/edge-network')}.
|
||||
|
||||
${chalk.yellow('NOTE:')} Running ${chalk.dim(
|
||||
'`now alias`'
|
||||
`${getPkgName()} alias`
|
||||
)} will automatically register your domain
|
||||
if it's configured with these nameservers (no need to ${chalk.dim(
|
||||
'`domain add`'
|
||||
@@ -67,7 +70,7 @@ const help = () => {
|
||||
'`1584722256178`'
|
||||
)} is the time in milliseconds since the UNIX epoch.
|
||||
|
||||
${chalk.cyan(`$ now domains ls --next 1584722256178`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} domains ls --next 1584722256178`)}
|
||||
`);
|
||||
};
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import { DomainNotFound, DomainPermissionDenied } from '../../util/errors-ts';
|
||||
import { NowContext } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import Client from '../../util/client';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import dnsTable from '../../util/format-dns-table';
|
||||
import formatDate from '../../util/format-date';
|
||||
@@ -11,6 +10,7 @@ import formatNSTable from '../../util/format-ns-table';
|
||||
import getDomainByName from '../../util/domains/get-domain-by-name';
|
||||
import getScope from '../../util/get-scope';
|
||||
import getDomainPrice from '../../util/domains/get-domain-price';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -48,14 +48,16 @@ export default async function inspect(
|
||||
const inspectStamp = stamp();
|
||||
|
||||
if (!domainName) {
|
||||
output.error(`${cmd('now domains inspect <domain>')} expects one argument`);
|
||||
output.error(
|
||||
`${getCommandName(`domains inspect <domain>`)} expects one argument`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.length !== 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now domains inspect <domain>`'
|
||||
`${getCommandName('domains inspect <domain>')}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
@@ -72,7 +74,7 @@ export default async function inspect(
|
||||
output.error(
|
||||
`Domain not found by "${domainName}" under ${chalk.bold(contextName)}`
|
||||
);
|
||||
output.log(`Run ${cmd('now domains ls')} to see your domains.`);
|
||||
output.log(`Run ${getCommandName(`domains ls`)} to see your domains.`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -82,7 +84,7 @@ export default async function inspect(
|
||||
contextName
|
||||
)}`
|
||||
);
|
||||
output.log(`Run ${cmd('now domains ls')} to see your domains.`);
|
||||
output.log(`Run ${getCommandName(`domains ls`)} to see your domains.`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -169,8 +171,8 @@ export default async function inspect(
|
||||
` We will run a verification for you and you will receive an email upon completion.\n`
|
||||
);
|
||||
output.print(
|
||||
` If you want to force running a verification, you can run ${cmd(
|
||||
'now domains verify <domain>'
|
||||
` If you want to force running a verification, you can run ${getCommandName(
|
||||
`domains verify <domain>`
|
||||
)}\n`
|
||||
);
|
||||
output.print(' Read more: https://err.sh/now/domain-verification\n\n');
|
||||
|
||||
@@ -10,7 +10,7 @@ import strlen from '../../util/strlen';
|
||||
import { Output } from '../../util/output';
|
||||
import { Domain, NowContext } from '../../types';
|
||||
import getCommandFlags from '../../util/get-command-flags';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -53,7 +53,9 @@ export default async function ls(
|
||||
|
||||
if (args.length !== 0) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan('`now domains ls`')}`
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
`${getCommandName('domains ls')}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
@@ -73,8 +75,8 @@ export default async function ls(
|
||||
if (pagination && pagination.count === 20) {
|
||||
const flags = getCommandFlags(opts, ['_', '--next']);
|
||||
output.log(
|
||||
`To display the next page run ${cmd(
|
||||
`now domains ls${flags} --next ${pagination.next}`
|
||||
`To display the next page run ${getCommandName(
|
||||
`domains ls${flags} --next ${pagination.next}`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { NowContext, User, Team } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import * as ERRORS from '../../util/errors-ts';
|
||||
import Client from '../../util/client';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import getScope from '../../util/get-scope';
|
||||
import withSpinner from '../../util/with-spinner';
|
||||
import moveOutDomain from '../../util/domains/move-out-domain';
|
||||
@@ -16,6 +15,7 @@ import getDomainAliases from '../../util/alias/get-domain-aliases';
|
||||
import getDomainByName from '../../util/domains/get-domain-by-name';
|
||||
import promptBool from '../../util/input/prompt-bool';
|
||||
import getTeams from '../../util/get-teams';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -53,7 +53,9 @@ export default async function move(
|
||||
const { domainName, destination } = await getArgs(args);
|
||||
if (!isRootDomain(domainName)) {
|
||||
output.error(
|
||||
`Invalid domain name "${domainName}". Run ${cmd('now domains --help')}`
|
||||
`Invalid domain name "${domainName}". Run ${getCommandName(
|
||||
`domains --help`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
@@ -61,7 +63,7 @@ export default async function move(
|
||||
const domain = await getDomainByName(client, contextName, domainName);
|
||||
if (domain instanceof ERRORS.DomainNotFound) {
|
||||
output.error(`Domain not found under ${chalk.bold(contextName)}`);
|
||||
output.log(`Run ${cmd('now domains ls')} to see your domains.`);
|
||||
output.log(`Run ${getCommandName(`domains ls`)} to see your domains.`);
|
||||
return 1;
|
||||
}
|
||||
if (domain instanceof ERRORS.DomainPermissionDenied) {
|
||||
@@ -100,7 +102,7 @@ export default async function move(
|
||||
output.warn(
|
||||
`This domain's ${chalk.bold(
|
||||
plural('alias', aliases.length, true)
|
||||
)} will be removed. Run ${chalk.dim('`now alias ls`')} to list them.`
|
||||
)} will be removed. Run ${getCommandName(`alias ls`)} to list them.`
|
||||
);
|
||||
if (
|
||||
!(await promptBool(
|
||||
@@ -140,7 +142,7 @@ export default async function move(
|
||||
}
|
||||
if (moveTokenResult instanceof ERRORS.DomainNotFound) {
|
||||
output.error(`Domain not found under ${chalk.bold(contextName)}`);
|
||||
output.log(`Run ${cmd('now domains ls')} to see your domains.`);
|
||||
output.log(`Run ${getCommandName(`domains ls`)} to see your domains.`);
|
||||
return 1;
|
||||
}
|
||||
if (moveTokenResult instanceof ERRORS.DomainPermissionDenied) {
|
||||
|
||||
@@ -5,7 +5,6 @@ import { DomainNotFound, DomainPermissionDenied } from '../../util/errors-ts';
|
||||
import { NowContext, Domain } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import Client from '../../util/client';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import deleteCertById from '../../util/certs/delete-cert-by-id';
|
||||
import getDomainByName from '../../util/domains/get-domain-by-name';
|
||||
import getScope from '../../util/get-scope';
|
||||
@@ -16,6 +15,7 @@ import * as ERRORS from '../../util/errors-ts';
|
||||
import param from '../../util/output/param';
|
||||
import promptBool from '../../util/input/prompt-bool';
|
||||
import setCustomSuffix from '../../util/domains/set-custom-suffix';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -51,14 +51,16 @@ export default async function rm(
|
||||
}
|
||||
|
||||
if (!domainName) {
|
||||
output.error(`${cmd('now domains rm <domain>')} expects one argument`);
|
||||
output.error(
|
||||
`${getCommandName(`domains rm <domain>`)} expects one argument`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.length !== 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now domains rm <domain>`'
|
||||
`${getCommandName('domains rm <domain>')}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
@@ -69,7 +71,7 @@ export default async function rm(
|
||||
output.error(
|
||||
`Domain not found by "${domainName}" under ${chalk.bold(contextName)}`
|
||||
);
|
||||
output.log(`Run ${cmd('now domains ls')} to see your domains.`);
|
||||
output.log(`Run ${getCommandName(`domains ls`)} to see your domains.`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -79,7 +81,7 @@ export default async function rm(
|
||||
contextName
|
||||
)}`
|
||||
);
|
||||
output.log(`Run ${cmd('now domains ls')} to see your domains.`);
|
||||
output.log(`Run ${getCommandName(`domains ls`)} to see your domains.`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -146,7 +148,7 @@ async function removeDomain(
|
||||
|
||||
if (removeResult instanceof ERRORS.DomainNotFound) {
|
||||
output.error(`Domain not found under ${chalk.bold(contextName)}`);
|
||||
output.log(`Run ${cmd('now domains ls')} to see your domains.`);
|
||||
output.log(`Run ${getCommandName(`domains ls`)} to see your domains.`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -204,7 +206,7 @@ async function removeDomain(
|
||||
output.warn(
|
||||
`This domain's ${chalk.bold(
|
||||
plural('alias', aliases.length, true)
|
||||
)} will be removed. Run ${chalk.dim('`now alias ls`')} to list them.`
|
||||
)} will be removed. Run ${getCommandName(`alias ls`)} to list them.`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -212,7 +214,7 @@ async function removeDomain(
|
||||
output.warn(
|
||||
`This domain's ${chalk.bold(
|
||||
plural('certificate', certs.length, true)
|
||||
)} will be removed. Run ${chalk.dim('`now cert ls`')} to list them.`
|
||||
)} will be removed. Run ${getCommandName(`cert ls`)} to list them.`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { NowContext } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import * as ERRORS from '../../util/errors-ts';
|
||||
import Client from '../../util/client';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import getScope from '../../util/get-scope';
|
||||
import param from '../../util/output/param';
|
||||
import transferInDomain from '../../util/domains/transfer-in-domain';
|
||||
@@ -15,6 +14,7 @@ import getDomainPrice from '../../util/domains/get-domain-price';
|
||||
import checkTransfer from '../../util/domains/check-transfer';
|
||||
import promptBool from '../../util/input/prompt-bool';
|
||||
import isRootDomain from '../../util/is-root-domain';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -50,14 +50,16 @@ export default async function transferIn(
|
||||
|
||||
const [domainName] = args;
|
||||
if (!domainName) {
|
||||
output.error(`Missing domain name. Run ${cmd('now domains --help')}`);
|
||||
output.error(
|
||||
`Missing domain name. Run ${getCommandName(`domains --help`)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!isRootDomain(domainName)) {
|
||||
output.error(
|
||||
`Invalid domain name ${param(domainName)}. Run ${cmd(
|
||||
'now domains --help'
|
||||
`Invalid domain name ${param(domainName)}. Run ${getCommandName(
|
||||
`domains --help`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
@@ -127,8 +129,8 @@ export default async function transferIn(
|
||||
|
||||
if (transferInResult instanceof ERRORS.SourceNotFound) {
|
||||
output.error(
|
||||
`Could not purchase domain. Please add a payment method using ${cmd(
|
||||
'now billing add'
|
||||
`Could not purchase domain. Please add a payment method using ${getCommandName(
|
||||
`billing add`
|
||||
)}.`
|
||||
);
|
||||
return 1;
|
||||
@@ -157,6 +159,8 @@ export default async function transferIn(
|
||||
` To transfer with previous DNS records, export the zone file from your previous registrar.\n`
|
||||
);
|
||||
output.print(` Then import it to Vercel DNS by using:\n`);
|
||||
output.print(` ${cmd(`now dns import ${domainName} <zonefile>`)}\n\n`);
|
||||
output.print(
|
||||
` ${getCommandName(`dns import ${domainName} <zonefile>`)}\n\n`
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ import { NowContext } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import * as ERRORS from '../../util/errors-ts';
|
||||
import Client from '../../util/client';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import formatDnsTable from '../../util/format-dns-table';
|
||||
import formatNSTable from '../../util/format-ns-table';
|
||||
import getDomainByName from '../../util/domains/get-domain-by-name';
|
||||
import getScope from '../../util/get-scope';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import verifyDomain from '../../util/domains/verify-domain';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -46,14 +46,16 @@ export default async function verify(
|
||||
const [domainName] = args;
|
||||
|
||||
if (!domainName) {
|
||||
output.error(`${cmd('now domains verify <domain>')} expects one argument`);
|
||||
output.error(
|
||||
`${getCommandName(`domains verify <domain>`)} expects one argument`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.length !== 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now domains verify <domain>`'
|
||||
`${getCommandName('domains verify <domain>')}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
@@ -64,7 +66,7 @@ export default async function verify(
|
||||
output.error(
|
||||
`Domain not found by "${domainName}" under ${chalk.bold(contextName)}`
|
||||
);
|
||||
output.log(`Run ${cmd('now domains ls')} to see your domains.`);
|
||||
output.log(`Run ${getCommandName(`domains ls`)} to see your domains.`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -74,7 +76,7 @@ export default async function verify(
|
||||
contextName
|
||||
)}`
|
||||
);
|
||||
output.log(`Run ${cmd('now domains ls')} to see your domains.`);
|
||||
output.log(`Run ${getCommandName(`domains ls`)} to see your domains.`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -111,8 +113,8 @@ export default async function verify(
|
||||
)}\n\n`
|
||||
);
|
||||
output.print(
|
||||
` Once your domain uses either the nameservers or the TXT DNS record from above, run again ${cmd(
|
||||
'now domains verify <domain>'
|
||||
` Once your domain uses either the nameservers or the TXT DNS record from above, run again ${getCommandName(
|
||||
`domains verify <domain>`
|
||||
)}.\n`
|
||||
);
|
||||
output.print(
|
||||
@@ -137,8 +139,8 @@ export default async function verify(
|
||||
)} was verified using DNS TXT record. ${verifyStamp()}`
|
||||
);
|
||||
output.print(
|
||||
` You can verify with nameservers too. Run ${cmd(
|
||||
`now domains inspect ${domain.name}`
|
||||
` You can verify with nameservers too. Run ${getCommandName(
|
||||
`domains inspect ${domain.name}`
|
||||
)} to find out the intended set.\n`
|
||||
);
|
||||
return 0;
|
||||
|
||||
256
packages/now-cli/src/commands/env/add.ts
vendored
256
packages/now-cli/src/commands/env/add.ts
vendored
@@ -1,10 +1,9 @@
|
||||
import chalk from 'chalk';
|
||||
import inquirer from 'inquirer';
|
||||
import { NowContext, ProjectEnvTarget } from '../../types';
|
||||
import { ProjectEnvTarget, Project } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import Client from '../../util/client';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import { getLinkedProject } from '../../util/projects/link';
|
||||
import addEnvRecord from '../../util/env/add-env-record';
|
||||
import getEnvVariables from '../../util/env/get-env-records';
|
||||
import {
|
||||
@@ -13,160 +12,137 @@ import {
|
||||
getEnvTargetChoices,
|
||||
} from '../../util/env/env-target';
|
||||
import readStandardInput from '../../util/input/read-standard-input';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import param from '../../util/output/param';
|
||||
import withSpinner from '../../util/with-spinner';
|
||||
import { emoji, prependEmoji } from '../../util/emoji';
|
||||
import { isKnownError } from '../../util/env/known-error';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
};
|
||||
|
||||
export default async function add(
|
||||
ctx: NowContext,
|
||||
client: Client,
|
||||
project: Project,
|
||||
opts: Options,
|
||||
args: string[],
|
||||
output: Output
|
||||
) {
|
||||
const {
|
||||
authConfig: { token },
|
||||
config,
|
||||
} = ctx;
|
||||
const { currentTeam } = config;
|
||||
const { apiUrl } = ctx;
|
||||
const debug = opts['--debug'];
|
||||
const client = new Client({ apiUrl, token, currentTeam, debug });
|
||||
const link = await getLinkedProject(output, client);
|
||||
const stdInput = await readStandardInput();
|
||||
let [envName, envTarget] = args;
|
||||
|
||||
if (link.status === 'error') {
|
||||
return link.exitCode;
|
||||
} else if (link.status === 'not_linked') {
|
||||
output.print(
|
||||
`${chalk.red(
|
||||
'Error!'
|
||||
)} Your codebase isn’t linked to a project on Vercel. Run ${cmd(
|
||||
'now'
|
||||
)} to link it.\n`
|
||||
if (args.length > 2) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${getCommandName(
|
||||
`env add <name> ${getEnvTargetPlaceholder()}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
} else {
|
||||
const { project } = link;
|
||||
const stdInput = await readStandardInput();
|
||||
let [envName, envTarget] = args;
|
||||
|
||||
if (args.length > 2) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${cmd(
|
||||
`now env add <name> ${getEnvTargetPlaceholder()}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (stdInput && (!envName || !envTarget)) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${cmd(
|
||||
`now env add <name> <target> < <file>`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
let envTargets: ProjectEnvTarget[] = [];
|
||||
if (envTarget) {
|
||||
if (!isValidEnvTarget(envTarget)) {
|
||||
output.error(
|
||||
`The Environment ${param(
|
||||
envTarget
|
||||
)} is invalid. It must be one of: ${getEnvTargetPlaceholder()}.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
envTargets.push(envTarget);
|
||||
}
|
||||
|
||||
while (!envName) {
|
||||
const { inputName } = await inquirer.prompt({
|
||||
type: 'input',
|
||||
name: 'inputName',
|
||||
message: `What’s the name of the variable?`,
|
||||
});
|
||||
|
||||
envName = inputName;
|
||||
|
||||
if (!inputName) {
|
||||
output.error('Name cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
const envs = await getEnvVariables(output, client, project.id);
|
||||
const existing = new Set(
|
||||
envs.filter(r => r.key === envName).map(r => r.target)
|
||||
);
|
||||
const choices = getEnvTargetChoices().filter(c => !existing.has(c.value));
|
||||
|
||||
if (choices.length === 0) {
|
||||
output.error(
|
||||
`The variable ${param(
|
||||
envName
|
||||
)} has already been added to all Environments. To remove, run ${cmd(
|
||||
`now env rm ${envName}`
|
||||
)}.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
let envValue: string;
|
||||
|
||||
if (stdInput) {
|
||||
envValue = stdInput;
|
||||
} else {
|
||||
const { inputValue } = await inquirer.prompt({
|
||||
type: 'password',
|
||||
name: 'inputValue',
|
||||
message: `What’s the value of ${envName}?`,
|
||||
});
|
||||
envValue = inputValue || '';
|
||||
}
|
||||
|
||||
while (envTargets.length === 0) {
|
||||
const { inputTargets } = await inquirer.prompt({
|
||||
name: 'inputTargets',
|
||||
type: 'checkbox',
|
||||
message: `Add ${envName} to which Environments (select multiple)?`,
|
||||
choices,
|
||||
});
|
||||
|
||||
envTargets = inputTargets;
|
||||
|
||||
if (inputTargets.length === 0) {
|
||||
output.error('Please select at least one Environment');
|
||||
}
|
||||
}
|
||||
|
||||
const addStamp = stamp();
|
||||
try {
|
||||
await withSpinner('Saving', () =>
|
||||
addEnvRecord(output, client, project.id, envName, envValue, envTargets)
|
||||
);
|
||||
} catch (error) {
|
||||
if (isKnownError(error) && error.serverMessage) {
|
||||
output.error(error.serverMessage);
|
||||
return 1;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
output.print(
|
||||
`${prependEmoji(
|
||||
`Added Environment Variable ${chalk.bold(
|
||||
envName
|
||||
)} to Project ${chalk.bold(project.name)} ${chalk.gray(addStamp())}`,
|
||||
emoji('success')
|
||||
)}\n`
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (stdInput && (!envName || !envTarget)) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${getCommandName(
|
||||
`env add <name> <target> < <file>`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
let envTargets: ProjectEnvTarget[] = [];
|
||||
if (envTarget) {
|
||||
if (!isValidEnvTarget(envTarget)) {
|
||||
output.error(
|
||||
`The Environment ${param(
|
||||
envTarget
|
||||
)} is invalid. It must be one of: ${getEnvTargetPlaceholder()}.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
envTargets.push(envTarget);
|
||||
}
|
||||
|
||||
while (!envName) {
|
||||
const { inputName } = await inquirer.prompt({
|
||||
type: 'input',
|
||||
name: 'inputName',
|
||||
message: `What’s the name of the variable?`,
|
||||
});
|
||||
|
||||
envName = inputName;
|
||||
|
||||
if (!inputName) {
|
||||
output.error('Name cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
const envs = await getEnvVariables(output, client, project.id, 4);
|
||||
const existing = new Set(
|
||||
envs.filter(r => r.key === envName).map(r => r.target)
|
||||
);
|
||||
const choices = getEnvTargetChoices().filter(c => !existing.has(c.value));
|
||||
|
||||
if (choices.length === 0) {
|
||||
output.error(
|
||||
`The variable ${param(
|
||||
envName
|
||||
)} has already been added to all Environments. To remove, run ${getCommandName(
|
||||
`env rm ${envName}`
|
||||
)}.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
let envValue: string;
|
||||
|
||||
if (stdInput) {
|
||||
envValue = stdInput;
|
||||
} else {
|
||||
const { inputValue } = await inquirer.prompt({
|
||||
type: 'password',
|
||||
name: 'inputValue',
|
||||
message: `What’s the value of ${envName}?`,
|
||||
});
|
||||
envValue = inputValue || '';
|
||||
}
|
||||
|
||||
while (envTargets.length === 0) {
|
||||
const { inputTargets } = await inquirer.prompt({
|
||||
name: 'inputTargets',
|
||||
type: 'checkbox',
|
||||
message: `Add ${envName} to which Environments (select multiple)?`,
|
||||
choices,
|
||||
});
|
||||
|
||||
envTargets = inputTargets;
|
||||
|
||||
if (inputTargets.length === 0) {
|
||||
output.error('Please select at least one Environment');
|
||||
}
|
||||
}
|
||||
|
||||
const addStamp = stamp();
|
||||
try {
|
||||
await withSpinner('Saving', () =>
|
||||
addEnvRecord(output, client, project.id, envName, envValue, envTargets)
|
||||
);
|
||||
} catch (error) {
|
||||
if (isKnownError(error) && error.serverMessage) {
|
||||
output.error(error.serverMessage);
|
||||
return 1;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
output.print(
|
||||
`${prependEmoji(
|
||||
`Added Environment Variable ${chalk.bold(
|
||||
envName
|
||||
)} to Project ${chalk.bold(project.name)} ${chalk.gray(addStamp())}`,
|
||||
emoji('success')
|
||||
)}\n`
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
90
packages/now-cli/src/commands/env/index.ts
vendored
90
packages/now-cli/src/commands/env/index.ts
vendored
@@ -6,8 +6,11 @@ import getArgs from '../../util/get-args';
|
||||
import getSubcommand from '../../util/get-subcommand';
|
||||
import getInvalidSubcommand from '../../util/get-invalid-subcommand';
|
||||
import { getEnvTargetPlaceholder } from '../../util/env/env-target';
|
||||
import { getLinkedProject } from '../../util/projects/link';
|
||||
import Client from '../../util/client';
|
||||
import handleError from '../../util/handle-error';
|
||||
import logo from '../../util/output/logo';
|
||||
import { getCommandName, getPkgName } from '../../util/pkg-name';
|
||||
|
||||
import add from './add';
|
||||
import pull from './pull';
|
||||
@@ -17,7 +20,7 @@ import rm from './rm';
|
||||
const help = () => {
|
||||
const placeholder = getEnvTargetPlaceholder();
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now env`)} [options] <command>
|
||||
${chalk.bold(`${logo} ${getPkgName()} env`)} [options] <command>
|
||||
|
||||
${chalk.dim('Commands:')}
|
||||
|
||||
@@ -31,42 +34,51 @@ const help = () => {
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
)} Login token
|
||||
-N, --next Show next page of results
|
||||
|
||||
${chalk.dim('Examples:')}
|
||||
|
||||
${chalk.gray('–')} Add a new variable to multiple Environments
|
||||
|
||||
${chalk.cyan('$ now env add <name>')}
|
||||
${chalk.cyan('$ now env add API_TOKEN')}
|
||||
${chalk.cyan(`$ ${getPkgName()} env add <name>`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} env add API_TOKEN`)}
|
||||
|
||||
${chalk.gray('–')} Add a new variable for a specific Environment
|
||||
|
||||
${chalk.cyan(`$ now env add <name> ${placeholder}`)}
|
||||
${chalk.cyan('$ now env add DB_CONNECTION production')}
|
||||
${chalk.cyan(`$ ${getPkgName()} env add <name> ${placeholder}`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} env add DB_CONNECTION production`)}
|
||||
|
||||
${chalk.gray('–')} Add a new Environment Variable from stdin
|
||||
|
||||
${chalk.cyan(`$ cat <file> | now env add <name> ${placeholder}`)}
|
||||
${chalk.cyan('$ cat ~/.npmrc | now env add NPM_RC preview')}
|
||||
${chalk.cyan('$ now env add DB_PASS production < secret.txt')}
|
||||
${chalk.cyan(
|
||||
`$ cat <file> | ${getPkgName()} env add <name> ${placeholder}`
|
||||
)}
|
||||
${chalk.cyan(`$ cat ~/.npmrc | ${getPkgName()} env add NPM_RC preview`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} env add DB_PASS production < secret.txt`)}
|
||||
|
||||
${chalk.gray('–')} Remove an variable from multiple Environments
|
||||
|
||||
${chalk.cyan('$ now env rm <name>')}
|
||||
${chalk.cyan('$ now env rm API_TOKEN')}
|
||||
${chalk.cyan(`$ ${getPkgName()} env rm <name>`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} env rm API_TOKEN`)}
|
||||
|
||||
${chalk.gray('–')} Remove a variable from a specific Environment
|
||||
|
||||
${chalk.cyan(`$ now env rm <name> ${placeholder}`)}
|
||||
${chalk.cyan('$ now env rm NPM_RC preview')}
|
||||
${chalk.cyan(`$ ${getPkgName()} env rm <name> ${placeholder}`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} env rm NPM_RC preview`)}
|
||||
|
||||
${chalk.gray('–')} Paginate results, where ${chalk.dim(
|
||||
'`1584722256178`'
|
||||
)} is the time in milliseconds since the UNIX epoch.
|
||||
|
||||
${chalk.cyan(`$ ${getPkgName()} env ls --next 1584722256178`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -84,6 +96,8 @@ export default async function main(ctx: NowContext) {
|
||||
argv = getArgs(ctx.argv.slice(2), {
|
||||
'--yes': Boolean,
|
||||
'-y': '--yes',
|
||||
'--next': Number,
|
||||
'-N': '--next',
|
||||
});
|
||||
} catch (error) {
|
||||
handleError(error);
|
||||
@@ -95,20 +109,40 @@ export default async function main(ctx: NowContext) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
const output = createOutput({ debug: argv['--debug'] });
|
||||
const debug = argv['--debug'];
|
||||
const output = createOutput({ debug });
|
||||
const { subcommand, args } = getSubcommand(argv._.slice(1), COMMAND_CONFIG);
|
||||
switch (subcommand) {
|
||||
case 'ls':
|
||||
return ls(ctx, argv, args, output);
|
||||
case 'add':
|
||||
return add(ctx, argv, args, output);
|
||||
case 'rm':
|
||||
return rm(ctx, argv, args, output);
|
||||
case 'pull':
|
||||
return pull(ctx, argv, args, output);
|
||||
default:
|
||||
output.error(getInvalidSubcommand(COMMAND_CONFIG));
|
||||
help();
|
||||
return 2;
|
||||
const {
|
||||
authConfig: { token },
|
||||
config,
|
||||
} = ctx;
|
||||
const { currentTeam } = config;
|
||||
const { apiUrl } = ctx;
|
||||
const client = new Client({ apiUrl, token, currentTeam, debug });
|
||||
const link = await getLinkedProject(output, client);
|
||||
if (link.status === 'error') {
|
||||
return link.exitCode;
|
||||
} else if (link.status === 'not_linked') {
|
||||
output.error(
|
||||
`Your codebase isn’t linked to a project on Vercel. Run ${getCommandName()} to link it.`
|
||||
);
|
||||
return 1;
|
||||
} else {
|
||||
const { project, org } = link;
|
||||
client.currentTeam = org.type === 'team' ? org.id : undefined;
|
||||
switch (subcommand) {
|
||||
case 'ls':
|
||||
return ls(client, project, argv, args, output);
|
||||
case 'add':
|
||||
return add(client, project, argv, args, output);
|
||||
case 'rm':
|
||||
return rm(client, project, argv, args, output);
|
||||
case 'pull':
|
||||
return pull(client, project, argv, args, output);
|
||||
default:
|
||||
output.error(getInvalidSubcommand(COMMAND_CONFIG));
|
||||
help();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
119
packages/now-cli/src/commands/env/ls.ts
vendored
119
packages/now-cli/src/commands/env/ls.ts
vendored
@@ -1,8 +1,7 @@
|
||||
import chalk from 'chalk';
|
||||
import ms from 'ms';
|
||||
import plural from 'pluralize';
|
||||
import { Output } from '../../util/output';
|
||||
import { ProjectEnvVariable, ProjectEnvTarget, NowContext } from '../../types';
|
||||
import { ProjectEnvVariable, ProjectEnvTarget, Project } from '../../types';
|
||||
import Client from '../../util/client';
|
||||
import formatTable from '../../util/format-table';
|
||||
import getEnvVariables from '../../util/env/get-env-records';
|
||||
@@ -10,82 +9,78 @@ import {
|
||||
isValidEnvTarget,
|
||||
getEnvTargetPlaceholder,
|
||||
} from '../../util/env/env-target';
|
||||
import { getLinkedProject } from '../../util/projects/link';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import param from '../../util/output/param';
|
||||
import getCommandFlags from '../../util/get-command-flags';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
'--next'?: number;
|
||||
};
|
||||
|
||||
export default async function ls(
|
||||
ctx: NowContext,
|
||||
client: Client,
|
||||
project: Project,
|
||||
opts: Options,
|
||||
args: string[],
|
||||
output: Output
|
||||
) {
|
||||
const {
|
||||
authConfig: { token },
|
||||
config,
|
||||
} = ctx;
|
||||
const { currentTeam } = config;
|
||||
const { apiUrl } = ctx;
|
||||
const debug = opts['--debug'];
|
||||
const client = new Client({ apiUrl, token, currentTeam, debug });
|
||||
const link = await getLinkedProject(output, client);
|
||||
const { '--next': nextTimestamp } = opts;
|
||||
|
||||
if (link.status === 'error') {
|
||||
return link.exitCode;
|
||||
} else if (link.status === 'not_linked') {
|
||||
output.print(
|
||||
`${chalk.red(
|
||||
'Error!'
|
||||
)} Your codebase isn’t linked to a project on Vercel. Run ${cmd(
|
||||
'now'
|
||||
)} to link it.\n`
|
||||
if (args.length > 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${getCommandName(
|
||||
`env ls ${getEnvTargetPlaceholder()}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
} else {
|
||||
if (args.length > 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${cmd(
|
||||
`now env ls ${getEnvTargetPlaceholder()}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const { project } = link;
|
||||
const envTarget = args[0] as ProjectEnvTarget | undefined;
|
||||
|
||||
if (!isValidEnvTarget(envTarget)) {
|
||||
output.error(
|
||||
`The Environment ${param(
|
||||
envTarget
|
||||
)} is invalid. It must be one of: ${getEnvTargetPlaceholder()}.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const lsStamp = stamp();
|
||||
|
||||
const records = await getEnvVariables(
|
||||
output,
|
||||
client,
|
||||
project.id,
|
||||
envTarget
|
||||
);
|
||||
output.log(
|
||||
`${plural(
|
||||
'Environment Variable',
|
||||
records.length,
|
||||
true
|
||||
)} found in Project ${chalk.bold(project.name)} ${chalk.gray(lsStamp())}`
|
||||
);
|
||||
console.log(getTable(records));
|
||||
return 0;
|
||||
}
|
||||
|
||||
const envTarget = args[0] as ProjectEnvTarget | undefined;
|
||||
|
||||
if (!isValidEnvTarget(envTarget)) {
|
||||
output.error(
|
||||
`The Environment ${param(
|
||||
envTarget
|
||||
)} is invalid. It must be one of: ${getEnvTargetPlaceholder()}.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const lsStamp = stamp();
|
||||
|
||||
if (typeof nextTimestamp !== 'undefined' && Number.isNaN(nextTimestamp)) {
|
||||
output.error('Please provide a number for flag --next');
|
||||
return 1;
|
||||
}
|
||||
|
||||
const data = await getEnvVariables(
|
||||
output,
|
||||
client,
|
||||
project.id,
|
||||
5,
|
||||
envTarget,
|
||||
nextTimestamp
|
||||
);
|
||||
const { envs: records, pagination } = data;
|
||||
output.log(
|
||||
`${
|
||||
records.length > 0 ? 'Environment Variables' : 'No Environment Variables'
|
||||
} found in Project ${chalk.bold(project.name)} ${chalk.gray(lsStamp())}`
|
||||
);
|
||||
console.log(getTable(records));
|
||||
|
||||
if (pagination && pagination.count === 20) {
|
||||
const flags = getCommandFlags(opts, ['_', '--next']);
|
||||
output.log(
|
||||
`To display the next page run ${getCommandName(
|
||||
`env ls${flags} --next ${pagination.next}`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getTable(records: ProjectEnvVariable[]) {
|
||||
|
||||
140
packages/now-cli/src/commands/env/pull.ts
vendored
140
packages/now-cli/src/commands/env/pull.ts
vendored
@@ -1,18 +1,17 @@
|
||||
import chalk from 'chalk';
|
||||
import { NowContext, ProjectEnvTarget } from '../../types';
|
||||
import { ProjectEnvTarget, Project } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import promptBool from '../../util/prompt-bool';
|
||||
import Client from '../../util/client';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import getEnvVariables from '../../util/env/get-env-records';
|
||||
import getDecryptedSecret from '../../util/env/get-decrypted-secret';
|
||||
import { getLinkedProject } from '../../util/projects/link';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import param from '../../util/output/param';
|
||||
import withSpinner from '../../util/with-spinner';
|
||||
import { join } from 'path';
|
||||
import { promises, existsSync } from 'fs';
|
||||
import { emoji, prependEmoji } from '../../util/emoji';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
const { writeFile } = promises;
|
||||
|
||||
type Options = {
|
||||
@@ -21,95 +20,72 @@ type Options = {
|
||||
};
|
||||
|
||||
export default async function pull(
|
||||
ctx: NowContext,
|
||||
client: Client,
|
||||
project: Project,
|
||||
opts: Options,
|
||||
args: string[],
|
||||
output: Output
|
||||
) {
|
||||
const {
|
||||
authConfig: { token },
|
||||
config,
|
||||
} = ctx;
|
||||
const { currentTeam } = config;
|
||||
const { apiUrl } = ctx;
|
||||
const debug = opts['--debug'];
|
||||
const client = new Client({ apiUrl, token, currentTeam, debug });
|
||||
const link = await getLinkedProject(output, client);
|
||||
|
||||
if (link.status === 'error') {
|
||||
return link.exitCode;
|
||||
} else if (link.status === 'not_linked') {
|
||||
output.print(
|
||||
`${chalk.red(
|
||||
'Error!'
|
||||
)} Your codebase isn’t linked to a project on Vercel. Run ${cmd(
|
||||
'now'
|
||||
)} to link it.\n`
|
||||
if (args.length > 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${getCommandName(`env pull <file>`)}`
|
||||
);
|
||||
return 1;
|
||||
} else {
|
||||
if (args.length > 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${cmd('now env pull <file>')}`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
const { project } = link;
|
||||
const [filename = '.env'] = args;
|
||||
const fullPath = join(process.cwd(), filename);
|
||||
const exists = existsSync(fullPath);
|
||||
const skipConfirmation = opts['--yes'];
|
||||
const [filename = '.env'] = args;
|
||||
const fullPath = join(process.cwd(), filename);
|
||||
const exists = existsSync(fullPath);
|
||||
const skipConfirmation = opts['--yes'];
|
||||
|
||||
if (
|
||||
exists &&
|
||||
!skipConfirmation &&
|
||||
!(await promptBool(
|
||||
output,
|
||||
`Found existing file ${param(filename)}. Do you want to overwrite?`
|
||||
))
|
||||
) {
|
||||
output.log('Aborted');
|
||||
return 0;
|
||||
}
|
||||
|
||||
output.print(
|
||||
`Downloading Development Environment Variables for Project ${chalk.bold(
|
||||
project.name
|
||||
)}\n`
|
||||
);
|
||||
const pullStamp = stamp();
|
||||
|
||||
const records = await withSpinner('Downloading', async () => {
|
||||
const dev = ProjectEnvTarget.Development;
|
||||
const envs = await getEnvVariables(output, client, project.id, dev);
|
||||
const values = await Promise.all(
|
||||
envs.map(env => getDecryptedSecret(output, client, env.value))
|
||||
);
|
||||
const results: { key: string; value: string }[] = [];
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
results.push({ key: envs[i].key, value: values[i] });
|
||||
}
|
||||
return results;
|
||||
});
|
||||
|
||||
const contents =
|
||||
records
|
||||
.map(({ key, value }) => `${key}="${escapeValue(value)}"`)
|
||||
.join('\n') + '\n';
|
||||
|
||||
await writeFile(fullPath, contents, 'utf8');
|
||||
|
||||
output.print(
|
||||
`${prependEmoji(
|
||||
`${exists ? 'Updated' : 'Created'} ${chalk.bold(
|
||||
filename
|
||||
)} file ${chalk.gray(pullStamp())}`,
|
||||
emoji('success')
|
||||
)}\n`
|
||||
);
|
||||
if (
|
||||
exists &&
|
||||
!skipConfirmation &&
|
||||
!(await promptBool(
|
||||
output,
|
||||
`Found existing file ${param(filename)}. Do you want to overwrite?`
|
||||
))
|
||||
) {
|
||||
output.log('Aborted');
|
||||
return 0;
|
||||
}
|
||||
|
||||
output.print(
|
||||
`Downloading Development Environment Variables for Project ${chalk.bold(
|
||||
project.name
|
||||
)}\n`
|
||||
);
|
||||
const pullStamp = stamp();
|
||||
|
||||
const records = await withSpinner('Downloading', async () => {
|
||||
const dev = ProjectEnvTarget.Development;
|
||||
const envs = await getEnvVariables(output, client, project.id, 4, dev);
|
||||
const values = await Promise.all(
|
||||
envs.map(env => getDecryptedSecret(output, client, env.value))
|
||||
);
|
||||
const results: { key: string; value: string }[] = [];
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
results.push({ key: envs[i].key, value: values[i] });
|
||||
}
|
||||
return results;
|
||||
});
|
||||
|
||||
const contents =
|
||||
records
|
||||
.map(({ key, value }) => `${key}="${escapeValue(value)}"`)
|
||||
.join('\n') + '\n';
|
||||
|
||||
await writeFile(fullPath, contents, 'utf8');
|
||||
|
||||
output.print(
|
||||
`${prependEmoji(
|
||||
`${exists ? 'Updated' : 'Created'} ${chalk.bold(
|
||||
filename
|
||||
)} file ${chalk.gray(pullStamp())}`,
|
||||
emoji('success')
|
||||
)}\n`
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
function escapeValue(value: string) {
|
||||
|
||||
212
packages/now-cli/src/commands/env/rm.ts
vendored
212
packages/now-cli/src/commands/env/rm.ts
vendored
@@ -1,9 +1,8 @@
|
||||
import chalk from 'chalk';
|
||||
import inquirer from 'inquirer';
|
||||
import { NowContext, ProjectEnvTarget } from '../../types';
|
||||
import { ProjectEnvTarget, Project } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import promptBool from '../../util/prompt-bool';
|
||||
import { getLinkedProject } from '../../util/projects/link';
|
||||
import removeEnvRecord from '../../util/env/remove-env-record';
|
||||
import getEnvVariables from '../../util/env/get-env-records';
|
||||
import {
|
||||
@@ -13,11 +12,11 @@ import {
|
||||
} from '../../util/env/env-target';
|
||||
import Client from '../../util/client';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import param from '../../util/output/param';
|
||||
import withSpinner from '../../util/with-spinner';
|
||||
import { emoji, prependEmoji } from '../../util/emoji';
|
||||
import { isKnownError } from '../../util/env/known-error';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -25,144 +24,119 @@ type Options = {
|
||||
};
|
||||
|
||||
export default async function rm(
|
||||
ctx: NowContext,
|
||||
client: Client,
|
||||
project: Project,
|
||||
opts: Options,
|
||||
args: string[],
|
||||
output: Output
|
||||
) {
|
||||
const {
|
||||
authConfig: { token },
|
||||
config,
|
||||
} = ctx;
|
||||
const { currentTeam } = config;
|
||||
const { apiUrl } = ctx;
|
||||
const debug = opts['--debug'];
|
||||
const client = new Client({ apiUrl, token, currentTeam, debug });
|
||||
const link = await getLinkedProject(output, client);
|
||||
|
||||
if (link.status === 'error') {
|
||||
return link.exitCode;
|
||||
} else if (link.status === 'not_linked') {
|
||||
output.print(
|
||||
`${chalk.red(
|
||||
'Error!'
|
||||
)} Your codebase isn’t linked to a project on Vercel. Run ${cmd(
|
||||
'now'
|
||||
)} to link it.\n`
|
||||
if (args.length > 2) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${getCommandName(
|
||||
`env rm <name> ${getEnvTargetPlaceholder()}`
|
||||
)}`
|
||||
);
|
||||
return 1;
|
||||
} else {
|
||||
if (args.length > 2) {
|
||||
}
|
||||
|
||||
let [envName, envTarget] = args;
|
||||
let envTargets: ProjectEnvTarget[] = [];
|
||||
|
||||
if (envTarget) {
|
||||
if (!isValidEnvTarget(envTarget)) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${cmd(
|
||||
`now env rm <name> ${getEnvTargetPlaceholder()}`
|
||||
)}`
|
||||
`The Environment ${param(
|
||||
envTarget
|
||||
)} is invalid. It must be one of: ${getEnvTargetPlaceholder()}.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
envTargets.push(envTarget);
|
||||
}
|
||||
|
||||
const { project } = link;
|
||||
let [envName, envTarget] = args;
|
||||
let envTargets: ProjectEnvTarget[] = [];
|
||||
while (!envName) {
|
||||
const { inputName } = await inquirer.prompt({
|
||||
type: 'input',
|
||||
name: 'inputName',
|
||||
message: `What’s the name of the variable?`,
|
||||
});
|
||||
|
||||
if (envTarget) {
|
||||
if (!isValidEnvTarget(envTarget)) {
|
||||
output.error(
|
||||
`The Environment ${param(
|
||||
envTarget
|
||||
)} is invalid. It must be one of: ${getEnvTargetPlaceholder()}.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
envTargets.push(envTarget);
|
||||
if (!inputName) {
|
||||
output.error(`Name cannot be empty`);
|
||||
continue;
|
||||
}
|
||||
|
||||
while (!envName) {
|
||||
const { inputName } = await inquirer.prompt({
|
||||
type: 'input',
|
||||
name: 'inputName',
|
||||
message: `What’s the name of the variable?`,
|
||||
});
|
||||
envName = inputName;
|
||||
}
|
||||
|
||||
if (!inputName) {
|
||||
output.error(`Name cannot be empty`);
|
||||
continue;
|
||||
}
|
||||
const envs = await getEnvVariables(output, client, project.id, 4);
|
||||
const existing = new Set(
|
||||
envs.filter(r => r.key === envName).map(r => r.target)
|
||||
);
|
||||
|
||||
envName = inputName;
|
||||
}
|
||||
if (existing.size === 0) {
|
||||
output.error(`The Environment Variable ${param(envName)} was not found.\n`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const envs = await getEnvVariables(output, client, project.id);
|
||||
const existing = new Set(
|
||||
envs.filter(r => r.key === envName).map(r => r.target)
|
||||
);
|
||||
|
||||
if (existing.size === 0) {
|
||||
if (envTargets.length === 0) {
|
||||
const choices = getEnvTargetChoices().filter(c => existing.has(c.value));
|
||||
if (choices.length === 0) {
|
||||
output.error(
|
||||
`The Environment Variable ${param(envName)} was not found.\n`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (envTargets.length === 0) {
|
||||
const choices = getEnvTargetChoices().filter(c => existing.has(c.value));
|
||||
if (choices.length === 0) {
|
||||
output.error(
|
||||
`The Environment Variable ${param(
|
||||
envName
|
||||
)} was found but it is not assigned to any Environments.\n`
|
||||
);
|
||||
return 1;
|
||||
} else if (choices.length === 1) {
|
||||
envTargets = [choices[0].value];
|
||||
} else {
|
||||
const { inputTargets } = await inquirer.prompt({
|
||||
name: 'inputTargets',
|
||||
type: 'checkbox',
|
||||
message: `Remove ${envName} from which Environments (select multiple)?`,
|
||||
choices,
|
||||
});
|
||||
envTargets = inputTargets;
|
||||
}
|
||||
}
|
||||
|
||||
const skipConfirmation = opts['--yes'];
|
||||
if (
|
||||
!skipConfirmation &&
|
||||
!(await promptBool(
|
||||
output,
|
||||
`Removing Environment Variable ${param(
|
||||
`The Environment Variable ${param(
|
||||
envName
|
||||
)} from Project ${chalk.bold(project.name)}. Are you sure?`
|
||||
))
|
||||
) {
|
||||
output.log('Aborted');
|
||||
return 0;
|
||||
}
|
||||
|
||||
const rmStamp = stamp();
|
||||
|
||||
try {
|
||||
await withSpinner('Removing', async () => {
|
||||
for (const target of envTargets) {
|
||||
await removeEnvRecord(output, client, project.id, envName, target);
|
||||
}
|
||||
)} was found but it is not assigned to any Environments.\n`
|
||||
);
|
||||
return 1;
|
||||
} else if (choices.length === 1) {
|
||||
envTargets = [choices[0].value];
|
||||
} else {
|
||||
const { inputTargets } = await inquirer.prompt({
|
||||
name: 'inputTargets',
|
||||
type: 'checkbox',
|
||||
message: `Remove ${envName} from which Environments (select multiple)?`,
|
||||
choices,
|
||||
});
|
||||
} catch (error) {
|
||||
if (isKnownError(error) && error.serverMessage) {
|
||||
output.error(error.serverMessage);
|
||||
return 1;
|
||||
}
|
||||
throw error;
|
||||
envTargets = inputTargets;
|
||||
}
|
||||
}
|
||||
|
||||
output.print(
|
||||
`${prependEmoji(
|
||||
`Removed Environment Variable ${chalk.gray(rmStamp())}`,
|
||||
emoji('success')
|
||||
)}\n`
|
||||
);
|
||||
|
||||
const skipConfirmation = opts['--yes'];
|
||||
if (
|
||||
!skipConfirmation &&
|
||||
!(await promptBool(
|
||||
output,
|
||||
`Removing Environment Variable ${param(
|
||||
envName
|
||||
)} from Project ${chalk.bold(project.name)}. Are you sure?`
|
||||
))
|
||||
) {
|
||||
output.log('Aborted');
|
||||
return 0;
|
||||
}
|
||||
|
||||
const rmStamp = stamp();
|
||||
|
||||
try {
|
||||
await withSpinner('Removing', async () => {
|
||||
for (const target of envTargets) {
|
||||
await removeEnvRecord(output, client, project.id, envName, target);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
if (isKnownError(error) && error.serverMessage) {
|
||||
output.error(error.serverMessage);
|
||||
return 1;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
output.print(
|
||||
`${prependEmoji(
|
||||
`Removed Environment Variable ${chalk.gray(rmStamp())}`,
|
||||
emoji('success')
|
||||
)}\n`
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,14 +8,15 @@ import createOutput from '../../util/output/create-output';
|
||||
import logo from '../../util/output/logo';
|
||||
import error from '../../util/output/error';
|
||||
import init from './init';
|
||||
import { getPkgName } from '../../util/pkg-name';
|
||||
|
||||
const COMMAND_CONFIG = {
|
||||
init: ['init']
|
||||
init: ['init'],
|
||||
};
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now init`)} [example] [dir] [-f | --force]
|
||||
${chalk.bold(`${logo} ${getPkgName()} init`)} [example] [dir] [-f | --force]
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
@@ -27,19 +28,19 @@ const help = () => {
|
||||
|
||||
${chalk.gray('–')} Choose from all available examples
|
||||
|
||||
${chalk.cyan(`$ now init`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} init`)}
|
||||
|
||||
${chalk.gray('–')} Initialize example project into a new directory
|
||||
|
||||
${chalk.cyan(`$ now init <example>`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} init <example>`)}
|
||||
|
||||
${chalk.gray('–')} Initialize example project into specified directory
|
||||
|
||||
${chalk.cyan(`$ now init <example> <dir>`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} init <example> <dir>`)}
|
||||
|
||||
${chalk.gray('–')} Initialize example project without checking
|
||||
|
||||
${chalk.cyan(`$ now init <example> --force`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} init <example> --force`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -51,7 +52,7 @@ export default async function main(ctx: NowContext) {
|
||||
try {
|
||||
argv = getArgs(ctx.argv.slice(2), {
|
||||
'--force': Boolean,
|
||||
'-f': Boolean
|
||||
'-f': Boolean,
|
||||
});
|
||||
args = getSubcommand(argv._.slice(1), COMMAND_CONFIG).args;
|
||||
output = createOutput({ debug: argv['--debug'] });
|
||||
|
||||
@@ -15,6 +15,7 @@ import success from '../../util/output/success';
|
||||
import info from '../../util/output/info';
|
||||
import cmd from '../../util/output/cmd';
|
||||
import didYouMean from '../../util/init/did-you-mean';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -152,9 +153,11 @@ async function extractExample(
|
||||
const folderRel = path.relative(process.cwd(), folder);
|
||||
const deployHint =
|
||||
folderRel === ''
|
||||
? listItem(`To deploy, run ${cmd('now')}.`)
|
||||
? listItem(`To deploy, run ${getCommandName()}.`)
|
||||
: listItem(
|
||||
`To deploy, ${cmd(`cd ${folderRel}`)} and run ${cmd('now')}.`
|
||||
`To deploy, ${cmd(
|
||||
`cd ${folderRel}`
|
||||
)} and run ${getCommandName()}.`
|
||||
);
|
||||
console.log(success(`${successLog}\n${deployHint}`));
|
||||
return 0;
|
||||
@@ -204,8 +207,8 @@ function prepareFolder(cwd: string, folder: string, force?: boolean) {
|
||||
*/
|
||||
async function guess(exampleList: string[], name: string) {
|
||||
const GuessError = new Error(
|
||||
`No example found for ${chalk.bold(name)}, run ${cmd(
|
||||
`now init`
|
||||
`No example found for ${chalk.bold(name)}, run ${getCommandName(
|
||||
`init`
|
||||
)} to see the list of available examples.`
|
||||
);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import getArgs from '../util/get-args';
|
||||
import buildsList from '../util/output/builds';
|
||||
import routesList from '../util/output/routes';
|
||||
import indent from '../util/output/indent';
|
||||
import cmd from '../util/output/cmd.ts';
|
||||
import createOutput from '../util/output';
|
||||
import Now from '../util';
|
||||
import logo from '../util/output/logo';
|
||||
@@ -13,22 +12,23 @@ import { handleError } from '../util/error';
|
||||
import strlen from '../util/strlen.ts';
|
||||
import Client from '../util/client.ts';
|
||||
import getScope from '../util/get-scope.ts';
|
||||
import { getPkgName, getCommandName } from '../util/pkg-name.ts';
|
||||
|
||||
const STATIC = 'STATIC';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now inspect`)} <url>
|
||||
${chalk.bold(`${logo} ${getPkgName()} inspect`)} <url>
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
)} Login token
|
||||
@@ -39,11 +39,11 @@ const help = () => {
|
||||
|
||||
${chalk.gray('–')} Get information about a deployment by its unique URL
|
||||
|
||||
${chalk.cyan('$ now inspect my-deployment-ji2fjij2.now.sh')}
|
||||
${chalk.cyan(`$ ${getPkgName()} inspect my-deployment-ji2fjij2.now.sh`)}
|
||||
|
||||
${chalk.gray('-')} Get information about the deployment an alias points to
|
||||
|
||||
${chalk.cyan('$ now inspect my-deployment.now.sh')}
|
||||
${chalk.cyan(`$ ${getPkgName()} inspect my-deployment.now.sh`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -73,7 +73,7 @@ export default async function main(ctx) {
|
||||
id = argv._[1];
|
||||
|
||||
if (argv._.length !== 2) {
|
||||
error(`${cmd('now inspect <url>')} expects exactly one argument`);
|
||||
error(`${getCommandName('inspect <url>')} expects exactly one argument`);
|
||||
help();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -18,20 +18,21 @@ import toHost from '../util/to-host';
|
||||
import parseMeta from '../util/parse-meta';
|
||||
import { isValidName } from '../util/is-valid-name';
|
||||
import getCommandFlags from '../util/get-command-flags';
|
||||
import { getPkgName, getCommandName } from '../util/pkg-name.ts';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now list`)} [app]
|
||||
${chalk.bold(`${logo} ${getPkgName()} list`)} [app]
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
@@ -47,27 +48,27 @@ const help = () => {
|
||||
|
||||
${chalk.gray('–')} List all deployments
|
||||
|
||||
${chalk.cyan('$ now ls')}
|
||||
${chalk.cyan(`$ ${getPkgName()} ls`)}
|
||||
|
||||
${chalk.gray('–')} List all deployments for the app ${chalk.dim('`my-app`')}
|
||||
|
||||
${chalk.cyan('$ now ls my-app')}
|
||||
${chalk.cyan(`$ ${getPkgName()} ls my-app`)}
|
||||
|
||||
${chalk.gray(
|
||||
'–'
|
||||
)} List all deployments and all instances for the app ${chalk.dim('`my-app`')}
|
||||
|
||||
${chalk.cyan('$ now ls my-app --all')}
|
||||
${chalk.cyan(`$ ${getPkgName()} ls my-app --all`)}
|
||||
|
||||
${chalk.gray('–')} Filter deployments by metadata
|
||||
|
||||
${chalk.cyan('$ now ls -m key1=value1 -m key2=value2')}
|
||||
|
||||
${chalk.cyan(`$ ${getPkgName()} ls -m key1=value1 -m key2=value2`)}
|
||||
|
||||
${chalk.gray('–')} Paginate deployments for a project, where ${chalk.dim(
|
||||
'`1584722256178`'
|
||||
)} is the time in milliseconds since the UNIX epoch.
|
||||
|
||||
${chalk.cyan(`$ now ls my-app --next 1584722256178`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} ls my-app --next 1584722256178`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -97,7 +98,7 @@ export default async function main(ctx) {
|
||||
});
|
||||
|
||||
if (argv._.length > 2) {
|
||||
error(`${cmd('now ls [app]')} accepts at most one argument`);
|
||||
error(`${getCommandName('ls [app]')} accepts at most one argument`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -162,12 +163,14 @@ export default async function main(ctx) {
|
||||
|
||||
// Some people are using entire domains as app names, so
|
||||
// we need to account for this here
|
||||
if (app && toHost(app).endsWith('.now.sh')) {
|
||||
const asHost = app ? toHost(app) : '';
|
||||
if (asHost.endsWith('.now.sh') || asHost.endsWith('.vercel.app')) {
|
||||
note(
|
||||
'We suggest using `now inspect <deployment>` for retrieving details about a single deployment'
|
||||
`We suggest using ${getCommandName(
|
||||
'inspect <deployment>'
|
||||
)} for retrieving details about a single deployment`
|
||||
);
|
||||
|
||||
const asHost = toHost(app);
|
||||
const hostParts = asHost.split('-');
|
||||
|
||||
if (hostParts < 2) {
|
||||
@@ -233,7 +236,7 @@ export default async function main(ctx) {
|
||||
now.close();
|
||||
stopSpinner();
|
||||
log(`Found matching path alias: ${chalk.cyan(item.alias)}`);
|
||||
log(`Please run ${cmd(`now alias ls ${item.alias}`)} instead`);
|
||||
log(`Please run ${getCommandName(`alias ls ${item.alias}`)} instead`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -283,10 +286,16 @@ export default async function main(ctx) {
|
||||
// information to help the user find other deployments or instances
|
||||
if (app == null) {
|
||||
log(
|
||||
`To list more deployments for a project run ${cmd('now ls [project]')}`
|
||||
`To list more deployments for a project run ${cmd(
|
||||
`${getCommandName('ls [project]')}`
|
||||
)}`
|
||||
);
|
||||
} else if (!argv['--all']) {
|
||||
log(`To list deployment instances run ${cmd('now ls --all [project]')}`);
|
||||
log(
|
||||
`To list deployment instances run ${cmd(
|
||||
`${getCommandName('ls --all [project]')}`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
print('\n');
|
||||
@@ -339,8 +348,8 @@ export default async function main(ctx) {
|
||||
if (pagination && pagination.count === 20) {
|
||||
const flags = getCommandFlags(argv, ['_', '--next']);
|
||||
log(
|
||||
`To display the next page run ${cmd(
|
||||
`now ls${app ? ' ' + app : ''}${flags} --next ${pagination.next}`
|
||||
`To display the next page run ${getCommandName(
|
||||
`ls${app ? ' ' + app : ''}${flags} --next ${pagination.next}`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,45 +10,45 @@ import getArgs from '../util/get-args';
|
||||
import error from '../util/output/error';
|
||||
import highlight from '../util/output/highlight';
|
||||
import ok from '../util/output/ok';
|
||||
import cmd from '../util/output/cmd.ts';
|
||||
import param from '../util/output/param.ts';
|
||||
import eraseLines from '../util/output/erase-lines';
|
||||
import sleep from '../util/sleep';
|
||||
import { handleError } from '../util/error';
|
||||
import { writeToAuthConfigFile, writeToConfigFile } from '../util/config/files';
|
||||
import getNowDir from '../util/config/global-path';
|
||||
import getGlobalPathConfig from '../util/config/global-path';
|
||||
import hp from '../util/humanize-path';
|
||||
import logo from '../util/output/logo';
|
||||
import exit from '../util/exit';
|
||||
import createOutput from '../util/output';
|
||||
import executeLogin from '../util/login/login.ts';
|
||||
import { prependEmoji, emoji } from '../util/emoji';
|
||||
import { getCommandName, getPkgName } from '../util/pkg-name.ts';
|
||||
|
||||
const debug = debugFactory('now:sh:login');
|
||||
const debug = debugFactory(`${getPkgName()}:login`);
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now login`)} <email>
|
||||
${chalk.bold(`${logo} ${getPkgName()} login`)} <email>
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
|
||||
${chalk.dim('Examples:')}
|
||||
|
||||
${chalk.gray('–')} Log into the Now platform
|
||||
${chalk.gray('–')} Log into the Vercel platform
|
||||
|
||||
${chalk.cyan('$ now login')}
|
||||
${chalk.cyan(`$ ${getPkgName()} login`)}
|
||||
|
||||
${chalk.gray('–')} Log in using a specific email address
|
||||
|
||||
${chalk.cyan('$ now login john@doe.com')}
|
||||
${chalk.cyan(`$ ${getPkgName()} login john@doe.com`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -114,8 +114,8 @@ const readEmail = async () => {
|
||||
if (err.message === 'stdin lacks setRawMode support') {
|
||||
throw new Error(
|
||||
error(
|
||||
`Interactive mode not supported – please run ${cmd(
|
||||
'now login you@domain.com'
|
||||
`Interactive mode not supported – please run ${getCommandName(
|
||||
`login you@domain.com`
|
||||
)}`
|
||||
)
|
||||
);
|
||||
@@ -248,11 +248,11 @@ const login = async ctx => {
|
||||
writeToAuthConfigFile(ctx.authConfig);
|
||||
writeToConfigFile(ctx.config);
|
||||
|
||||
output.debug(`Saved credentials in "${hp(getNowDir())}"`);
|
||||
output.debug(`Saved credentials in "${hp(getGlobalPathConfig())}"`);
|
||||
|
||||
console.log(
|
||||
`${chalk.cyan('Congratulations!')} ` +
|
||||
`You are now logged in. In order to deploy something, run ${cmd('now')}.`
|
||||
`You are now logged in. In order to deploy something, run ${getCommandName()}.`
|
||||
);
|
||||
|
||||
output.print(
|
||||
|
||||
@@ -12,26 +12,27 @@ import {
|
||||
import getArgs from '../util/get-args';
|
||||
import { NowContext } from '../types';
|
||||
import createOutput, { Output } from '../util/output';
|
||||
import { getPkgName } from '../util/pkg-name';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now logout`)}
|
||||
${chalk.bold(`${logo} ${getPkgName()} logout`)}
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
|
||||
${chalk.dim('Examples:')}
|
||||
|
||||
${chalk.gray('–')} Logout from the CLI:
|
||||
|
||||
${chalk.cyan('$ now logout')}
|
||||
${chalk.cyan(`$ ${getPkgName()} logout`)}
|
||||
`);
|
||||
};
|
||||
|
||||
|
||||
@@ -8,20 +8,21 @@ import { maybeURL, normalizeURL } from '../util/url';
|
||||
import printEvents from '../util/events';
|
||||
import Client from '../util/client.ts';
|
||||
import getScope from '../util/get-scope.ts';
|
||||
import { getPkgName } from '../util/pkg-name.ts';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now logs`)} <url|deploymentId>
|
||||
${chalk.bold(`${logo} ${getPkgName()} logs`)} <url|deploymentId>
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-f, --follow Wait for additional data [off]
|
||||
-n ${chalk.bold.underline(
|
||||
@@ -49,7 +50,7 @@ const help = () => {
|
||||
'`deploymentId`'
|
||||
)}
|
||||
|
||||
${chalk.cyan('$ now logs deploymentId')}
|
||||
${chalk.cyan(`$ ${getPkgName()} logs deploymentId`)}
|
||||
`);
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import chalk from 'chalk';
|
||||
import table from 'text-table';
|
||||
import mri from 'mri';
|
||||
import ms from 'ms';
|
||||
import plural from 'pluralize';
|
||||
import strlen from '../util/strlen';
|
||||
import { handleError, error } from '../util/error';
|
||||
import exit from '../util/exit';
|
||||
@@ -10,12 +9,16 @@ import Client from '../util/client.ts';
|
||||
import logo from '../util/output/logo';
|
||||
import getScope from '../util/get-scope';
|
||||
import createOutput from '../util/output';
|
||||
import getCommandFlags from '../util/get-command-flags';
|
||||
import wait from '../util/output/wait';
|
||||
import getPrefixedFlags from '../util/get-prefixed-flags';
|
||||
import { getPkgName, getCommandName } from '../util/pkg-name.ts';
|
||||
|
||||
const e = encodeURIComponent;
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now projects`)} [options] <command>
|
||||
${chalk.bold(`${logo} ${getPkgName()} projects`)} [options] <command>
|
||||
|
||||
${chalk.dim('Commands:')}
|
||||
|
||||
@@ -30,12 +33,19 @@ const help = () => {
|
||||
'TOKEN'
|
||||
)} Login token
|
||||
-S, --scope Set a custom scope
|
||||
-N, --next Show next page of results
|
||||
|
||||
${chalk.dim('Examples:')}
|
||||
|
||||
${chalk.gray('–')} Add a new project
|
||||
|
||||
${chalk.cyan('$ now projects add my-project')}
|
||||
${chalk.cyan(`$ ${getPkgName()} projects add my-project`)}
|
||||
|
||||
${chalk.gray('–')} Paginate projects, where ${chalk.dim(
|
||||
'`1584722256178`'
|
||||
)} is the time in milliseconds since the UNIX epoch.
|
||||
|
||||
${chalk.cyan(`$ ${getPkgName()} projects ls --next 1584722256178`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -50,6 +60,7 @@ const main = async ctx => {
|
||||
boolean: ['help'],
|
||||
alias: {
|
||||
help: 'h',
|
||||
next: 'N',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -111,20 +122,33 @@ async function run({ client, contextName }) {
|
||||
console.error(
|
||||
error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now projects ls`'
|
||||
`${getCommandName('projects ls')}`
|
||||
)}`
|
||||
)
|
||||
);
|
||||
return exit(1);
|
||||
}
|
||||
|
||||
const list = await client.fetch('/v2/projects/', { method: 'GET' });
|
||||
const stopSpinner = wait(`Fetching projects in ${chalk.bold(contextName)}`);
|
||||
|
||||
let projectsUrl = '/v4/projects/?limit=20';
|
||||
|
||||
if (argv.next) {
|
||||
projectsUrl += `&until=${argv.next}`;
|
||||
}
|
||||
|
||||
const { projects: list, pagination } = await client.fetch(projectsUrl, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
stopSpinner();
|
||||
|
||||
const elapsed = ms(new Date() - start);
|
||||
|
||||
console.log(
|
||||
`> ${plural('project', list.length, true)} found under ${chalk.bold(
|
||||
contextName
|
||||
)} ${chalk.gray(`[${elapsed}]`)}`
|
||||
`> ${
|
||||
list.length > 0 ? 'Projects' : 'No projects'
|
||||
} found under ${chalk.bold(contextName)} ${chalk.gray(`[${elapsed}]`)}`
|
||||
);
|
||||
|
||||
if (list.length > 0) {
|
||||
@@ -149,6 +173,19 @@ async function run({ client, contextName }) {
|
||||
if (out) {
|
||||
console.log(`\n${out}\n`);
|
||||
}
|
||||
|
||||
if (pagination && pagination.count === 20) {
|
||||
const prefixedArgs = getPrefixedFlags(argv);
|
||||
const flags = getCommandFlags(prefixedArgs, [
|
||||
'_',
|
||||
'--next',
|
||||
'-N',
|
||||
'-d',
|
||||
'-y',
|
||||
]);
|
||||
const nextCmd = `projects ls${flags} --next ${pagination.next}`;
|
||||
console.log(`To display the next page run ${getCommandName(nextCmd)}`);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -158,7 +195,7 @@ async function run({ client, contextName }) {
|
||||
console.error(
|
||||
error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now project rm <name>`'
|
||||
`${getCommandName('project rm <name>')}`
|
||||
)}`
|
||||
)
|
||||
);
|
||||
@@ -200,13 +237,15 @@ async function run({ client, contextName }) {
|
||||
console.error(
|
||||
error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now projects add <name>`'
|
||||
`${getCommandName('projects add <name>')}`
|
||||
)}`
|
||||
)
|
||||
);
|
||||
|
||||
if (args.length > 1) {
|
||||
const example = chalk.cyan(`$ now projects add "${args.join(' ')}"`);
|
||||
const example = chalk.cyan(
|
||||
`${getCommandName(`projects add "${args.join(' ')}"`)}`
|
||||
);
|
||||
console.log(
|
||||
`> If your project name has spaces, make sure to wrap it in quotes. Example: \n ${example} `
|
||||
);
|
||||
|
||||
@@ -7,7 +7,6 @@ import Now from '../util';
|
||||
import getAliases from '../util/alias/get-aliases';
|
||||
import createOutput from '../util/output';
|
||||
import logo from '../util/output/logo';
|
||||
import cmd from '../util/output/cmd.ts';
|
||||
import elapsed from '../util/output/elapsed.ts';
|
||||
import { normalizeURL } from '../util/url';
|
||||
import Client from '../util/client.ts';
|
||||
@@ -18,20 +17,23 @@ import removeProject from '../util/projects/remove-project';
|
||||
import getProjectByIdOrName from '../util/projects/get-project-by-id-or-name';
|
||||
import getDeploymentByIdOrHost from '../util/deploy/get-deployment-by-id-or-host';
|
||||
import getDeploymentsByProjectId from '../util/deploy/get-deployments-by-project-id';
|
||||
import { getPkgName, getCommandName } from '../util/pkg-name.ts';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now remove`)} [...deploymentId|deploymentName]
|
||||
${chalk.bold(
|
||||
`${logo} ${getPkgName()} remove`
|
||||
)} [...deploymentId|deploymentName]
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
@@ -46,17 +48,17 @@ const help = () => {
|
||||
'`deploymentId`'
|
||||
)}
|
||||
|
||||
${chalk.cyan('$ now rm deploymentId')}
|
||||
${chalk.cyan(`$ ${getPkgName()} rm deploymentId`)}
|
||||
|
||||
${chalk.gray('–')} Remove all deployments with name ${chalk.dim('`my-app`')}
|
||||
|
||||
${chalk.cyan('$ now rm my-app')}
|
||||
${chalk.cyan(`$ ${getPkgName()} rm my-app`)}
|
||||
|
||||
${chalk.gray('–')} Remove two deployments with IDs ${chalk.dim(
|
||||
'`eyWt6zuSdeus`'
|
||||
)} and ${chalk.dim('`uWHoA9RQ1d1o`')}
|
||||
|
||||
${chalk.cyan('$ now rm eyWt6zuSdeus uWHoA9RQ1d1o')}
|
||||
${chalk.cyan(`$ ${getPkgName()} rm eyWt6zuSdeus uWHoA9RQ1d1o`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -91,7 +93,7 @@ export default async function main(ctx) {
|
||||
}
|
||||
|
||||
if (ids.length < 1) {
|
||||
error(`${cmd('now rm')} expects at least one argument`);
|
||||
error(`${getCommandName('rm')} expects at least one argument`);
|
||||
help();
|
||||
return 1;
|
||||
}
|
||||
@@ -212,9 +214,9 @@ export default async function main(ctx) {
|
||||
log(
|
||||
`Could not find ${argv.safe ? 'unaliased' : 'any'} deployments ` +
|
||||
`or projects matching ` +
|
||||
`${ids.map(id => chalk.bold(`"${id}"`)).join(', ')}. Run ${cmd(
|
||||
'now ls'
|
||||
)} to list.`
|
||||
`${ids
|
||||
.map(id => chalk.bold(`"${id}"`))
|
||||
.join(', ')}. Run ${getCommandName('ls')} to list.`
|
||||
);
|
||||
client.close();
|
||||
return 1;
|
||||
|
||||
@@ -35,20 +35,21 @@ import {
|
||||
} from '../util/errors-ts';
|
||||
import { InvalidAllForScale, InvalidRegionOrDCForScale } from '../util/errors';
|
||||
import handleCertError from '../util/certs/handle-cert-error';
|
||||
import { getPkgName } from '../util/pkg-name.ts';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now scale`)} <url> <dc> [min] [max]
|
||||
${chalk.bold(`${logo} ${getPkgName()} scale`)} <url> <dc> [min] [max]
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
)} Login token
|
||||
@@ -63,25 +64,25 @@ const help = () => {
|
||||
'–'
|
||||
)} Enable your deployment in all datacenters (min: 0, max: auto)
|
||||
|
||||
${chalk.cyan('$ now scale my-deployment-123.now.sh all')}
|
||||
${chalk.cyan(`$ ${getPkgName()} scale my-deployment-123.now.sh all`)}
|
||||
|
||||
${chalk.gray(
|
||||
'-'
|
||||
)} Enable your deployment in the SFO datacenter (min: 0, max: auto)
|
||||
|
||||
${chalk.cyan('$ now scale my-deployment-123.now.sh sfo')}
|
||||
${chalk.cyan(`$ ${getPkgName()} scale my-deployment-123.now.sh sfo`)}
|
||||
|
||||
${chalk.gray(
|
||||
'–'
|
||||
)} Scale a deployment in all datacenters to 3 instances at all times (no sleep)
|
||||
|
||||
${chalk.cyan('$ now scale my-deployment-123.now.sh all 3')}
|
||||
${chalk.cyan(`$ ${getPkgName()} scale my-deployment-123.now.sh all 3`)}
|
||||
|
||||
${chalk.gray(
|
||||
'–'
|
||||
)} Enable your deployment in all datacenters, with auto-scaling
|
||||
|
||||
${chalk.cyan('$ now scale my-deployment-123.now.sh all auto')}
|
||||
${chalk.cyan(`$ ${getPkgName()} scale my-deployment-123.now.sh all auto`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -133,9 +134,9 @@ export default async function main(ctx) {
|
||||
// Fail if the user is providing an old command
|
||||
if (argv._[1] === 'ls') {
|
||||
output.error(
|
||||
`${cmd('now scale ls')} has been deprecated. Use ${cmd(
|
||||
`${cmd(`${getPkgName()} scale ls`)} has been deprecated. Use ${cmd(
|
||||
'now ls'
|
||||
)} and ${cmd('now inspect <url>')}`
|
||||
)} and ${cmd(`${getPkgName()} inspect <url>`)}`
|
||||
);
|
||||
now.close();
|
||||
return 1;
|
||||
@@ -145,7 +146,7 @@ export default async function main(ctx) {
|
||||
if (argv._.length < 3 || argv._.length > 5) {
|
||||
output.error(
|
||||
`${cmd(
|
||||
'now scale <url> <dc> [min] [max]'
|
||||
`${getPkgName()} scale <url> <dc> [min] [max]`
|
||||
)} expects at least two arguments`
|
||||
);
|
||||
help();
|
||||
|
||||
@@ -12,11 +12,12 @@ import getScope from '../util/get-scope.ts';
|
||||
import createOutput from '../util/output';
|
||||
import confirm from '../util/input/confirm';
|
||||
import getCommandFlags from '../util/get-command-flags';
|
||||
import cmd from '../util/output/cmd.ts';
|
||||
import getPrefixedFlags from '../util/get-prefixed-flags';
|
||||
import { getPkgName, getCommandName } from '../util/pkg-name.ts';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now secrets`)} [options] <command>
|
||||
${chalk.bold(`${logo} ${getPkgName()} secrets`)} [options] <command>
|
||||
|
||||
${chalk.dim('Commands:')}
|
||||
|
||||
@@ -30,10 +31,10 @@ const help = () => {
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
@@ -45,7 +46,7 @@ const help = () => {
|
||||
|
||||
${chalk.gray('–')} Add a new secret
|
||||
|
||||
${chalk.cyan('$ now secrets add my-secret "my value"')}
|
||||
${chalk.cyan(`$ ${getPkgName()} secrets add my-secret "my value"`)}
|
||||
|
||||
${chalk.gray(
|
||||
'–'
|
||||
@@ -61,13 +62,13 @@ const help = () => {
|
||||
'`@`'
|
||||
)} symbol)
|
||||
|
||||
${chalk.cyan(`$ now -e MY_SECRET=${chalk.bold('@my-secret')}`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} -e MY_SECRET=${chalk.bold('@my-secret')}`)}
|
||||
|
||||
${chalk.gray('–')} Paginate results, where ${chalk.dim(
|
||||
'`1584722256178`'
|
||||
)} is the time in milliseconds since the UNIX epoch.
|
||||
|
||||
${chalk.cyan(`$ now secrets ls --next 1584722256178`)}
|
||||
|
||||
${chalk.cyan(`$ ${getPkgName()} secrets ls --next 1584722256178`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -146,7 +147,9 @@ async function run({ output, token, contextName, currentTeam, ctx }) {
|
||||
if (args.length > 1) {
|
||||
console.error(
|
||||
error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan('`now secret ls`')}`
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
`${getCommandName('secret ls')}`
|
||||
)}`
|
||||
)
|
||||
);
|
||||
return exit(1);
|
||||
@@ -193,8 +196,8 @@ async function run({ output, token, contextName, currentTeam, ctx }) {
|
||||
'-d',
|
||||
'-y',
|
||||
]);
|
||||
const nextCmd = `now secrets ${subcommand}${flags} --next ${pagination.next}`;
|
||||
output.log(`To display the next page run ${cmd(nextCmd)}`);
|
||||
const nextCmd = `secrets ${subcommand}${flags} --next ${pagination.next}`;
|
||||
output.log(`To display the next page run ${getCommandName(nextCmd)}`);
|
||||
}
|
||||
return secrets.close();
|
||||
}
|
||||
@@ -204,7 +207,7 @@ async function run({ output, token, contextName, currentTeam, ctx }) {
|
||||
console.error(
|
||||
error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now secret rm <name>`'
|
||||
`${getCommandName('secret rm <name>')}`
|
||||
)}`
|
||||
)
|
||||
);
|
||||
@@ -246,7 +249,7 @@ async function run({ output, token, contextName, currentTeam, ctx }) {
|
||||
console.error(
|
||||
error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now secret rename <old-name> <new-name>`'
|
||||
`${getCommandName('secret rename <old-name> <new-name>')}`
|
||||
)}`
|
||||
)
|
||||
);
|
||||
@@ -269,13 +272,15 @@ async function run({ output, token, contextName, currentTeam, ctx }) {
|
||||
console.error(
|
||||
error(
|
||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||
'`now secret add <name> <value>`'
|
||||
`${getCommandName('secret add <name> <value>')}`
|
||||
)}`
|
||||
)
|
||||
);
|
||||
|
||||
if (args.length > 2) {
|
||||
const example = chalk.cyan(`$ now secret add -- "${args[0]}"`);
|
||||
const example = chalk.cyan(
|
||||
`$ ${getCommandName('secret add -- "${args[0]}"')}`
|
||||
);
|
||||
console.log(
|
||||
`If your secret has spaces or starts with '-', make sure to terminate command options with double dash and wrap it in quotes. Example: \n ${example} `
|
||||
);
|
||||
@@ -299,7 +304,9 @@ async function run({ output, token, contextName, currentTeam, ctx }) {
|
||||
}
|
||||
|
||||
if (typeof value === 'boolean') {
|
||||
const example = chalk.cyan(`$ now secret add -- "${name}"`);
|
||||
const example = chalk.cyan(
|
||||
`$ ${getCommandName('secret add -- "${name}"')}`
|
||||
);
|
||||
console.log(
|
||||
`If your secret starts with '-', make sure to terminate command options with double dash and wrap it in quotes. Example: \n ${example} `
|
||||
);
|
||||
@@ -349,28 +356,3 @@ async function readConfirmation(output, secret, contextName) {
|
||||
|
||||
return confirm(`${chalk.bold.red('Are you sure?')}`, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function adds a prefix `-` or `--` to the flags
|
||||
* passed from the command line, because the package `mri`
|
||||
* used to extract the args removes them for some reason.
|
||||
*/
|
||||
function getPrefixedFlags(args) {
|
||||
const prefixedArgs = {};
|
||||
|
||||
for (const arg in args) {
|
||||
if (arg === '_') {
|
||||
prefixedArgs[arg] = argv[arg];
|
||||
} else {
|
||||
let prefix = '-';
|
||||
// Full form flags need two dashes, whereas one letter
|
||||
// flags need only one.
|
||||
if (arg.length > 1) {
|
||||
prefix = '--';
|
||||
}
|
||||
prefixedArgs[`${prefix}${arg}`] = argv[arg];
|
||||
}
|
||||
}
|
||||
|
||||
return prefixedArgs;
|
||||
}
|
||||
|
||||
@@ -9,10 +9,11 @@ import list from './teams/list';
|
||||
import add from './teams/add';
|
||||
import change from './teams/switch';
|
||||
import invite from './teams/invite';
|
||||
import { getPkgName } from '../util/pkg-name.ts';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now teams`)} [options] <command>
|
||||
${chalk.bold(`${logo} ${getPkgName()} teams`)} [options] <command>
|
||||
|
||||
${chalk.dim('Commands:')}
|
||||
|
||||
@@ -26,17 +27,18 @@ const help = () => {
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-N, --next Show next page of results
|
||||
|
||||
${chalk.dim('Examples:')}
|
||||
|
||||
${chalk.gray('–')} Switch to a team
|
||||
|
||||
${chalk.cyan(`$ now switch <slug>`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} switch <slug>`)}
|
||||
|
||||
${chalk.gray(
|
||||
'–'
|
||||
@@ -49,7 +51,13 @@ const help = () => {
|
||||
|
||||
${chalk.gray('–')} Invite new members (interactively)
|
||||
|
||||
${chalk.cyan(`$ now teams invite`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} teams invite`)}
|
||||
|
||||
${chalk.gray('–')} Paginate results, where ${chalk.dim(
|
||||
'`1584722256178`'
|
||||
)} is the time in milliseconds since the UNIX epoch.
|
||||
|
||||
${chalk.cyan(`$ ${getPkgName()} teams ls --next 1584722256178`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -64,8 +72,9 @@ const main = async ctx => {
|
||||
alias: {
|
||||
help: 'h',
|
||||
debug: 'd',
|
||||
switch: 'change'
|
||||
}
|
||||
switch: 'change',
|
||||
next: 'N',
|
||||
},
|
||||
});
|
||||
|
||||
debug = argv.debug;
|
||||
@@ -86,7 +95,10 @@ const main = async ctx => {
|
||||
await exit(0);
|
||||
}
|
||||
|
||||
const { authConfig: { token }, config } = ctx;
|
||||
const {
|
||||
authConfig: { token },
|
||||
config,
|
||||
} = ctx;
|
||||
|
||||
return run({ token, config });
|
||||
};
|
||||
@@ -113,7 +125,8 @@ async function run({ token, config }) {
|
||||
teams,
|
||||
config,
|
||||
apiUrl,
|
||||
token
|
||||
token,
|
||||
argv,
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -124,7 +137,7 @@ async function run({ token, config }) {
|
||||
config,
|
||||
apiUrl,
|
||||
token,
|
||||
debug
|
||||
debug,
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -140,7 +153,7 @@ async function run({ token, config }) {
|
||||
args,
|
||||
config,
|
||||
apiUrl,
|
||||
token
|
||||
token,
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ import rightPad from '../../util/output/right-pad';
|
||||
import eraseLines from '../../util/output/erase-lines';
|
||||
import chars from '../../util/output/chars';
|
||||
import success from '../../util/output/success';
|
||||
import cmd from '../../util/output/cmd.ts';
|
||||
import note from '../../util/output/note';
|
||||
import textInput from '../../util/input/text';
|
||||
import invite from './invite';
|
||||
import { writeToConfigFile } from '../../util/config/files';
|
||||
import { getPkgName, getCommandName } from '../../util/pkg-name.ts';
|
||||
|
||||
const validateSlugKeypress = (data, value) =>
|
||||
// TODO: the `value` here should contain the current value + the keypress
|
||||
@@ -26,8 +26,8 @@ const validateNameKeypress = (data, value) =>
|
||||
const gracefulExit = () => {
|
||||
console.log(); // Blank line
|
||||
note(
|
||||
`Your team is now active for all ${cmd('now')} commands!\n Run ${cmd(
|
||||
'now switch'
|
||||
`Your team is now active for all ${getPkgName()} commands!\n Run ${getCommandName(
|
||||
`switch`
|
||||
)} to change it in the future.`
|
||||
);
|
||||
return 0;
|
||||
@@ -151,8 +151,8 @@ export default async function({ apiUrl, token, teams, config }) {
|
||||
apiUrl,
|
||||
config,
|
||||
introMsg: 'Invite your teammates! When done, press enter on an empty field',
|
||||
noopMsg: `You can invite teammates later by running ${cmd(
|
||||
'now teams invite'
|
||||
noopMsg: `You can invite teammates later by running ${getCommandName(
|
||||
`teams invite`
|
||||
)}`,
|
||||
});
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import eraseLines from '../../util/output/erase-lines';
|
||||
import success from '../../util/output/success';
|
||||
import getUser from '../../util/get-user.ts';
|
||||
import Client from '../../util/client.ts';
|
||||
import { getCommandName } from '../../util/pkg-name.ts';
|
||||
|
||||
const validateEmail = data => regexEmail.test(data.trim()) || data.length === 0;
|
||||
|
||||
@@ -96,9 +97,9 @@ export default async function({
|
||||
// We specifically need a team scope here
|
||||
let err = `You can't run this command under ${param(
|
||||
user.username || user.email
|
||||
)}.\nPlease select a team scope using ${cmd('now switch')} or use ${cmd(
|
||||
'--scope'
|
||||
)}`;
|
||||
)}.\nPlease select a team scope using ${getCommandName(
|
||||
`switch`
|
||||
)} or use ${cmd('--scope')}`;
|
||||
return fatalError(err);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,28 @@ import info from '../../util/output/info';
|
||||
import error from '../../util/output/error';
|
||||
import chars from '../../util/output/chars';
|
||||
import table from '../../util/output/table';
|
||||
import createOutput from '../../util/output';
|
||||
import getUser from '../../util/get-user.ts';
|
||||
import Client from '../../util/client.ts';
|
||||
import getPrefixedFlags from '../../util/get-prefixed-flags';
|
||||
import { getPkgName } from '../../util/pkg-name.ts';
|
||||
import getCommandFlags from '../../util/get-command-flags';
|
||||
import cmd from '../../util/output/cmd.ts';
|
||||
|
||||
export default async function({ teams, config, apiUrl, token, argv }) {
|
||||
const { next } = argv;
|
||||
const output = createOutput({ debug: argv['--debug'] });
|
||||
|
||||
if (typeof next !== 'undefined' && !Number.isInteger(next)) {
|
||||
output.error('Please provide a number for flag --next');
|
||||
return 1;
|
||||
}
|
||||
|
||||
export default async function({ teams, config, apiUrl, token }) {
|
||||
const stopSpinner = wait('Fetching teams');
|
||||
const list = (await teams.ls()).teams;
|
||||
const { teams: list, pagination } = await teams.ls({
|
||||
next,
|
||||
apiVersion: 2,
|
||||
});
|
||||
let { currentTeam } = config;
|
||||
const accountIsCurrent = !currentTeam;
|
||||
|
||||
@@ -78,4 +94,14 @@ export default async function({ teams, config, apiUrl, token }) {
|
||||
teamList.map(team => [team.current, team.value, team.name]),
|
||||
[1, 5]
|
||||
);
|
||||
|
||||
if (pagination && pagination.count === 20) {
|
||||
const prefixedArgs = getPrefixedFlags(argv);
|
||||
const flags = getCommandFlags(prefixedArgs, ['_', '--next', '-N', '-d']);
|
||||
const nextCmd = `${getPkgName()} teams ls${flags} --next ${
|
||||
pagination.next
|
||||
}`;
|
||||
console.log(); // empty line
|
||||
output.log(`To display the next page run ${cmd(nextCmd)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,11 @@ import getArgs from '../util/get-args';
|
||||
import { NowContext } from '../types';
|
||||
import createOutput from '../util/output';
|
||||
import getUpdateCommand from '../util/get-update-command';
|
||||
import { getPkgName, getTitleName } from '../util/pkg-name';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now update`)} [options]
|
||||
${chalk.bold(`${logo} ${getPkgName()} update`)} [options]
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
@@ -26,9 +27,9 @@ const help = () => {
|
||||
|
||||
${chalk.dim('Examples:')}
|
||||
|
||||
${chalk.gray('–')} Update Now CLI to the latest "canary" version
|
||||
${chalk.gray('–')} Update ${getTitleName()} CLI to the latest "canary" version
|
||||
|
||||
${chalk.cyan(`$ now update --channel=canary`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} update --channel=canary`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -42,7 +43,7 @@ export default async function main(ctx: NowContext): Promise<number> {
|
||||
'--release': String,
|
||||
'-V': '--release',
|
||||
'--yes': Boolean,
|
||||
'-y': '--yes'
|
||||
'-y': '--yes',
|
||||
});
|
||||
} catch (err) {
|
||||
handleError(err);
|
||||
@@ -56,6 +57,10 @@ export default async function main(ctx: NowContext): Promise<number> {
|
||||
|
||||
const debugEnabled = argv['--debug'];
|
||||
const output = createOutput({ debug: debugEnabled });
|
||||
output.log(`Please run ${cmd(await getUpdateCommand())} to update Now CLI`);
|
||||
output.log(
|
||||
`Please run ${cmd(
|
||||
await getUpdateCommand()
|
||||
)} to update ${getTitleName()} CLI`
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -5,20 +5,21 @@ import { handleError } from '../util/error';
|
||||
import Client from '../util/client.ts';
|
||||
import getScope from '../util/get-scope.ts';
|
||||
import createOutput from '../util/output';
|
||||
import { getPkgName } from '../util/pkg-name.ts';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
${chalk.bold(`${logo} now whoami`)}
|
||||
${chalk.bold(`${logo} ${getPkgName()} whoami`)}
|
||||
|
||||
${chalk.dim('Options:')}
|
||||
|
||||
-h, --help Output usage information
|
||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
||||
'FILE'
|
||||
)} Path to the local ${'`now.json`'} file
|
||||
)} Path to the local ${'`vercel.json`'} file
|
||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
||||
'DIR'
|
||||
)} Path to the global ${'`.now`'} directory
|
||||
)} Path to the global ${'`.vercel`'} directory
|
||||
-d, --debug Debug mode [off]
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
@@ -28,7 +29,7 @@ const help = () => {
|
||||
|
||||
${chalk.gray('–')} Shows the username of the currently logged in user
|
||||
|
||||
${chalk.cyan('$ now whoami')}
|
||||
${chalk.cyan(`$ ${getPkgName()} whoami`)}
|
||||
`);
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import checkForUpdate from 'update-check';
|
||||
import ms from 'ms';
|
||||
import { URL } from 'url';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import getNowDir from './util/config/global-path';
|
||||
import getGlobalPathConfig from './util/config/global-path';
|
||||
import {
|
||||
getDefaultConfig,
|
||||
getDefaultAuthConfig,
|
||||
@@ -48,11 +48,11 @@ import { NowError } from './util/now-error';
|
||||
import { SENTRY_DSN } from './util/constants.ts';
|
||||
import getUpdateCommand from './util/get-update-command';
|
||||
import { metrics, shouldCollectMetrics } from './util/metrics.ts';
|
||||
import { getLinkedOrg } from './util/projects/link';
|
||||
import { getCommandName, getTitleName } from './util/pkg-name.ts';
|
||||
|
||||
const NOW_DIR = getNowDir();
|
||||
const NOW_CONFIG_PATH = configFiles.getConfigFilePath();
|
||||
const NOW_AUTH_CONFIG_PATH = configFiles.getAuthConfigFilePath();
|
||||
const VERCEL_DIR = getGlobalPathConfig();
|
||||
const VERCEL_CONFIG_PATH = configFiles.getConfigFilePath();
|
||||
const VERCEL_AUTH_CONFIG_PATH = configFiles.getAuthConfigFilePath();
|
||||
|
||||
const GLOBAL_COMMANDS = new Set(['help']);
|
||||
|
||||
@@ -63,7 +63,7 @@ sourceMap.install();
|
||||
// Configure the error reporting system
|
||||
Sentry.init({
|
||||
dsn: SENTRY_DSN,
|
||||
release: `now-cli@${pkg.version}`,
|
||||
release: `vercel-cli@${pkg.version}`,
|
||||
environment: pkg.version.includes('canary') ? 'canary' : 'stable',
|
||||
});
|
||||
|
||||
@@ -122,8 +122,8 @@ const main = async argv_ => {
|
||||
}
|
||||
|
||||
// the second argument to the command can be a path
|
||||
// (as in: `now path/`) or a subcommand / provider
|
||||
// (as in: `now ls`)
|
||||
// (as in: `vercel path/`) or a subcommand / provider
|
||||
// (as in: `vercel ls`)
|
||||
const targetOrSubcommand = argv._[2];
|
||||
|
||||
let update = null;
|
||||
@@ -149,9 +149,9 @@ const main = async argv_ => {
|
||||
console.log(
|
||||
info(
|
||||
`${chalk.bgRed('UPDATE AVAILABLE')} ` +
|
||||
`Run ${cmd(await getUpdateCommand())} to install Now CLI ${
|
||||
update.latest
|
||||
}`
|
||||
`Run ${cmd(
|
||||
await getUpdateCommand()
|
||||
)} to install ${getTitleName()} CLI ${update.latest}`
|
||||
)
|
||||
);
|
||||
|
||||
@@ -164,7 +164,7 @@ const main = async argv_ => {
|
||||
|
||||
output.print(
|
||||
`${chalk.grey(
|
||||
`Now CLI ${pkg.version}${
|
||||
`${getTitleName()} CLI ${pkg.version}${
|
||||
targetOrSubcommand === 'dev' ? ' dev (beta)' : ''
|
||||
}${
|
||||
pkg.version.includes('canary') || targetOrSubcommand === 'dev'
|
||||
@@ -177,7 +177,7 @@ const main = async argv_ => {
|
||||
// we want to handle version or help directly only
|
||||
if (!targetOrSubcommand) {
|
||||
if (argv['--version']) {
|
||||
console.log(require('../package').version);
|
||||
console.log(pkg.version);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -185,12 +185,12 @@ const main = async argv_ => {
|
||||
let nowDirExists;
|
||||
|
||||
try {
|
||||
nowDirExists = existsSync(NOW_DIR);
|
||||
nowDirExists = existsSync(VERCEL_DIR);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
error(
|
||||
`${'An unexpected error occurred while trying to find the ' +
|
||||
'now global directory: '}${err.message}`
|
||||
'global directory: '}${err.message}`
|
||||
)
|
||||
);
|
||||
|
||||
@@ -199,12 +199,12 @@ const main = async argv_ => {
|
||||
|
||||
if (!nowDirExists) {
|
||||
try {
|
||||
await mkdirp(NOW_DIR);
|
||||
await mkdirp(VERCEL_DIR);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
error(
|
||||
`${'An unexpected error occurred while trying to create the ' +
|
||||
`now global directory "${hp(NOW_DIR)}" `}${err.message}`
|
||||
`global directory "${hp(VERCEL_DIR)}" `}${err.message}`
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -214,12 +214,12 @@ const main = async argv_ => {
|
||||
let configExists;
|
||||
|
||||
try {
|
||||
configExists = existsSync(NOW_CONFIG_PATH);
|
||||
configExists = existsSync(VERCEL_CONFIG_PATH);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
error(
|
||||
`${'An unexpected error occurred while trying to find the ' +
|
||||
`now config file "${hp(NOW_CONFIG_PATH)}" `}${err.message}`
|
||||
`config file "${hp(VERCEL_CONFIG_PATH)}" `}${err.message}`
|
||||
)
|
||||
);
|
||||
|
||||
@@ -235,14 +235,14 @@ const main = async argv_ => {
|
||||
console.error(
|
||||
error(
|
||||
`${'An unexpected error occurred while trying to read the ' +
|
||||
`now config in "${hp(NOW_CONFIG_PATH)}" `}${err.message}`
|
||||
`config in "${hp(VERCEL_CONFIG_PATH)}" `}${err.message}`
|
||||
)
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// This is from when Now CLI supported
|
||||
// This is from when Vercel CLI supported
|
||||
// multiple providers. In that case, we really
|
||||
// need to migrate.
|
||||
if (
|
||||
@@ -267,7 +267,7 @@ const main = async argv_ => {
|
||||
console.error(
|
||||
error(
|
||||
`${'An unexpected error occurred while trying to write the ' +
|
||||
`default now config to "${hp(NOW_CONFIG_PATH)}" `}${err.message}`
|
||||
`default config to "${hp(VERCEL_CONFIG_PATH)}" `}${err.message}`
|
||||
)
|
||||
);
|
||||
|
||||
@@ -278,12 +278,12 @@ const main = async argv_ => {
|
||||
let authConfigExists;
|
||||
|
||||
try {
|
||||
authConfigExists = existsSync(NOW_AUTH_CONFIG_PATH);
|
||||
authConfigExists = existsSync(VERCEL_AUTH_CONFIG_PATH);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
error(
|
||||
`${'An unexpected error occurred while trying to find the ' +
|
||||
`now auth file "${hp(NOW_AUTH_CONFIG_PATH)}" `}${err.message}`
|
||||
`auth file "${hp(VERCEL_AUTH_CONFIG_PATH)}" `}${err.message}`
|
||||
)
|
||||
);
|
||||
|
||||
@@ -301,14 +301,14 @@ const main = async argv_ => {
|
||||
console.error(
|
||||
error(
|
||||
`${'An unexpected error occurred while trying to read the ' +
|
||||
`now auth config in "${hp(NOW_AUTH_CONFIG_PATH)}" `}${err.message}`
|
||||
`auth config in "${hp(VERCEL_AUTH_CONFIG_PATH)}" `}${err.message}`
|
||||
)
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// This is from when Now CLI supported
|
||||
// This is from when Vercel CLI supported
|
||||
// multiple providers. In that case, we really
|
||||
// need to migrate.
|
||||
if (authConfig.credentials) {
|
||||
@@ -321,8 +321,10 @@ const main = async argv_ => {
|
||||
) {
|
||||
console.error(
|
||||
error(
|
||||
`The content of "${hp(NOW_AUTH_CONFIG_PATH)}" is invalid. ` +
|
||||
'No `token` property found inside. Run `now login` to authorize.'
|
||||
`The content of "${hp(VERCEL_AUTH_CONFIG_PATH)}" is invalid. ` +
|
||||
`No \`token\` property found inside. Run ${getCommandName(
|
||||
'login'
|
||||
)} to authorize.`
|
||||
)
|
||||
);
|
||||
return 1;
|
||||
@@ -339,7 +341,7 @@ const main = async argv_ => {
|
||||
console.error(
|
||||
error(
|
||||
`${'An unexpected error occurred while trying to write the ' +
|
||||
`default now config to "${hp(NOW_AUTH_CONFIG_PATH)}" `}${
|
||||
`default config to "${hp(VERCEL_AUTH_CONFIG_PATH)}" `}${
|
||||
err.message
|
||||
}`
|
||||
)
|
||||
@@ -350,7 +352,7 @@ const main = async argv_ => {
|
||||
|
||||
// Let the user know we migrated the config
|
||||
if (migrated) {
|
||||
const directory = param(hp(NOW_DIR));
|
||||
const directory = param(hp(VERCEL_DIR));
|
||||
debug(
|
||||
`The credentials and configuration within the ${directory} directory were upgraded`
|
||||
);
|
||||
@@ -464,7 +466,7 @@ const main = async argv_ => {
|
||||
error({
|
||||
message:
|
||||
'No existing credentials found. Please run ' +
|
||||
`${param('now login')} or pass ${param('--token')}`,
|
||||
`${getCommandName('login')} or pass ${param('--token')}`,
|
||||
slug: 'no-credentials-found',
|
||||
})
|
||||
);
|
||||
@@ -541,22 +543,6 @@ const main = async argv_ => {
|
||||
|
||||
const targetCommand = commands.get(subcommand);
|
||||
|
||||
if (
|
||||
!['login', 'logout'].includes(targetCommand) &&
|
||||
(process.env.NOW_ORG_ID || !scope)
|
||||
) {
|
||||
const client = new Client({ apiUrl, token });
|
||||
const link = await getLinkedOrg(client, output);
|
||||
|
||||
if (link.status === 'error') {
|
||||
return link.exitCode;
|
||||
}
|
||||
|
||||
if (link.status === 'linked') {
|
||||
scope = link.org.slug;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
typeof scope === 'string' &&
|
||||
targetCommand !== 'login' &&
|
||||
|
||||
@@ -187,6 +187,9 @@ export type DNSRecord = {
|
||||
value: string;
|
||||
created: number;
|
||||
updated: number;
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
domain: string;
|
||||
};
|
||||
|
||||
type SRVRecordData = {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user