@nestjs/cli 6.14.0-next.1 → 6.14.2

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.
@@ -0,0 +1,28 @@
1
+ {
2
+ "extends": ["@commitlint/config-angular"],
3
+ "rules": {
4
+ "subject-case": [
5
+ 2,
6
+ "always",
7
+ ["sentence-case", "start-case", "pascal-case", "upper-case", "lower-case"]
8
+ ],
9
+ "type-enum": [
10
+ 2,
11
+ "always",
12
+ [
13
+ "build",
14
+ "chore",
15
+ "ci",
16
+ "docs",
17
+ "feat",
18
+ "fix",
19
+ "perf",
20
+ "refactor",
21
+ "revert",
22
+ "style",
23
+ "test",
24
+ "sample"
25
+ ]
26
+ ]
27
+ }
28
+ }
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ src/**/*.test.ts
2
+ src/**/files/**
3
+ test/**
package/.eslintrc.js ADDED
@@ -0,0 +1,26 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ parserOptions: {
4
+ project: 'tsconfig.json',
5
+ sourceType: 'module',
6
+ },
7
+ plugins: ['@typescript-eslint/eslint-plugin'],
8
+ extends: [
9
+ 'plugin:@typescript-eslint/eslint-recommended',
10
+ 'plugin:@typescript-eslint/recommended',
11
+ 'prettier',
12
+ 'prettier/@typescript-eslint',
13
+ ],
14
+ root: true,
15
+ env: {
16
+ node: true,
17
+ jest: true,
18
+ },
19
+ rules: {
20
+ '@typescript-eslint/interface-name-prefix': 'off',
21
+ '@typescript-eslint/explicit-function-return-type': 'off',
22
+ '@typescript-eslint/no-explicit-any': 'off',
23
+ '@typescript-eslint/no-use-before-define': 'off',
24
+ '@typescript-eslint/no-non-null-assertion': 'off',
25
+ },
26
+ };
@@ -0,0 +1,8 @@
1
+ {
2
+ "git": {
3
+ "commitMessage": "chore(): release v${version}"
4
+ },
5
+ "github": {
6
+ "release": true
7
+ }
8
+ }
@@ -32,6 +32,7 @@ const generateFiles = (inputs) => __awaiter(void 0, void 0, void 0, function* ()
32
32
  .value;
33
33
  const appName = inputs.find(option => option.name === 'project')
34
34
  .value;
35
+ const spec = inputs.find(option => option.name === 'spec');
35
36
  const collection = schematics_1.CollectionFactory.create(collectionOption || configuration.collection);
36
37
  const schematicOptions = mapSchematicOptions(inputs);
37
38
  schematicOptions.push(new schematics_1.SchematicOption('language', configuration.language));
@@ -39,6 +40,9 @@ const generateFiles = (inputs) => __awaiter(void 0, void 0, void 0, function* ()
39
40
  let sourceRoot = appName
40
41
  ? get_value_or_default_1.getValueOrDefault(configuration, 'sourceRoot', appName)
41
42
  : configuration.sourceRoot;
43
+ const specValue = spec.value;
44
+ const specOptions = spec.options;
45
+ let generateSpec = project_utils_1.shouldGenerateSpec(configuration, schematic, appName, specValue, specOptions.passedAsInput);
42
46
  // If you only add a `lib` we actually don't have monorepo: true BUT we do have "projects"
43
47
  // Ensure we don't run for new app/libs schematics
44
48
  if (project_utils_1.shouldAskForProject(schematic, configurationProjects, appName)) {
@@ -56,8 +60,13 @@ const generateFiles = (inputs) => __awaiter(void 0, void 0, void 0, function* ()
56
60
  if (project !== configuration.sourceRoot) {
57
61
  sourceRoot = configurationProjects[project].sourceRoot;
58
62
  }
63
+ if (answers.appName !== defaultProjectName) {
64
+ // Only overwrite if the appName is not the default- as it has already been loaded above
65
+ generateSpec = project_utils_1.shouldGenerateSpec(configuration, schematic, answers.appName, specValue, specOptions.passedAsInput);
66
+ }
59
67
  }
60
68
  schematicOptions.push(new schematics_1.SchematicOption('sourceRoot', sourceRoot));
69
+ schematicOptions.push(new schematics_1.SchematicOption('spec', generateSpec));
61
70
  try {
62
71
  const schematicInput = inputs.find(input => input.name === 'schematic');
63
72
  if (!schematicInput) {
@@ -72,9 +81,10 @@ const generateFiles = (inputs) => __awaiter(void 0, void 0, void 0, function* ()
72
81
  }
73
82
  });
74
83
  const mapSchematicOptions = (inputs) => {
84
+ const excludedInputNames = ['schematic', 'spec'];
75
85
  const options = [];
76
86
  inputs.forEach(input => {
77
- if (input.name !== 'schematic' && input.value !== undefined) {
87
+ if (!excludedInputNames.includes(input.name) && input.value !== undefined) {
78
88
  options.push(new schematics_1.SchematicOption(input.name, input.value));
79
89
  }
80
90
  });
@@ -26,13 +26,14 @@ const abstract_action_1 = require("./abstract.action");
26
26
  class NewAction extends abstract_action_1.AbstractAction {
27
27
  handle(inputs, options) {
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
+ const directoryOption = options.find(option => option.name === 'directory');
29
30
  const dryRunOption = options.find(option => option.name === 'dry-run');
30
31
  const isDryRunEnabled = dryRunOption && dryRunOption.value;
31
32
  yield askForMissingInformation(inputs);
32
33
  yield generateApplicationFiles(inputs, options).catch(exports.exit);
33
34
  const shouldSkipInstall = options.some(option => option.name === 'skip-install' && option.value === true);
34
35
  const shouldSkipGit = options.some(option => option.name === 'skip-git' && option.value === true);
35
- const projectDirectory = strings_1.dasherize(getApplicationNameInput(inputs).value);
36
+ const projectDirectory = getProjectDirectory(getApplicationNameInput(inputs), directoryOption);
36
37
  if (!shouldSkipInstall) {
37
38
  yield installPackages(options, isDryRunEnabled, projectDirectory);
38
39
  }
@@ -49,6 +50,10 @@ class NewAction extends abstract_action_1.AbstractAction {
49
50
  }
50
51
  exports.NewAction = NewAction;
51
52
  const getApplicationNameInput = (inputs) => inputs.find(input => input.name === 'name');
53
+ const getProjectDirectory = (applicationName, directoryOption) => {
54
+ return ((directoryOption && directoryOption.value) ||
55
+ strings_1.dasherize(applicationName.value));
56
+ };
52
57
  const askForMissingInformation = (inputs) => __awaiter(void 0, void 0, void 0, function* () {
53
58
  console.info(ui_1.MESSAGES.PROJECT_INFORMATION_START);
54
59
  console.info();
@@ -53,7 +53,7 @@ class StartAction extends build_action_1.BuildAction {
53
53
  const sourceRoot = get_value_or_default_1.getValueOrDefault(configuration, 'sourceRoot', appName);
54
54
  const entryFile = get_value_or_default_1.getValueOrDefault(configuration, 'entryFile', appName);
55
55
  let childProcessRef;
56
- process.on('exit', code => childProcessRef && killProcess(childProcessRef.pid));
56
+ process.on('exit', () => childProcessRef && killProcess(childProcessRef.pid));
57
57
  return () => {
58
58
  if (childProcessRef) {
59
59
  childProcessRef.removeAllListeners('exit');
@@ -1,4 +1,5 @@
1
1
  export interface Input {
2
2
  name: string;
3
3
  value: boolean | string;
4
+ options?: any;
4
5
  }
@@ -19,10 +19,15 @@ class GenerateCommand extends abstract_command_1.AbstractCommand {
19
19
  .command('generate <schematic> [name] [path]')
20
20
  .alias('g')
21
21
  .description(this.buildDescription())
22
- .option('--dry-run', 'Report actions that would be taken without writing out results.')
22
+ .option('-d, --dry-run', 'Report actions that would be taken without writing out results.')
23
23
  .option('-p, --project [project]', 'Project in which to generate files.')
24
24
  .option('--flat', 'Enforce flat structure of generated element.')
25
- .option('--no-spec', 'Disable spec files generation.')
25
+ .option('--spec', 'Enforce spec files generation.', () => {
26
+ return { value: true, passedAsInput: true };
27
+ }, true)
28
+ .option('--no-spec', 'Disable spec files generation.', () => {
29
+ return { value: false, passedAsInput: true };
30
+ })
26
31
  .option('-c, --collection [collectionName]', 'Schematics collection to use.')
27
32
  .action((schematic, name, path, command) => __awaiter(this, void 0, void 0, function* () {
28
33
  const options = [];
@@ -30,7 +35,14 @@ class GenerateCommand extends abstract_command_1.AbstractCommand {
30
35
  options.push({ name: 'flat', value: command.flat });
31
36
  options.push({
32
37
  name: 'spec',
33
- value: command.spec,
38
+ value: typeof command.spec === 'boolean'
39
+ ? command.spec
40
+ : command.spec.value,
41
+ options: {
42
+ passedAsInput: typeof command.spec === 'boolean'
43
+ ? false
44
+ : command.spec.passedAsInput,
45
+ },
34
46
  });
35
47
  options.push({
36
48
  name: 'collection',
@@ -17,6 +17,7 @@ class NewCommand extends abstract_command_1.AbstractCommand {
17
17
  .command('new [name]')
18
18
  .alias('n')
19
19
  .description('Generate Nest application.')
20
+ .option('--directory [directory]', 'Specify the destination directory')
20
21
  .option('-d, --dry-run', 'Report actions that would be performed without writing out results.')
21
22
  .option('-g, --skip-git', 'Skip git repository initialization.')
22
23
  .option('-s, --skip-install', 'Skip package installation.')
@@ -25,6 +26,7 @@ class NewCommand extends abstract_command_1.AbstractCommand {
25
26
  .option('-c, --collection [collectionName]', 'Schematics collection to use.')
26
27
  .action((name, command) => __awaiter(this, void 0, void 0, function* () {
27
28
  const options = [];
29
+ options.push({ name: 'directory', value: command.directory });
28
30
  options.push({ name: 'dry-run', value: !!command.dryRun });
29
31
  options.push({ name: 'skip-git', value: !!command.skipGit });
30
32
  options.push({ name: 'skip-install', value: !!command.skipInstall });
@@ -36,7 +36,7 @@ class AssetsManager {
36
36
  flat: item.flat,
37
37
  };
38
38
  });
39
- const copyFiles = (item) => new Promise((resolve, reject) => copyfiles([item.glob, outDir], {
39
+ const copyFiles = (item) => new Promise((resolve, reject) => copyfiles([item.glob, item.outDir], {
40
40
  exclude: item.exclude,
41
41
  flat: item.flat,
42
42
  up: sourceRoot.split(path_1.sep).length,
@@ -8,12 +8,15 @@ function getValueOrDefault(configuration, propertyPath, appName, key, options =
8
8
  }
9
9
  if (configuration.projects && configuration.projects[appName]) {
10
10
  const perAppValue = getValueOfPath(configuration, `projects.${appName}.`.concat(propertyPath));
11
- if (perAppValue) {
11
+ if (perAppValue !== undefined) {
12
12
  return perAppValue;
13
13
  }
14
14
  }
15
- const value = getValueOfPath(configuration, propertyPath);
16
- return value || defaultValue;
15
+ let value = getValueOfPath(configuration, propertyPath);
16
+ if (value === undefined) {
17
+ value = defaultValue;
18
+ }
19
+ return value;
17
20
  }
18
21
  exports.getValueOrDefault = getValueOrDefault;
19
22
  function getValueOfPath(object, propertyPath) {
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs_1 = require("fs");
4
3
  const path_1 = require("path");
5
4
  const util_1 = require("util");
6
5
  const ui_1 = require("../ui");
@@ -12,13 +11,13 @@ class PluginsLoader {
12
11
  ...module.paths,
13
12
  ];
14
13
  const pluginRefs = pluginNames.map(item => {
15
- for (const path of nodeModulePaths) {
16
- const binaryPath = path_1.resolve(path, item);
17
- if (fs_1.existsSync(binaryPath + '.js')) {
18
- return require(binaryPath);
19
- }
14
+ try {
15
+ const binaryPath = require.resolve(item, { paths: nodeModulePaths });
16
+ return require(binaryPath);
17
+ }
18
+ catch (e) {
19
+ throw new Error(`"${item}" plugin could not be found!`);
20
20
  }
21
- throw new Error(`"${item}" plugin could not be found!`);
22
21
  });
23
22
  const beforeHooks = [];
24
23
  const afterHooks = [];
@@ -13,6 +13,9 @@ interface CompilerOptions {
13
13
  assets?: string[];
14
14
  deleteOutDir?: boolean;
15
15
  }
16
+ interface GenerateOptions {
17
+ spec?: boolean | Record<string, boolean>;
18
+ }
16
19
  export interface ProjectConfiguration {
17
20
  type?: string;
18
21
  root?: string;
@@ -28,6 +31,7 @@ export interface Configuration {
28
31
  entryFile?: string;
29
32
  monorepo?: boolean;
30
33
  compilerOptions?: CompilerOptions;
34
+ generateOptions?: GenerateOptions;
31
35
  projects?: {
32
36
  [key: string]: ProjectConfiguration;
33
37
  };
@@ -14,6 +14,7 @@ exports.defaultConfiguration = {
14
14
  plugins: [],
15
15
  assets: [],
16
16
  },
17
+ generateOptions: {},
17
18
  };
18
19
  exports.defaultOutDir = 'dist';
19
20
  exports.defaultGitIgnore = `# compiled output
@@ -8,6 +8,7 @@ function localBinExists() {
8
8
  }
9
9
  exports.localBinExists = localBinExists;
10
10
  function loadLocalBinCommandLoader() {
11
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
11
12
  const commandsFile = require(path_1.posix.join(...localBinPathSegments, 'commands'));
12
13
  return commandsFile.CommandLoader;
13
14
  }
@@ -3,5 +3,6 @@ import { Configuration, ProjectConfiguration } from '../configuration';
3
3
  export declare function shouldAskForProject(schematic: string, configurationProjects: {
4
4
  [key: string]: ProjectConfiguration;
5
5
  }, appName: string): boolean;
6
+ export declare function shouldGenerateSpec(configuration: Required<Configuration>, schematic: string, appName: string, specValue: boolean, specPassedAsInput?: boolean): any;
6
7
  export declare function askForProjectName(promptQuestion: string, projects: string[]): Promise<Answers>;
7
8
  export declare function moveDefaultProjectToStart(configuration: Configuration, defaultProjectName: string, defaultLabel: string): string[];
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const inquirer = require("inquirer");
13
+ const get_value_or_default_1 = require("../compiler/helpers/get-value-or-default");
13
14
  const questions_1 = require("../questions/questions");
14
15
  function shouldAskForProject(schematic, configurationProjects, appName) {
15
16
  return (['app', 'sub-app', 'library', 'lib'].includes(schematic) === false &&
@@ -18,6 +19,34 @@ function shouldAskForProject(schematic, configurationProjects, appName) {
18
19
  !appName);
19
20
  }
20
21
  exports.shouldAskForProject = shouldAskForProject;
22
+ function shouldGenerateSpec(configuration, schematic, appName, specValue, specPassedAsInput) {
23
+ if (specPassedAsInput === true || specPassedAsInput === undefined) {
24
+ // CLI parameters has the highest priority
25
+ return specValue;
26
+ }
27
+ let specConfiguration = get_value_or_default_1.getValueOrDefault(configuration, 'generateOptions.spec', appName || '');
28
+ if (typeof specConfiguration === 'boolean') {
29
+ return specConfiguration;
30
+ }
31
+ if (typeof specConfiguration === 'object' &&
32
+ specConfiguration[schematic] !== undefined) {
33
+ return specConfiguration[schematic];
34
+ }
35
+ if (typeof specConfiguration === 'object' && appName) {
36
+ // The appName has a generateOption spec, but not for the schematic trying to generate
37
+ // Check if the global generateOptions has a spec to use instead
38
+ specConfiguration = get_value_or_default_1.getValueOrDefault(configuration, 'generateOptions.spec', '');
39
+ if (typeof specConfiguration === 'boolean') {
40
+ return specConfiguration;
41
+ }
42
+ if (typeof specConfiguration === 'object' &&
43
+ specConfiguration[schematic] !== undefined) {
44
+ return specConfiguration[schematic];
45
+ }
46
+ }
47
+ return specValue;
48
+ }
49
+ exports.shouldGenerateSpec = shouldGenerateSpec;
21
50
  function askForProjectName(promptQuestion, projects) {
22
51
  return __awaiter(this, void 0, void 0, function* () {
23
52
  const questions = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/cli",
3
- "version": "6.14.0-next.1",
3
+ "version": "6.14.2",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@cli)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,14 +16,16 @@
16
16
  "build": "tsc",
17
17
  "clean": "gulp clean:bundle",
18
18
  "format": "prettier --write \"**/*.ts\"",
