@o3r/create 11.0.0-next.0 → 11.0.0-next.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.
Files changed (3) hide show
  1. package/README.md +25 -3
  2. package/index.js +88 -24
  3. package/package.json +37 -26
package/README.md CHANGED
@@ -3,20 +3,42 @@
3
3
  <img src="https://raw.githubusercontent.com/AmadeusITGroup/otter/main/assets/logo/otter.png" alt="Super cute Otter!" width="40%"/>
4
4
  </p>
5
5
 
6
+ ## Description
7
+
8
+ [![Stable Version](https://img.shields.io/npm/v/@o3r/create?style=for-the-badge)](https://www.npmjs.com/package/@o3r/create)
9
+ [![Bundle Size](https://img.shields.io/bundlephobia/min/@o3r/create?color=green&style=for-the-badge)](https://www.npmjs.com/package/@o3r/create)
10
+
11
+ This package is an [NPM initializer](https://docs.npmjs.com/cli/v8/commands/npm-init) to generate a web application based on the [Otter Framework](https://github.com/AmadeusITGroup/otter).
12
+
6
13
  ## Create an Otter application
7
14
 
8
15
  This package is simplifying the start of an [Otter Framework](https://github.com/AmadeusITGroup/otter) based application.
9
16
 
10
17
  ## Usage
11
18
 
12
- ### NPM
13
-
14
19
  ```shell
15
20
  npm create @o3r <project-name> -- [...options]
16
21
  ```
17
22
 
18
- ### Yarn
23
+ or
19
24
 
20
25
  ```shell
21
26
  yarn create @o3r <project-name> [...options]
22
27
  ```
28
+
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)).
31
+
32
+ You can generate an environment with a specific package manager thanks to the `--package-manager` options:
33
+
34
+ ```shell
35
+ npm create @o3r <project-name> -- --package-manager=yarn [...options]
36
+ ```
37
+
38
+ ## Available options
39
+
40
+ The generator accepts all the configurations from Angular `ng new` command, find the list [here](https://angular.io/cli/new#options).
41
+ On top of them, the following options can be provided to the initializer:
42
+
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).
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&
@@ -69,18 +72,23 @@ const logo = `
69
72
  `;
70
73
  const binPath = (0, node_path_1.join)(require.resolve('@angular/cli/package.json'), '../bin/ng.js');
71
74
  const args = process.argv.slice(2).filter((a) => a !== '--create-application');
75
+ // Default styling to Sass
72
76
  if (!args.some((a) => a.startsWith('--style'))) {
73
77
  args.push('--style', 'scss');
74
78
  }
75
- const hasPackageManagerArg = args.some((a) => a.startsWith('--package-manager'));
76
- if (!hasPackageManagerArg) {
77
- const packageManager = process.env.npm_config_user_agent?.split('/')[0];
78
- if (packageManager && ['npm', 'pnpm', 'yarn', 'cnpm'].includes(packageManager)) {
79
- args.push('--package-manager', packageManager);
80
- }
79
+ // Default Preset to Basic
80
+ if (!args.some((a) => a.startsWith('--preset'))) {
81
+ args.push('--preset', 'basic');
81
82
  }
82
83
  args.push('--no-create-application');
83
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;
91
+ const exactO3rVersion = !!argv['exact-o3r-version'];
84
92
  if (argv._.length === 0) {
85
93
  // eslint-disable-next-line no-console
86
94
  console.error('The project name is mandatory');
@@ -100,8 +108,17 @@ const isNgNewOptions = (arg) => {
100
108
  }
101
109
  return true;
102
110
  };
111
+ const exitProcessIfErrorInSpawnSync = (exitCode, { error, status }) => {
112
+ if (error || status !== 0) {
113
+ if (error) {
114
+ // eslint-disable-next-line no-console
115
+ console.error(error);
116
+ }
117
+ process.exit(exitCode);
118
+ }
119
+ };
103
120
  const schematicsCliOptions = Object.entries(argv)
104
- .filter(([key]) => key !== '_')
121
+ .filter(([key]) => key !== '_' && !optionsList.includes(key))
105
122
  .map(([key, value]) => value === true && [key] || value === false && key.length > 1 && [`no-${key}`] || [key, value])
106
123
  .map(([key, value]) => {
107
124
  const optionKey = key.length > 1 ? `--${key}` : `-${key}`;
@@ -111,30 +128,77 @@ const createNgProject = () => {
111
128
  const options = schematicsCliOptions
112
129
  .filter(([key]) => isNgNewOptions(key))
113
130
  .flat();
114
- const { error } = (0, node_child_process_1.spawnSync)(process.execPath, [binPath, 'new', ...argv._, ...options, '--skip-install'], {
115
- stdio: 'inherit'
131
+ exitProcessIfErrorInSpawnSync(1, (0, node_child_process_1.spawnSync)(`"${process.execPath}"`, [binPath, 'new', ...argv._, ...options], {
132
+ stdio: 'inherit',
133
+ shell: true
134
+ }));
135
+ };
136
+ const prepareWorkspace = (relativeDirectory = '.', projectPackageManager = 'npm') => {
137
+ const cwd = (0, node_path_1.resolve)(process.cwd(), relativeDirectory);
138
+ const runner = process.platform === 'win32' ? `${projectPackageManager}.cmd` : projectPackageManager;
139
+ const mandatoryDependencies = [
140
+ '@angular-devkit/schematics',
141
+ '@schematics/angular',
142
+ '@angular-devkit/core',
143
+ '@angular-devkit/architect',
144
+ '@o3r/schematics'
145
+ ];
146
+ const packageJsonPath = (0, node_path_1.resolve)(cwd, 'package.json');
147
+ const packageJson = JSON.parse((0, node_fs_1.readFileSync)(packageJsonPath, { encoding: 'utf-8' })
148
+ // Replace the ^ with ~ to use the same minor version for angular packages as @angular/cli
149
+ .replace(/(@(?:angular|schematics).*)\^/g, '$1~'));
150
+ packageJson.devDependencies ||= {};
151
+ mandatoryDependencies.forEach((dep) => {
152
+ packageJson.devDependencies[dep] = dependencies?.[dep] || devDependencies?.[dep] || 'latest';
116
153
  });
117
- if (error) {
118
- // eslint-disable-next-line no-console
119
- console.error(error);
120
- process.exit(1);
154
+ if (exactO3rVersion) {
155
+ const o3rPackages = ['@o3r/core', '@o3r/schematics', '@o3r/workspace'];
156
+ const resolutions = {};
157
+ o3rPackages.forEach((pkg) => {
158
+ if (packageJson.devDependencies?.[pkg]) {
159
+ packageJson.devDependencies[pkg] = version;
160
+ }
161
+ resolutions[pkg] = version;
162
+ });
163
+ if (projectPackageManager === 'yarn') {
164
+ packageJson.resolutions = resolutions;
165
+ }
166
+ else {
167
+ packageJson.overrides = resolutions;
168
+ }
121
169
  }
170
+ (0, node_fs_1.writeFileSync)(packageJsonPath, JSON.stringify(packageJson, null, 2));
171
+ 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
+ }));
177
+ }
178
+ exitProcessIfErrorInSpawnSync(2, (0, node_child_process_1.spawnSync)(runner, ['install'], {
179
+ stdio: 'inherit',
180
+ shell: true,
181
+ cwd
182
+ }));
122
183
  };
123
- const addOtterFramework = (relativeDirectory = '.') => {
184
+ const addOtterFramework = (relativeDirectory = '.', projectPackageManager = 'npm') => {
124
185
  const cwd = (0, node_path_1.resolve)(process.cwd(), relativeDirectory);
186
+ const runner = process.platform === 'win32' ? `${projectPackageManager}.cmd` : projectPackageManager;
125
187
  const options = schematicsCliOptions
126
188
  .flat();
127
- const { error } = (0, node_child_process_1.spawnSync)(process.execPath, [binPath, 'add', `@o3r/core@${version || 'latest'}`, ...options], {
189
+ exitProcessIfErrorInSpawnSync(3, (0, node_child_process_1.spawnSync)(runner, ['exec', 'ng', 'add', `@o3r/core@${exactO3rVersion ? '' : '~'}${version}`, ...(projectPackageManager === 'npm' ? ['--'] : []), ...options], {
128
190
  stdio: 'inherit',
129
- cwd
130
- });
131
- if (error) {
132
- // eslint-disable-next-line no-console
133
- console.error(error);
134
- process.exit(2);
135
- }
191
+ cwd,
192
+ shell: true,
193
+ env: exactO3rVersion && projectPackageManager === 'npm' ? {
194
+ ...process.env,
195
+ // eslint-disable-next-line @typescript-eslint/naming-convention, camelcase
196
+ NPM_CONFIG_SAVE_EXACT: 'true'
197
+ } : undefined
198
+ }));
136
199
  };
137
200
  const projectFolder = argv._[0]?.replaceAll(' ', '-').toLowerCase() || '.';
138
201
  console.info(logo);
139
202
  createNgProject();
140
- addOtterFramework(projectFolder);
203
+ prepareWorkspace(projectFolder, packageManager);
204
+ addOtterFramework(projectFolder, packageManager);
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@o3r/create",
3
- "version": "11.0.0-next.0",
3
+ "version": "11.0.0-next.2",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
4
7
  "description": "Create a new Otter based application",
5
8
  "keywords": [
6
9
  "create",
@@ -15,46 +18,54 @@
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.3.0",
22
+ "@schematics/angular": "~17.3.0",
20
23
  "minimist": "^1.2.6",
21
- "tslib": "^2.5.3"
24
+ "tslib": "^2.6.2",
25
+ "type-fest": "^4.10.2"
22
26
  },
23
27
  "devDependencies": {
24
- "@angular-eslint/eslint-plugin": "~17.1.0",
25
- "@angular-eslint/eslint-plugin-template": "~17.1.0",
26
- "@nx/eslint": "~17.1.1",
27
- "@nx/eslint-plugin": "~17.1.1",
28
- "@nx/jest": "~17.1.1",
29
- "@nx/js": "~17.1.1",
30
- "@o3r/build-helpers": "^11.0.0-next.0",
31
- "@o3r/eslint-config-otter": "^11.0.0-next.0",
32
- "@o3r/eslint-plugin": "^11.0.0-next.0",
33
- "@o3r/test-helpers": "^11.0.0-next.0",
28
+ "@angular-devkit/architect": "~0.1703.0",
29
+ "@angular-devkit/core": "~17.3.0",
30
+ "@angular-devkit/schematics": "~17.3.0",
31
+ "@angular-eslint/eslint-plugin": "~17.3.0",
32
+ "@angular-eslint/eslint-plugin-template": "~17.3.0",
33
+ "@nx/eslint": "~18.3.0",
34
+ "@nx/eslint-plugin": "~18.3.0",
35
+ "@nx/jest": "~18.3.0",
36
+ "@nx/js": "~18.3.0",
37
+ "@o3r/build-helpers": "^11.0.0-next.2",
38
+ "@o3r/eslint-config-otter": "^11.0.0-next.2",
39
+ "@o3r/eslint-plugin": "^11.0.0-next.2",
40
+ "@o3r/schematics": "^11.0.0-next.2",
41
+ "@o3r/test-helpers": "^11.0.0-next.2",
42
+ "@stylistic/eslint-plugin-ts": "^1.5.4",
34
43
  "@types/jest": "~29.5.2",
35
44
  "@types/minimist": "^1.2.2",
36
45
  "@types/node": "^20.0.0",
37
- "@typescript-eslint/eslint-plugin": "6.11.0",
38
- "@typescript-eslint/parser": "^6.11.0",
46
+ "@typescript-eslint/eslint-plugin": "^7.2.0",
47
+ "@typescript-eslint/parser": "^7.2.0",
39
48
  "cpy-cli": "^5.0.0",
40
- "eslint": "^8.42.0",
41
- "eslint-import-resolver-node": "^0.3.4",
42
- "eslint-plugin-jest": "~27.6.0",
43
- "eslint-plugin-jsdoc": "~48.0.0",
49
+ "eslint": "^8.57.0",
50
+ "eslint-import-resolver-node": "^0.3.9",
51
+ "eslint-plugin-jest": "~27.9.0",
52
+ "eslint-plugin-jsdoc": "~48.2.1",
44
53
  "eslint-plugin-prefer-arrow": "~1.2.3",
45
- "eslint-plugin-unicorn": "^50.0.0",
54
+ "eslint-plugin-unicorn": "^51.0.1",
46
55
  "jest": "~29.7.0",
47
56
  "jest-junit": "~16.0.0",
48
57
  "jsonc-eslint-parser": "~2.4.0",
49
- "nx": "~17.1.1",
58
+ "nx": "~18.3.0",
50
59
  "rimraf": "^5.0.1",
51
60
  "rxjs": "^7.8.1",
52
- "ts-jest": "~29.1.1",
53
- "type-fest": "^4.3.1",
54
- "typescript": "~5.2.2"
61
+ "ts-jest": "~29.1.2",
62
+ "type-fest": "^4.10.2",
63
+ "typescript": "~5.4.2"
55
64
  },
56
65
  "engines": {
57
- "node": ">=18.0.0"
66
+ "node": ">=18.0.0",
67
+ "yarn": "<2.0.0",
68
+ "npm": "*"
58
69
  },
59
70
  "contributors": [
60
71
  {