@ama-sdk/create 11.0.0-next.0 → 11.0.0-next.1

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 +22 -5
  2. package/index.js +35 -29
  3. package/package.json +40 -31
package/README.md CHANGED
@@ -3,28 +3,45 @@
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/@ama-sdk/create?style=for-the-badge)](https://www.npmjs.com/package/@ama-sdk/create)
9
+ [![Bundle Size](https://img.shields.io/bundlephobia/min/@ama-sdk/create?color=green&style=for-the-badge)](https://www.npmjs.com/package/@ama-sdk/create)
10
+
11
+ This package is an [NPM initializer](https://docs.npmjs.com/cli/v8/commands/npm-init) to generate an API client SDK based on [OpenAPI specification](https://spec.openapis.org/oas/v3.1.0).
12
+
6
13
  ## Create an SDK package
7
14
 
8
15
  This package is simplifying the start of new SDK repository.
9
16
 
10
17
  ## Usage
11
18
 
12
- ### NPM
13
-
14
19
  ```shell
15
20
  npm create @ama-sdk typescript <package-name> -- [...options]
16
21
  ```
17
22
 
18
- ### Yarn
23
+ or
19
24
 
20
25
  ```shell
21
26
  yarn create @ama-sdk typescript <project-name> [...options]
22
27
  ```
23
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 @ama-sdk typescript <project-name> -- --package-manager=yarn [...options]
36
+ ```
37
+
24
38
  ## Options list
25
39
 
26
40
  - `--spec-path`: Path to the swagger/open-api specification used to generate the SDK
27
41
  - `--package-manager`: Node package manager to be used (`npm` and `yarn` are available).
28
- - `--debug`: Enable schematics debug mode (including dry run).
42
+ - `--debug --no-dry-run`: Enable schematics debug mode (dry-run is not currently supported).
43
+ - `--o3r-metrics`: Enable or disable the collection of anonymous data for Otter
44
+ - `--exact-o3r-version` : use a pinned version for [otter packages](https://github.com/AmadeusITGroup/otter/blob/main/docs/README.md).
29
45
 
30
- > **Note**: if the `--spec-path` is specified, the SDK will be generated based on this specification at the creation time.
46
+ > [!NOTE]
47
+ > If the `--spec-path` is specified, the SDK will be generated based on this specification at the creation time.
package/index.js CHANGED
@@ -1,43 +1,38 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ /* eslint-disable no-console */
3
4
  Object.defineProperty(exports, "__esModule", { value: true });
4
5
  const node_child_process_1 = require("node:child_process");
5
6
  const node_path_1 = require("node:path");
6
7
  const minimist = require("minimist");
7
- const defaultScope = 'sdk';
8
+ const packageManagerEnv = process.env.npm_config_user_agent?.split('/')[0];
8
9
  const binPath = (0, node_path_1.resolve)(require.resolve('@angular-devkit/schematics-cli/package.json'), '../bin/schematics.js');
9
10
  const args = process.argv.slice(2);
10
11
  const argv = minimist(args);
11
- const packageManagerEnv = process.env.npm_config_user_agent?.split('/')[0];
12
12
  let defaultPackageManager = 'npm';
13
13
  if (packageManagerEnv && ['npm', 'yarn'].includes(packageManagerEnv)) {
14
14
  defaultPackageManager = packageManagerEnv;
15
15
  }
16
16
  const packageManager = argv['package-manager'] || defaultPackageManager;
17
17
  if (argv._.length < 2) {
18
- // eslint-disable-next-line no-console
19
18
  console.error('The SDK type and project name are mandatory');
20
19
  console.info(`usage: ${packageManager} create @ama-sdk typescript <@scope/package>`);
21
20
  process.exit(-1);
22
21
  }
23
22
  const sdkType = argv._[0];
24
- let [name, pck] = argv._[1].replace(/^@/, '').split('/');
25
23
  if (sdkType !== 'typescript') {
26
- // eslint-disable-next-line no-console
27
24
  console.error('Only the generation of "typescript" SDK is available');
28
25
  process.exit(-2);
29
26
  }
30
- if (!pck) {
31
- console.warn(`The given package name, is not a scoped package. a default "@${defaultScope}" scope will be used`);
32
- pck = name;
33
- name = defaultScope;
27
+ const fullPackage = argv._[1];
28
+ const packageMatch = /^(?:@([^@/]+)\/)?([^@/]+)$/.exec(fullPackage);
29
+ if (!packageMatch) {
30
+ console.error('Invalid package name');
31
+ process.exit(-3);
34
32
  }
35
- const targetDirectory = (0, node_path_1.join)('.', name, pck);
33
+ const [, name, pck] = packageMatch;
34
+ const targetDirectory = name ? (0, node_path_1.join)('.', name, pck) : (0, node_path_1.join)('.', pck);
36
35
  const schematicsPackage = (0, node_path_1.dirname)(require.resolve('@ama-sdk/schematics/package.json'));
37
- const schematicsToRun = [
38
- `${schematicsPackage}:typescript-shell`,
39
- ...(argv['spec-path'] ? [`${schematicsPackage}:typescript-core`] : [])
40
- ];
41
36
  const getYarnVersion = () => {
42
37
  try {
43
38
  return (0, node_child_process_1.execSync)('yarn --version', {
@@ -58,31 +53,42 @@ const getYarnVersion = () => {
58
53
  }
59
54
  };
60
55
  const schematicArgs = [
61
- argv.debug !== undefined ? `--debug=${argv.debug}` : '--debug=false',
62
- '--name', name,
56
+ argv.debug !== undefined ? `--debug=${argv.debug}` : '--debug=false', // schematics enable debug mode per default when using schematics with relative path
57
+ ...(name ? ['--name', name] : []),
63
58
  '--package', pck,
64
59
  '--package-manager', packageManager,
65
- '--directory', targetDirectory,
66
- ...(argv['spec-path'] ? ['--spec-path', argv['spec-path']] : [])
60
+ ...(argv['exact-o3r-version'] ? ['--exact-o3r-version'] : []),
61
+ ...(typeof argv['dry-run'] !== 'undefined' ? [`--${!argv['dry-run'] || argv['dry-run'] === 'false' ? 'no-' : ''}dry-run`] : []),
62
+ ...(typeof argv['o3r-metrics'] !== 'undefined' ? [`--${!argv['o3r-metrics'] || argv['o3r-metrics'] === 'false' ? 'no-' : ''}o3r-metrics`] : [])
67
63
  ];
68
- const getSchematicStepInfo = (schematic) => ({
69
- args: [binPath, schematic, ...schematicArgs]
70
- });
64
+ const resolveTargetDirectory = (0, node_path_1.resolve)(process.cwd(), targetDirectory);
71
65
  const run = () => {
66
+ const isSpecRelativePath = !!argv['spec-path'] && !(0, node_path_1.parse)(argv['spec-path']).root;
67
+ const runner = process.platform === 'win32' ? `${packageManager}.cmd` : packageManager;
72
68
  const steps = [
73
- getSchematicStepInfo(schematicsToRun[0]),
69
+ { args: [binPath, `${schematicsPackage}:typescript-shell`, ...schematicArgs, '--directory', targetDirectory] },
74
70
  ...(packageManager === 'yarn'
75
- ? [{ args: ['yarn', 'set', 'version', getYarnVersion()], cwd: (0, node_path_1.resolve)(process.cwd(), targetDirectory) }]
71
+ ? [{ runner, args: ['set', 'version', getYarnVersion()], cwd: resolveTargetDirectory }]
76
72
  : []),
77
- ...schematicsToRun.slice(1).map(getSchematicStepInfo)
73
+ ...(argv['spec-path'] ? [{
74
+ args: [
75
+ binPath,
76
+ `${schematicsPackage}:typescript-core`,
77
+ ...schematicArgs,
78
+ '--spec-path', isSpecRelativePath ? (0, node_path_1.relative)(resolveTargetDirectory, (0, node_path_1.resolve)(process.cwd(), argv['spec-path'])) : argv['spec-path']
79
+ ],
80
+ cwd: resolveTargetDirectory
81
+ }] : [])
78
82
  ];
79
83
  const errors = steps
80
- .map((step) => (0, node_child_process_1.spawnSync)(process.execPath, step.args, { stdio: 'inherit', cwd: step.cwd || process.cwd() }))
81
- .map(({ error }) => error)
82
- .filter((err) => !!err);
84
+ .map((step) => (0, node_child_process_1.spawnSync)(step.runner || `"${process.execPath}"`, step.args, { stdio: 'inherit', cwd: step.cwd || process.cwd(), shell: true }))
85
+ .filter(({ error, status }) => (error || status !== 0));
83
86
  if (errors.length > 0) {
84
- // eslint-disable-next-line no-console
85
- errors.forEach((err) => console.error(err));
87
+ errors.forEach(({ error }) => {
88
+ if (error) {
89
+ console.error(error);
90
+ }
91
+ });
86
92
  process.exit(1);
87
93
  }
88
94
  };
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@ama-sdk/create",
3
- "version": "11.0.0-next.0",
3
+ "version": "11.0.0-next.1",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
4
7
  "description": "Create a new SDK",
5
8
  "keywords": [
6
9
  "create"
@@ -14,55 +17,61 @@
14
17
  "prepare:publish": "prepare-publish ./dist"
15
18
  },
16
19
  "dependencies": {
17
- "@ama-sdk/core": "^11.0.0-next.0",
18
- "@ama-sdk/schematics": "^11.0.0-next.0",
19
- "@angular-devkit/core": "~17.0.3",
20
- "@angular-devkit/schematics": "~17.0.3",
21
- "@angular-devkit/schematics-cli": "~17.0.3",
22
- "@openapitools/openapi-generator-cli": "~2.7.0",
23
- "@schematics/angular": "~17.0.3",
20
+ "@ama-sdk/core": "11.0.0-next.1",
21
+ "@ama-sdk/schematics": "11.0.0-next.1",
22
+ "@angular-devkit/core": "~17.3.0",
23
+ "@angular-devkit/schematics": "~17.3.0",
24
+ "@angular-devkit/schematics-cli": "~17.3.0",
25
+ "@angular/cli": "~17.3.0",
26
+ "@o3r/schematics": "11.0.0-next.1",
27
+ "@openapitools/openapi-generator-cli": "~2.13.0",
28
+ "@schematics/angular": "~17.3.0",
24
29
  "minimist": "^1.2.6",
25
- "typescript": "~5.2.2"
30
+ "rxjs": "^7.8.1",
31
+ "typescript": "~5.4.2"
26
32
  },
27
33
  "devDependencies": {
28
- "@angular-eslint/eslint-plugin": "~17.1.0",
29
- "@angular-eslint/eslint-plugin-template": "~17.1.0",
30
- "@nx/eslint": "~17.1.1",
31
- "@nx/eslint-plugin": "~17.1.1",
32
- "@nx/jest": "~17.1.1",
33
- "@nx/js": "~17.1.1",
34
- "@o3r/build-helpers": "^11.0.0-next.0",
35
- "@o3r/eslint-config-otter": "^11.0.0-next.0",
36
- "@o3r/eslint-plugin": "^11.0.0-next.0",
37
- "@o3r/test-helpers": "^11.0.0-next.0",
34
+ "@angular-eslint/eslint-plugin": "~17.3.0",
35
+ "@angular-eslint/eslint-plugin-template": "~17.3.0",
36
+ "@nx/eslint": "~18.3.0",
37
+ "@nx/eslint-plugin": "~18.3.0",
38
+ "@nx/jest": "~18.3.0",
39
+ "@nx/js": "~18.3.0",
40
+ "@o3r/build-helpers": "^11.0.0-next.1",
41
+ "@o3r/eslint-config-otter": "^11.0.0-next.1",
42
+ "@o3r/eslint-plugin": "^11.0.0-next.1",
43
+ "@o3r/test-helpers": "^11.0.0-next.1",
44
+ "@stylistic/eslint-plugin-ts": "^1.5.4",
38
45
  "@types/jest": "~29.5.2",
39
46
  "@types/minimist": "^1.2.2",
40
47
  "@types/node": "^20.0.0",
41
48
  "@types/pid-from-port": "^1.1.0",
42
49
  "@types/semver": "^7.3.13",
43
- "@typescript-eslint/eslint-plugin": "6.11.0",
44
- "@typescript-eslint/parser": "^6.11.0",
50
+ "@typescript-eslint/eslint-plugin": "^7.2.0",
51
+ "@typescript-eslint/parser": "^7.2.0",
45
52
  "cpy-cli": "^5.0.0",
46
- "eslint": "^8.42.0",
47
- "eslint-import-resolver-node": "^0.3.4",
48
- "eslint-plugin-jest": "~27.6.0",
49
- "eslint-plugin-jsdoc": "~48.0.0",
53
+ "eslint": "^8.57.0",
54
+ "eslint-import-resolver-node": "^0.3.9",
55
+ "eslint-plugin-jest": "~27.9.0",
56
+ "eslint-plugin-jsdoc": "~48.2.1",
50
57
  "eslint-plugin-prefer-arrow": "~1.2.3",
51
- "eslint-plugin-unicorn": "^50.0.0",
58
+ "eslint-plugin-unicorn": "^51.0.1",
52
59
  "jest": "~29.7.0",
53
60
  "jest-junit": "~16.0.0",
54
61
  "jsonc-eslint-parser": "~2.4.0",
55
- "nx": "~17.1.1",
62
+ "nx": "~18.3.0",
56
63
  "pid-from-port": "^1.1.3",
57
64
  "rimraf": "^5.0.1",
58
65
  "rxjs": "^7.8.1",
59
66
  "semver": "^7.5.2",
60
- "ts-jest": "~29.1.1",
61
- "tslib": "^2.5.3",
62
- "type-fest": "^4.3.1"
67
+ "ts-jest": "~29.1.2",
68
+ "tslib": "^2.6.2",
69
+ "type-fest": "^4.10.2"
63
70
  },
64
71
  "engines": {
65
- "node": ">=18.0.0"
72
+ "node": ">=18.0.0",
73
+ "yarn": "<2.0.0",
74
+ "npm": "*"
66
75
  },
67
76
  "contributors": [
68
77
  {