19
- "lint": "tslint -p .",
19
+ "lint": "eslint '{lib,commands,actions}/**/*.ts' --fix",
20
20
  "start": "node bin/nest.js",
21
21
  "prepublish:next": "npm run build",
22
22
  "publish:next": "npm publish --access public --tag next",
23
23
  "prepublish:npm": "npm run build",
24
24
  "publish:npm": "npm publish --access public",
25
25
  "test": "jest --config test/jest-config.json",
26
- "test:dev": "npm run clean && jest --config test/jest-config.json --watchAll"
26
+ "test:dev": "npm run clean && jest --config test/jest-config.json --watchAll",
27
+ "prerelease": "npm run build",
28
+ "release": "release-it"
27
29
  },
28
30
  "repository": {
29
31
  "type": "git",
@@ -43,18 +45,18 @@
43
45
  "@angular-devkit/core": "7.3.8",
44
46
  "@angular-devkit/schematics": "7.3.8",
45
47
  "@angular-devkit/schematics-cli": "0.13.8",
46
- "@nestjs/schematics": "^6.8.0",
47
- "@types/webpack": "4.41.2",
48
+ "@nestjs/schematics": "^6.8.2",
49
+ "@types/webpack": "4.41.5",
48
50
  "chalk": "2.4.2",
49
51
  "cli-table3": "0.5.1",
50
- "commander": "4.1.0",
51
- "copyfiles": "2.1.1",
52
- "fork-ts-checker-webpack-plugin": "3.1.1",
53
- "inquirer": "7.0.3",
52
+ "commander": "4.1.1",
53
+ "copyfiles": "2.2.0",
54
+ "fork-ts-checker-webpack-plugin": "4.0.3",
55
+ "inquirer": "7.0.4",
54
56
  "node-emoji": "1.10.0",
55
57
  "ora": "4.0.3",
56
58
  "os-name": "3.1.0",
57
- "rimraf": "3.0.0",
59
+ "rimraf": "3.0.1",
58
60
  "tree-kill": "1.2.2",
59
61
  "tsconfig-paths": "3.9.0",
60
62
  "tsconfig-paths-webpack-plugin": "3.2.0",
@@ -63,23 +65,36 @@
63
65
  "webpack-node-externals": "1.7.2"
64
66
  },
