Skip to content

Commit

Permalink
fix(sdk): call yarn set version at sdk creation (#1032)
Browse files Browse the repository at this point in the history
## Proposed change

<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that is required for this change. -->

## Related issues

- 🐛 Fixes #(issue)
- 🚀 Feature #(issue)

<!-- Please make sure to follow the contributing guidelines on
https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md -->
  • Loading branch information
matthieu-crouzet authored Nov 13, 2023
2 parents 0f510a0 + d563a2a commit 3bff15e
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions packages/@ama-sdk/create/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { spawnSync } from 'node:child_process';
import { execSync, spawnSync } from 'node:child_process';
import { dirname, join, resolve } from 'node:path';
import * as minimist from 'minimist';

Expand Down Expand Up @@ -46,18 +46,52 @@ if (packageManagerEnv && ['npm', 'yarn'].includes(packageManagerEnv)) {

const packageManager = argv['package-manager'] || defaultPackageManager;

const getYarnVersion = () => {
try {
return execSync('yarn --version', {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore'],
env: {
...process.env,
// NPM updater notifier will prevents the child process from closing until it timeout after 3 minutes.
// eslint-disable-next-line @typescript-eslint/naming-convention
NO_UPDATE_NOTIFIER: '1',
// eslint-disable-next-line @typescript-eslint/naming-convention
NPM_CONFIG_UPDATE_NOTIFIER: 'false'
}
}).trim();
} catch {
return 'latest';
}
};

const schematicArgs = [
argv.debug !== undefined ? `--debug=${argv.debug as string}` : '--debug=false', // schematics enable debug mode per default when using schematics with relative path
'--name', name,
'--package', pck,
'--package-manager', packageManager,
'--directory', targetDirectory,
...(argv['spec-path'] ? ['--spec-path', argv['spec-path']] : [])
];

const getSchematicStepInfo = (schematic: string) => ({
args: [binPath, schematic, ...schematicArgs]
});

const run = () => {
const schematicArgs = [
argv.debug !== undefined ? `--debug=${argv.debug as string}` : '--debug=false', // schematics enable debug mode per default when using schematics with relative path
'--name', name,
'--package', pck,
'--package-manager', packageManager,
'--directory', targetDirectory,
...(argv['spec-path'] ? ['--spec-path', argv['spec-path']] : [])

const steps: { args: string[]; cwd?: string }[] = [
getSchematicStepInfo(schematicsToRun[0]),
...(
packageManager === 'yarn'
? [{ args: ['yarn', 'set', 'version', getYarnVersion()], cwd: resolve(process.cwd(), targetDirectory)}]
: []
),
...schematicsToRun.slice(1).map(getSchematicStepInfo)
];

const errors = schematicsToRun
.map((schematic) => spawnSync(process.execPath, [binPath, schematic, ...schematicArgs], { stdio: 'inherit', cwd: process.cwd()}))
const errors = steps
.map((step) => spawnSync(process.execPath, step.args, { stdio: 'inherit', cwd: step.cwd || process.cwd() }))
.map(({error}) => error)
.filter((err) => !!err);

Expand Down

0 comments on commit 3bff15e

Please sign in to comment.