@o3r/create 10.0.0-prerelease.11 → 10.0.0-prerelease.111

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 +17 -3
  2. package/index.js +55 -23
  3. package/package.json +30 -20
package/README.md CHANGED
@@ -9,14 +9,28 @@ This package is simplifying the start of an [Otter Framework](https://github.com
9
9
 
10
10
  ## Usage
11
11
 
12
- ### NPM
13
-
14
12
  ```shell
15
13
  npm create @o3r <project-name> -- [...options]
16
14
  ```
17
15
 
18
- ### Yarn
16
+ or
19
17
 
20
18
  ```shell
21
19
  yarn create @o3r <project-name> [...options]
22
20
  ```
21
+
22
+ > [!WARNING]
23
+ > Please notice that the command `yarn create` is **not** available for versions *>= 2.0.0* (see [Yarn cli commands](https://yarnpkg.com/cli)).
24
+
25
+ You can generate an environment with a specific package manager thanks to the `--package-manager` options:
26
+
27
+ ```shell
28
+ npm create @o3r <project-name> -- --package-manager=yarn [...options]
29
+ ```
30
+
31
+ ## Available options
32
+
33
+ The generator accepts all the configurations from Angular `ng new` command, find the list [here](https://angular.io/cli/new#options).
34
+ On top of them, the following options can be provided to the initializer:
35
+
36
+ - `--yarn-version` : specify the version of yarn to use (default: `latest`)
package/index.js CHANGED
@@ -6,7 +6,10 @@ const node_path_1 = require("node:path");
6
6
  const node_fs_1 = require("node:fs");
7
7
  const minimist = require("minimist");
8
8
  const { properties } = JSON.parse((0, node_fs_1.readFileSync)(require.resolve('@schematics/angular/ng-new/schema').replace(/\.js$/, '.json'), { encoding: 'utf-8' }));
9
- const { version } = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.resolve)(__dirname, 'package.json'), { encoding: 'utf-8' }));
9
+ const { version, dependencies, devDependencies } = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.resolve)(__dirname, 'package.json'), { encoding: 'utf-8' }));
10
+ const optionsList = [
11
+ 'yarn-version'
12
+ ];
10
13
  const logo = `
11
14
 
12
15
  &BPPPB & &BPGB&
@@ -77,15 +80,14 @@ if (!args.some((a) => a.startsWith('--style'))) {
77
80
  if (!args.some((a) => a.startsWith('--preset'))) {
78
81
  args.push('--preset', 'basic');
79
82
  }
80
- const hasPackageManagerArg = args.some((a) => a.startsWith('--package-manager'));
81
- if (!hasPackageManagerArg) {
82
- const packageManager = process.env.npm_config_user_agent?.split('/')[0];
83
- if (packageManager && ['npm', 'pnpm', 'yarn', 'cnpm'].includes(packageManager)) {
84
- args.push('--package-manager', packageManager);
85
- }
86
- }
87
83
  args.push('--no-create-application');
88
84
  const argv = minimist(args);
85
+ const packageManagerEnv = process.env.npm_config_user_agent?.split('/')[0];
86
+ let defaultPackageManager = 'npm';
87
+ if (packageManagerEnv && ['npm', 'yarn'].includes(packageManagerEnv)) {
88
+ defaultPackageManager = packageManagerEnv;
89
+ }
90
+ const packageManager = argv['package-manager'] || defaultPackageManager;
89
91
  if (argv._.length === 0) {
90
92
  // eslint-disable-next-line no-console
91
93
  console.error('The project name is mandatory');
@@ -105,8 +107,17 @@ const isNgNewOptions = (arg) => {
105
107
  }
106
108
  return true;
107
109
  };
110
+ const exitProcessIfErrorInSpawnSync = (exitCode, { error, status }) => {
111
+ if (error || status !== 0) {
112
+ if (error) {
113
+ // eslint-disable-next-line no-console
114
+ console.error(error);
115
+ }
116
+ process.exit(exitCode);
117
+ }
118
+ };
108
119
  const schematicsCliOptions = Object.entries(argv)
109
- .filter(([key]) => key !== '_')
120
+ .filter(([key]) => key !== '_' && !optionsList.includes(key))
110
121
  .map(([key, value]) => value === true && [key] || value === false && key.length > 1 && [`no-${key}`] || [key, value])
111
122
  .map(([key, value]) => {
112
123
  const optionKey = key.length > 1 ? `--${key}` : `-${key}`;
@@ -116,30 +127,51 @@ const createNgProject = () => {
116
127
  const options = schematicsCliOptions
117
128
  .filter(([key]) => isNgNewOptions(key))
118
129
  .flat();
119
- const { error } = (0, node_child_process_1.spawnSync)(process.execPath, [binPath, 'new', ...argv._, ...options, '--skip-install'], {
130
+ exitProcessIfErrorInSpawnSync(1, (0, node_child_process_1.spawnSync)(process.execPath, [binPath, 'new', ...argv._, ...options], {
120
131
  stdio: 'inherit'
132
+ }));
133
+ };
134
+ const prepareWorkspace = (relativeDirectory = '.', projectPackageManager = 'npm') => {
135
+ const cwd = (0, node_path_1.resolve)(process.cwd(), relativeDirectory);
136
+ const runner = process.platform === 'win32' ? `${projectPackageManager}.cmd` : projectPackageManager;
137
+ const mandatoryDependencies = [
138
+ '@angular-devkit/schematics',
139
+ '@schematics/angular',
140
+ '@angular-devkit/core',
141
+ '@angular-devkit/architect'
142
+ ];
143
+ const packageJsonPath = (0, node_path_1.resolve)(cwd, 'package.json');
144
+ const packageJson = JSON.parse((0, node_fs_1.readFileSync)(packageJsonPath, { encoding: 'utf-8' })
145
+ // Replace the ^ with ~ to use the same minor version for angular packages as @angular/cli
146
+ .replace(/(@(?:angular|schematics).*)\^/g, '$1~'));
147
+ packageJson.devDependencies ||= {};
148
+ mandatoryDependencies.forEach((dep) => {
149
+ packageJson.devDependencies[dep] = dependencies?.[dep] || devDependencies?.[dep] || 'latest';
121
150
  });
122
- if (error) {
123
- // eslint-disable-next-line no-console
124
- console.error(error);
125
- process.exit(1);
151
+ (0, node_fs_1.writeFileSync)(packageJsonPath, JSON.stringify(packageJson, null, 2));
152
+ if (projectPackageManager === 'yarn') {
153
+ exitProcessIfErrorInSpawnSync(2, (0, node_child_process_1.spawnSync)(runner, ['set', 'version', argv['yarn-version'] || 'stable'], {
154
+ stdio: 'inherit',
155
+ cwd
156
+ }));
126
157
  }
158
+ exitProcessIfErrorInSpawnSync(2, (0, node_child_process_1.spawnSync)(runner, ['install'], {
159
+ stdio: 'inherit',
160
+ cwd
161
+ }));
127
162
  };
128
- const addOtterFramework = (relativeDirectory = '.') => {
163
+ const addOtterFramework = (relativeDirectory = '.', projectPackageManager = 'npm') => {
129
164
  const cwd = (0, node_path_1.resolve)(process.cwd(), relativeDirectory);
165
+ const runner = process.platform === 'win32' ? `${projectPackageManager}.cmd` : projectPackageManager;
130
166
  const options = schematicsCliOptions
131
167
  .flat();
132
- const { error } = (0, node_child_process_1.spawnSync)(process.execPath, [binPath, 'add', `@o3r/core@${version || 'latest'}`, ...options], {
168
+ exitProcessIfErrorInSpawnSync(3, (0, node_child_process_1.spawnSync)(runner, ['exec', 'ng', 'add', `@o3r/core@~${version}`, ...(projectPackageManager === 'npm' ? ['--'] : []), ...options], {
133
169
  stdio: 'inherit',
134
170
  cwd
135
- });
136
- if (error) {
137
- // eslint-disable-next-line no-console
138
- console.error(error);
139
- process.exit(2);
140
- }
171
+ }));
141
172
  };
142
173
  const projectFolder = argv._[0]?.replaceAll(' ', '-').toLowerCase() || '.';
143
174
  console.info(logo);
144
175
  createNgProject();
145
- addOtterFramework(projectFolder);
176
+ prepareWorkspace(projectFolder, packageManager);
177
+ addOtterFramework(projectFolder, packageManager);
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@o3r/create",
3
- "version": "10.0.0-prerelease.11",
3
+ "version": "10.0.0-prerelease.111",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
4
7
  "description": "Create a new Otter based application",
5
8
  "keywords": [
6
9
  "create",
@@ -15,46 +18,53 @@
15
18
  "prepare:publish": "prepare-publish ./dist"
16
19
  },
17
20
  "dependencies": {
18
- "@angular/cli": "~17.0.3",
19
- "@schematics/angular": "~17.0.3",
21
+ "@angular/cli": "~17.2.0",
22
+ "@schematics/angular": "~17.2.0",
20
23
  "minimist": "^1.2.6",
21
- "tslib": "^2.5.3"
24
+ "tslib": "^2.5.3",
25
+ "type-fest": "^4.10.2"
22
26
  },
23
27
  "devDependencies": {
28
+ "@angular-devkit/architect": "~0.1702.0",
29
+ "@angular-devkit/core": "~17.2.0",
30
+ "@angular-devkit/schematics": "~17.2.0",
24
31
  "@angular-eslint/eslint-plugin": "~17.2.0",
25
32
  "@angular-eslint/eslint-plugin-template": "~17.2.0",
26
- "@nx/eslint": "~17.2.0",
27
- "@nx/eslint-plugin": "~17.2.0",
28
- "@nx/jest": "~17.2.0",
29
- "@nx/js": "~17.2.0",
30
- "@o3r/build-helpers": "^10.0.0-prerelease.11",
31
- "@o3r/eslint-config-otter": "^10.0.0-prerelease.11",
32
- "@o3r/eslint-plugin": "^10.0.0-prerelease.11",
33
- "@o3r/test-helpers": "^10.0.0-prerelease.11",
33
+ "@nx/eslint": "~18.0.2",
34
+ "@nx/eslint-plugin": "~18.0.2",
35
+ "@nx/jest": "~18.0.2",
36
+ "@nx/js": "~18.0.2",
37
+ "@o3r/build-helpers": "^10.0.0-prerelease.111",
38
+ "@o3r/eslint-config-otter": "^10.0.0-prerelease.111",
39
+ "@o3r/eslint-plugin": "^10.0.0-prerelease.111",
40
+ "@o3r/test-helpers": "^10.0.0-prerelease.111",
41
+ "@stylistic/eslint-plugin-ts": "^1.5.4",
34
42
  "@types/jest": "~29.5.2",
35
43
  "@types/minimist": "^1.2.2",
36
44
  "@types/node": "^20.0.0",
37
- "@typescript-eslint/eslint-plugin": "^6.19.0",
38
- "@typescript-eslint/parser": "^6.11.0",
45
+ "@typescript-eslint/eslint-plugin": "^7.0.1",
46
+ "@typescript-eslint/parser": "^7.0.1",
39
47
  "cpy-cli": "^5.0.0",
40
48
  "eslint": "^8.42.0",
41
49
  "eslint-import-resolver-node": "^0.3.4",
42
- "eslint-plugin-jest": "~27.6.0",
43
- "eslint-plugin-jsdoc": "~48.0.0",
50
+ "eslint-plugin-jest": "~27.9.0",
51
+ "eslint-plugin-jsdoc": "~48.1.0",
44
52
  "eslint-plugin-prefer-arrow": "~1.2.3",
45
- "eslint-plugin-unicorn": "^50.0.0",
53
+ "eslint-plugin-unicorn": "^51.0.0",
46
54
  "jest": "~29.7.0",
47
55
  "jest-junit": "~16.0.0",
48
56
  "jsonc-eslint-parser": "~2.4.0",
49
- "nx": "~17.2.0",
57
+ "nx": "~18.0.2",
50
58
  "rimraf": "^5.0.1",
51
59
  "rxjs": "^7.8.1",
52
60
  "ts-jest": "~29.1.1",
53
- "type-fest": "^4.3.1",
61
+ "type-fest": "^4.10.2",
54
62
  "typescript": "~5.2.2"
55
63
  },
56
64
  "engines": {
57
- "node": ">=18.0.0"
65
+ "node": ">=18.0.0",
66
+ "yarn": "<2.0.0",
67
+ "npm": "*"
58
68
  },
59
69
  "contributors": [
60
70
  {