65
67
  "devDependencies": {
68
+ "@commitlint/cli": "8.3.5",
69
+ "@commitlint/config-angular": "8.3.4",
66
70
  "@types/copyfiles": "2.1.1",
67
71
  "@types/inquirer": "6.5.0",
68
- "@types/jest": "24.0.25",
72
+ "@types/jest": "25.1.1",
69
73
  "@types/node": "12.12.21",
70
74
  "@types/node-emoji": "1.8.1",
71
75
  "@types/ora": "3.1.0",
72
76
  "@types/os-name": "2.0.0",
73
77
  "@types/rimraf": "2.0.3",
74
- "@types/webpack-node-externals": "1.7.0",
78
+ "@types/webpack-node-externals": "1.7.1",
79
+ "@typescript-eslint/eslint-plugin": "^2.19.0",
80
+ "@typescript-eslint/parser": "^2.19.0",
75
81
  "delete-empty": "3.0.0",
82
+ "eslint": "6.8.0",
83
+ "eslint-config-prettier": "6.10.0",
84
+ "eslint-plugin-import": "2.20.1",
76
85
  "gulp": "4.0.2",
77
86
  "gulp-clean": "0.4.0",
78
- "jest": "24.9.0",
87
+ "husky": "4.2.1",
88
+ "jest": "25.1.0",
79
89
  "prettier": "1.19.1",
80
- "ts-jest": "24.3.0",
90
+ "release-it": "12.4.3",
91
+ "ts-jest": "25.2.0",
81
92
  "ts-loader": "6.2.1",
82
- "ts-node": "8.6.0",
83
- "tslint": "5.20.1"
93
+ "ts-node": "8.6.2"
94
+ },
95
+ "husky": {
96
+ "hooks": {
97
+ "commit-msg": "commitlint -c .commitlintrc.json -E HUSKY_GIT_PARAMS"
98
+ }
84
99
  }
85
100
  }