@nx-extend/vercel 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
1
 
2
+ # [1.3.0](https://github.com/TriPSs/nx-extend/compare/vercel@1.2.0...vercel@1.3.0) (2022-09-13)
3
+
4
+
5
+ ### Features
6
+
7
+ * **vercel:** Added support for `envVars` option ([55e8e14](https://github.com/TriPSs/nx-extend/commit/55e8e14d2f7304a6833bc49881cfd3554a051192))
8
+
9
+
10
+
2
11
  # [1.2.0](https://github.com/TriPSs/nx-extend/compare/vercel@1.1.1...vercel@1.2.0) (2022-09-06)
3
12
 
4
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx-extend/vercel",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "keywords": [
5
5
  "nx",
6
6
  "vercel"
@@ -19,7 +19,7 @@
19
19
  "generators": "./generators.json",
20
20
  "typings": "./src/index.d.ts",
21
21
  "dependencies": {
22
- "@nx-extend/core": "1.2.2",
22
+ "@nx-extend/core": "1.3.0",
23
23
  "shelljs": "^0.8.5"
24
24
  },
25
25
  "peerDependencies": {}
@@ -3,6 +3,7 @@ export interface ExecutorSchema {
3
3
  projectId: string;
4
4
  orgId: string;
5
5
  debug?: boolean;
6
+ envVars?: Record<string, string>;
6
7
  }
7
8
  export declare function buildExecutor(options: ExecutorSchema, context: ExecutorContext): Promise<{
8
9
  success: boolean;
@@ -3,9 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildExecutor = void 0;
4
4
  const devkit_1 = require("@nrwl/devkit");
5
5
  const core_1 = require("@nx-extend/core");
6
+ const path_1 = require("path");
7
+ const add_env_variables_to_file_1 = require("../../utils/add-env-variables-to-file");
6
8
  function buildExecutor(options, context) {
7
9
  var _a, _b, _c, _d, _e, _f, _g, _h;
8
10
  const { targets } = context.workspace.projects[context.projectName];
11
+ if (!options.orgId) {
12
+ throw new Error(`"orgId" option is required!`);
13
+ }
14
+ if (!options.projectId) {
15
+ throw new Error(`"projectId" option is required!`);
16
+ }
9
17
  if (!targets['build-next']) {
10
18
  throw new Error(`"${context.projectName}" is missing the original "build-next" target!`);
11
19
  }
@@ -22,10 +30,23 @@ function buildExecutor(options, context) {
22
30
  (0, core_1.execCommand)((0, core_1.buildCommand)([
23
31
  'npx vercel pull --yes',
24
32
  context.configurationName === 'production' && '--environment=production',
33
+ context.configurationName !== 'production' && '--environment=preview',
25
34
  options.debug && '--debug'
26
35
  ]));
36
+ const vercelDirectory = '.vercel';
37
+ const vercelProjectJson = `./${vercelDirectory}/project.json`;
38
+ const outputDirectory = (_d = (_c = targets['build-next']) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.outputPath;
39
+ const vercelEnironment = context.configurationName === 'production'
40
+ ? 'production'
41
+ : 'preview';
42
+ const vercelEnvFile = `.env.${vercelEnironment}.local`;
43
+ const vercelEnvFileLocation = (0, path_1.join)(context.root, vercelDirectory);
44
+ const envVars = (0, core_1.getEnvVars)(options.envVars, true);
45
+ if (envVars.length > 0) {
46
+ (0, add_env_variables_to_file_1.addEnvVariablesToFile)((0, path_1.join)(vercelEnvFileLocation, vercelEnvFile), envVars);
47
+ }
27
48
  // Update the project json with the correct settings
28
- (0, devkit_1.writeJsonFile)('./.vercel/project.json', {
49
+ (0, devkit_1.writeJsonFile)(vercelProjectJson, {
29
50
  projectId: options.projectId,
30
51
  orgId: options.orgId,
31
52
  settings: {
@@ -33,8 +54,8 @@ function buildExecutor(options, context) {
33
54
  framework: 'nextjs',
34
55
  devCommand: null,
35
56
  installCommand: 'echo \'\'',
36
- buildCommand: `nx build-next ${context.projectName} --prod`,
37
- outputDirectory: `${(_d = (_c = targets['build-next']) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.outputPath}/.next`,
57
+ buildCommand: `nx build-next ${context.projectName}${context.configurationName === 'production' ? ' --prod' : ''}`,
58
+ outputDirectory: `${(_f = (_e = targets['build-next']) === null || _e === void 0 ? void 0 : _e.options) === null || _f === void 0 ? void 0 : _f.outputPath}/.next`,
38
59
  rootDirectory: null,
39
60
  directoryListing: false,
40
61
  nodeVersion: '16.x'
@@ -42,11 +63,14 @@ function buildExecutor(options, context) {
42
63
  });
43
64
  const { success } = (0, core_1.execCommand)((0, core_1.buildCommand)([
44
65
  'npx vercel build',
45
- `--output ${(_f = (_e = targets['build-next']) === null || _e === void 0 ? void 0 : _e.options) === null || _f === void 0 ? void 0 : _f.outputPath}/.vercel/output`,
66
+ `--output ${(_h = (_g = targets['build-next']) === null || _g === void 0 ? void 0 : _g.options) === null || _h === void 0 ? void 0 : _h.outputPath}/.vercel/output`,
46
67
  options.debug && '--debug'
47
68
  ]));
48
69
  if (success) {
49
- (0, devkit_1.writeJsonFile)(`${(_h = (_g = targets['build-next']) === null || _g === void 0 ? void 0 : _g.options) === null || _h === void 0 ? void 0 : _h.outputPath}/.vercel/project.json`, (0, devkit_1.readJsonFile)('./.vercel/project.json'));
70
+ // Write the project.json to the .vercel directory
71
+ (0, devkit_1.writeJsonFile)((0, path_1.join)(outputDirectory, vercelDirectory, 'project.json'), (0, devkit_1.readJsonFile)(vercelProjectJson));
72
+ // Also copy over the env files
73
+ (0, core_1.copyFile)(vercelEnvFileLocation, (0, path_1.join)(outputDirectory, vercelDirectory), vercelEnvFile);
50
74
  }
51
75
  return Promise.resolve({ success });
52
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"build.impl.js","sourceRoot":"","sources":["../../../../../../packages/vercel/src/executors/build/build.impl.ts"],"names":[],"mappings":";;;AAAA,yCAA0D;AAC1D,0CAA2D;AAU3D,SAAgB,aAAa,CAC3B,OAAuB,EACvB,OAAwB;;IAExB,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAE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AAE;YACR,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC/B,SAAS,EAAE,QAAQ;YACnB,UAAU,EAAE,IAAI;YAChB,cAAc,EAAE,WAAW;YAC3B,YAAY,EAAE,iBAAiB,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,iBAAiB,KAAK,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;YAClH,eAAe,EAAE,GAAG,MAAA,MAAA,OAAO,CAAC,YAAY,CAAC,0CAAE,OAAO,0CAAE,UAAU,QAAQ;YACtE,aAAa,EAAE,IAAI;YACnB,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,MAAM;SACpB;KACF,CAAC,CAAA;IAEF,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,kBAAW,EAAC,IAAA,mBAAY,EAAC;QAC3C,kBAAkB;QAClB,YAAY,MAAA,MAAA,OAAO,CAAC,YAAY,CAAC,0CAAE,OAAO,0CAAE,UAAU,iBAAiB;QAEvE,OAAO,CAAC,KAAK,IAAI,SAAS;KAC3B,CAAC,CAAC,CAAA;IAEH,IAAI,OAAO,EAAE;QACX,kDAAkD;QAClD,IAAA,sBAAa,EAAC,IAAA,WAAI,EAAC,eAAe,EAAE,eAAe,EAAE,cAAc,CAAC,EAAE,IAAA,qBAAY,EAAC,iBAAiB,CAAC,CAAC,CAAA;QACtG,+BAA+B;QAC/B,IAAA,eAAQ,EAAC,qBAAqB,EAAE,IAAA,WAAI,EAAC,eAAe,EAAE,eAAe,CAAC,EAAE,aAAa,CAAC,CAAA;KACvF;IAED,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;AACrC,CAAC;AAtFD,sCAsFC;AAED,kBAAe,aAAa,CAAA"}
@@ -1,12 +1,16 @@
1
1
  import { readJsonFile, writeJsonFile } from '@nrwl/devkit'
2
- import { buildCommand, execCommand } from '@nx-extend/core'
2
+ import { buildCommand, copyFile, execCommand, getEnvVars } from '@nx-extend/core'
3
+ import { join } from 'path'
3
4
 
4
5
  import type { ExecutorContext } from '@nrwl/devkit'
5
6
 
7
+ import { addEnvVariablesToFile } from '../../utils/add-env-variables-to-file'
8
+
6
9
  export interface ExecutorSchema {
7
10
  projectId: string
8
11
  orgId: string
9
12
  debug?: boolean
13
+ envVars?: Record<string, string>
10
14
  }
11
15
 
12
16
  export function buildExecutor(
@@ -15,6 +19,14 @@ export function buildExecutor(
15
19
  ): Promise<{ success: boolean }> {
16
20
  const { targets } = context.workspace.projects[context.projectName]
17
21
 
22
+ if (!options.orgId) {
23
+ throw new Error(`"orgId" option is required!`)
24
+ }
25
+
26
+ if (!options.projectId) {
27
+ throw new Error(`"projectId" option is required!`)
28
+ }
29
+
18
30
  if (!targets['build-next']) {
19
31
  throw new Error(`"${context.projectName}" is missing the original "build-next" target!`)
20
32
  }
@@ -34,12 +46,29 @@ export function buildExecutor(
34
46
  execCommand(buildCommand([
35
47
  'npx vercel pull --yes',
36
48
  context.configurationName === 'production' && '--environment=production',
49
+ context.configurationName !== 'production' && '--environment=preview',
37
50
 
38
51
  options.debug && '--debug'
39
52
  ]))
40
53
 
54
+ const vercelDirectory = '.vercel'
55
+ const vercelProjectJson = `./${vercelDirectory}/project.json`
56
+ const outputDirectory = targets['build-next']?.options?.outputPath
57
+
58
+ const vercelEnironment = context.configurationName === 'production'
59
+ ? 'production'
60
+ : 'preview'
61
+
62
+ const vercelEnvFile = `.env.${vercelEnironment}.local`
63
+ const vercelEnvFileLocation = join(context.root, vercelDirectory)
64
+
65
+ const envVars = getEnvVars(options.envVars, true)
66
+ if (envVars.length > 0) {
67
+ addEnvVariablesToFile(join(vercelEnvFileLocation, vercelEnvFile), envVars)
68
+ }
69
+
41
70
  // Update the project json with the correct settings
42
- writeJsonFile('./.vercel/project.json', {
71
+ writeJsonFile(vercelProjectJson, {
43
72
  projectId: options.projectId,
44
73
  orgId: options.orgId,
45
74
  settings: {
@@ -47,7 +76,7 @@ export function buildExecutor(
47
76
  framework: 'nextjs',
48
77
  devCommand: null,
49
78
  installCommand: 'echo \'\'',
50
- buildCommand: `nx build-next ${context.projectName} --prod`,
79
+ buildCommand: `nx build-next ${context.projectName}${context.configurationName === 'production' ? ' --prod' : ''}`,
51
80
  outputDirectory: `${targets['build-next']?.options?.outputPath}/.next`,
52
81
  rootDirectory: null,
53
82
  directoryListing: false,
@@ -63,7 +92,10 @@ export function buildExecutor(
63
92
  ]))
64
93
 
65
94
  if (success) {
66
- writeJsonFile(`${targets['build-next']?.options?.outputPath}/.vercel/project.json`, readJsonFile('./.vercel/project.json'))
95
+ // Write the project.json to the .vercel directory
96
+ writeJsonFile(join(outputDirectory, vercelDirectory, 'project.json'), readJsonFile(vercelProjectJson))
97
+ // Also copy over the env files
98
+ copyFile(vercelEnvFileLocation, join(outputDirectory, vercelDirectory), vercelEnvFile)
67
99
  }
68
100
 
69
101
  return Promise.resolve({ success })
@@ -3,15 +3,15 @@
3
3
  "type": "object",
4
4
  "cli": "nx",
5
5
  "title": "Deploy executor",
6
- "description": "Deploy to Firebase Hosting",
6
+ "description": "Deploy to Vercel",
7
7
  "properties": {
8
8
  "projectId": {
9
9
  "type": "string",
10
- "description": "Site name in Firebase Hosting"
10
+ "description": "Project ID in Vercel"
11
11
  },
12
12
  "orgId": {
13
13
  "type": "string",
14
- "description": "Site name in Firebase Hosting"
14
+ "description": "Origination ID in Vercel"
15
15
  }
16
16
  }
17
17
  }
@@ -0,0 +1 @@
1
+ export declare const addEnvVariablesToFile: (envFile: string, envVars: string[]) => void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addEnvVariablesToFile = void 0;
4
+ const fs_1 = require("fs");
5
+ const addEnvVariablesToFile = (envFile, envVars) => {
6
+ if ((0, fs_1.existsSync)(envFile)) {
7
+ (0, fs_1.appendFileSync)(envFile, envVars.join('\r\n'));
8
+ }
9
+ };
10
+ exports.addEnvVariablesToFile = addEnvVariablesToFile;
11
+ //# sourceMappingURL=add-env-variables-to-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-env-variables-to-file.js","sourceRoot":"","sources":["../../../../../packages/vercel/src/utils/add-env-variables-to-file.ts"],"names":[],"mappings":";;;AAAA,2BAA+C;AAExC,MAAM,qBAAqB,GAAG,CAAC,OAAe,EAAE,OAAiB,EAAE,EAAE;IAC1E,IAAI,IAAA,eAAU,EAAC,OAAO,CAAC,EAAE;QACvB,IAAA,mBAAc,EAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;KAC9C;AACH,CAAC,CAAA;AAJY,QAAA,qBAAqB,yBAIjC"}