@o3r/create 11.0.0-prerelease.13 → 11.0.0-prerelease.14

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.
Files changed (3) hide show
  1. package/README.md +20 -10
  2. package/index.js +44 -15
  3. package/package.json +8 -6
package/README.md CHANGED
@@ -20,25 +20,35 @@ This package is simplifying the start of an [Otter Framework](https://github.com
20
20
  npm create @o3r <project-name> -- [...options]
21
21
  ```
22
22
 
23
- or
23
+ > [!WARNING]
24
+ > `yarn create` is not supported.
25
+
26
+ ### Custom package manager
27
+
28
+ You can generate an environment with a specific package manager thanks to the `--package-manager` options:
24
29
 
25
30
  ```shell
26
- yarn create @o3r <project-name> [...options]
31
+ npm create @o3r <project-name> -- --package-manager=yarn [...options]
27
32
  ```
28
33
 
29
- > [!WARNING]
30
- > Please notice that the command `yarn create` is **not** available for versions *>= 2.0.0* (see [Yarn cli commands](https://yarnpkg.com/cli)).
34
+ > [!NOTE]
35
+ > At the moment, the ``package-manager`` option only supports `yarn` and `npm`.
31
36
 
32
- You can generate an environment with a specific package manager thanks to the `--package-manager` options:
37
+ ### Custom registry
38
+
39
+ You can specify the npm's package registry to use.
33
40
 
34
41
  ```shell
35
- npm create @o3r <project-name> -- --package-manager=yarn [...options]
42
+ npm create @o3r <project-name> --registry=<registry-url> -- [...options]
36
43
  ```
37
44
 
38
- ## Available options
45
+ It will create a project with a `.npmrc` file configured to target the specified registry.
46
+ If the specified package manager is `yarn`, it will also configure the `.yarnrc.yml` file.
47
+
48
+ ### Others available options
39
49
 
40
- The generator accepts all the configurations from Angular `ng new` command, find the list [here](https://angular.io/cli/new#options).
50
+ The generator accepts all the configurations from the Angular `ng new` command, see the [options list](https://angular.io/cli/new#options).
41
51
  On top of them, the following options can be provided to the initializer:
42
52
 
43
- - `--yarn-version` : specify the version of yarn to use (default: `latest`)
44
- - `--exact-o3r-version` : use a pinned version for [otter packages](https://github.com/AmadeusITGroup/otter/blob/main/docs/README.md).
53
+ - `--yarn-version`: specify the version of yarn to use (default: `latest`)
54
+ - `--exact-o3r-version`: use a pinned version for [Otter packages](https://github.com/AmadeusITGroup/otter/blob/main/docs/README.md).
package/index.js CHANGED
@@ -5,6 +5,7 @@ const node_child_process_1 = require("node:child_process");
5
5
  const node_path_1 = require("node:path");
6
6
  const node_fs_1 = require("node:fs");
7
7
  const minimist = require("minimist");
8
+ const shell_quote_1 = require("shell-quote");
8
9
  const { properties } = JSON.parse((0, node_fs_1.readFileSync)(require.resolve('@schematics/angular/ng-new/schema').replace(/\.js$/, '.json'), { encoding: 'utf-8' }));
9
10
  const { version, dependencies, devDependencies } = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.resolve)(__dirname, 'package.json'), { encoding: 'utf-8' }));
10
11
  const optionsList = [
@@ -81,13 +82,24 @@ if (!args.some((a) => a.startsWith('--preset'))) {
81
82
  args.push('--preset', 'basic');
82
83
  }
83
84
  args.push('--no-create-application');
85
+ const supportedPackageManager = ['npm', 'yarn'];
86
+ const supportedPackageManagerRegExp = new RegExp(`^(${supportedPackageManager.join('|')})$`);
84
87
  const argv = minimist(args);
85
88
  const packageManagerEnv = process.env.npm_config_user_agent?.split('/')[0];
86
- let defaultPackageManager = 'npm';
87
- if (packageManagerEnv && ['npm', 'yarn'].includes(packageManagerEnv)) {
89
+ let defaultPackageManager = supportedPackageManager[0];
90
+ if (packageManagerEnv && supportedPackageManager.includes(packageManagerEnv)) {
88
91
  defaultPackageManager = packageManagerEnv;
89
92
  }
90
- const packageManager = argv['package-manager'] || defaultPackageManager;
93
+ const argvPackageManager = argv['package-manager'];
94
+ let packageManager = supportedPackageManagerRegExp.test(argvPackageManager) ? argv['package-manager'] : defaultPackageManager;
95
+ if (argvPackageManager && supportedPackageManagerRegExp.test(argvPackageManager)) {
96
+ packageManager = argvPackageManager;
97
+ }
98
+ else if (argvPackageManager) {
99
+ // eslint-disable-next-line no-console
100
+ console.error(`The package manager option supports only npm and yarn, you provided "${argvPackageManager}"`);
101
+ process.exit(-1);
102
+ }
91
103
  const exactO3rVersion = !!argv['exact-o3r-version'];
92
104
  if (argv._.length === 0) {
93
105
  // eslint-disable-next-line no-console
@@ -108,6 +120,12 @@ const isNgNewOptions = (arg) => {
108
120
  }
109
121
  return true;
110
122
  };
123
+ const NG_NEW_ERROR_CODE = 1;
124
+ const YARN_SET_VERSION_ERROR_CODE = 2;
125
+ const ADD_O3R_CORE_ERROR_CODE = 3;
126
+ const NPM_CONFIG_REGISTRY_ERROR_CODE = 4;
127
+ const YARN_CONFIG_REGISTRY_ERROR_CODE = 5;
128
+ const INSTALL_PROCESS_ERROR_CODE = 6;
111
129
  const exitProcessIfErrorInSpawnSync = (exitCode, { error, status }) => {
112
130
  if (error || status !== 0) {
113
131
  if (error) {
@@ -128,13 +146,23 @@ const createNgProject = () => {
128
146
  const options = schematicsCliOptions
129
147
  .filter(([key]) => isNgNewOptions(key))
130
148
  .flat();
131
- exitProcessIfErrorInSpawnSync(1, (0, node_child_process_1.spawnSync)(`"${process.execPath}"`, [binPath, 'new', ...argv._, ...options], {
149
+ exitProcessIfErrorInSpawnSync(NG_NEW_ERROR_CODE, (0, node_child_process_1.spawnSync)(`"${process.execPath}"`, [
150
+ binPath,
151
+ 'new',
152
+ ...argv._.map((arg) => arg && (0, shell_quote_1.quote)([arg])),
153
+ ...options.map((opt) => opt && (0, shell_quote_1.quote)([opt]))
154
+ ], {
132
155
  stdio: 'inherit',
133
156
  shell: true
134
157
  }));
135
158
  };
136
159
  const prepareWorkspace = (relativeDirectory = '.', projectPackageManager = 'npm') => {
137
160
  const cwd = (0, node_path_1.resolve)(process.cwd(), relativeDirectory);
161
+ const spawnSyncOpts = {
162
+ stdio: 'inherit',
163
+ shell: true,
164
+ cwd
165
+ };
138
166
  const runner = process.platform === 'win32' ? `${projectPackageManager}.cmd` : projectPackageManager;
139
167
  const mandatoryDependencies = [
140
168
  '@angular-devkit/schematics',
@@ -169,24 +197,25 @@ const prepareWorkspace = (relativeDirectory = '.', projectPackageManager = 'npm'
169
197
  }
170
198
  (0, node_fs_1.writeFileSync)(packageJsonPath, JSON.stringify(packageJson, null, 2));
171
199
  if (projectPackageManager === 'yarn') {
172
- exitProcessIfErrorInSpawnSync(2, (0, node_child_process_1.spawnSync)(runner, ['set', 'version', argv['yarn-version'] || 'stable'], {
173
- stdio: 'inherit',
174
- shell: true,
175
- cwd
176
- }));
200
+ const yarnVersion = (0, shell_quote_1.quote)([argv['yarn-version'] || 'stable']);
201
+ exitProcessIfErrorInSpawnSync(YARN_SET_VERSION_ERROR_CODE, (0, node_child_process_1.spawnSync)(runner, ['set', 'version', yarnVersion], spawnSyncOpts));
177
202
  }
178
- exitProcessIfErrorInSpawnSync(2, (0, node_child_process_1.spawnSync)(runner, ['install'], {
179
- stdio: 'inherit',
180
- shell: true,
181
- cwd
182
- }));
203
+ const registry = process.env.npm_config_registry || (argv.registry && (0, shell_quote_1.quote)([argv.registry]));
204
+ if (registry) {
205
+ // Need to add this even for yarn because `ng add` only reads registry from .npmrc
206
+ exitProcessIfErrorInSpawnSync(NPM_CONFIG_REGISTRY_ERROR_CODE, (0, node_child_process_1.spawnSync)(runner, ['config', 'set', '-L', 'project', 'registry', registry], spawnSyncOpts));
207
+ if (projectPackageManager === 'yarn') {
208
+ exitProcessIfErrorInSpawnSync(YARN_CONFIG_REGISTRY_ERROR_CODE, (0, node_child_process_1.spawnSync)(runner, ['config', 'set', 'npmRegistryServer', registry], spawnSyncOpts));
209
+ }
210
+ }
211
+ exitProcessIfErrorInSpawnSync(INSTALL_PROCESS_ERROR_CODE, (0, node_child_process_1.spawnSync)(runner, ['install'], spawnSyncOpts));
183
212
  };
184
213
  const addOtterFramework = (relativeDirectory = '.', projectPackageManager = 'npm') => {
185
214
  const cwd = (0, node_path_1.resolve)(process.cwd(), relativeDirectory);
186
215
  const runner = process.platform === 'win32' ? `${projectPackageManager}.cmd` : projectPackageManager;
187
216
  const options = schematicsCliOptions
188
217
  .flat();
189
- exitProcessIfErrorInSpawnSync(3, (0, node_child_process_1.spawnSync)(runner, ['exec', 'ng', 'add', `@o3r/core@${exactO3rVersion ? '' : '~'}${version}`, ...(projectPackageManager === 'npm' ? ['--'] : []), ...options], {
218
+ exitProcessIfErrorInSpawnSync(ADD_O3R_CORE_ERROR_CODE, (0, node_child_process_1.spawnSync)(runner, ['exec', 'ng', 'add', `@o3r/core@${exactO3rVersion ? '' : '~'}${version}`, ...(projectPackageManager === 'npm' ? ['--'] : []), ...options], {
190
219
  stdio: 'inherit',
191
220
  cwd,
192
221
  shell: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/create",
3
- "version": "11.0.0-prerelease.13",
3
+ "version": "11.0.0-prerelease.14",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -21,6 +21,7 @@
21
21
  "@angular/cli": "~17.3.0",
22
22
  "@schematics/angular": "~17.3.0",
23
23
  "minimist": "^1.2.6",
24
+ "shell-quote": "^1.8.1",
24
25
  "tslib": "^2.6.2",
25
26
  "type-fest": "^4.10.2"
26
27
  },
@@ -34,15 +35,16 @@
34
35
  "@nx/eslint-plugin": "~18.3.0",
35
36
  "@nx/jest": "~18.3.0",
36
37
  "@nx/js": "~18.3.0",
37
- "@o3r/build-helpers": "^11.0.0-prerelease.13",
38
- "@o3r/eslint-config-otter": "^11.0.0-prerelease.13",
39
- "@o3r/eslint-plugin": "^11.0.0-prerelease.13",
40
- "@o3r/schematics": "^11.0.0-prerelease.13",
41
- "@o3r/test-helpers": "^11.0.0-prerelease.13",
38
+ "@o3r/build-helpers": "^11.0.0-prerelease.14",
39
+ "@o3r/eslint-config-otter": "^11.0.0-prerelease.14",
40
+ "@o3r/eslint-plugin": "^11.0.0-prerelease.14",
41
+ "@o3r/schematics": "^11.0.0-prerelease.14",
42
+ "@o3r/test-helpers": "^11.0.0-prerelease.14",
42
43
  "@stylistic/eslint-plugin-ts": "^1.5.4",
43
44
  "@types/jest": "~29.5.2",
44
45
  "@types/minimist": "^1.2.2",
45
46
  "@types/node": "^20.0.0",
47
+ "@types/shell-quote": "^1.7.5",
46
48
  "@typescript-eslint/eslint-plugin": "^7.2.0",
47
49
  "@typescript-eslint/parser": "^7.2.0",
48
50
  "cpy-cli": "^5.0.0",