|
1 | 1 | const fs = require('fs'); |
2 | 2 | const path = require('path'); |
| 3 | +const packageJson = require('./package.json'); |
3 | 4 |
|
4 | 5 | const CT_PACKAGE_NAME = '@sand4rt/experimental-ct-angular'; |
| 6 | +const CT_PACKAGE_VERSION = packageJson.config.ctPackageVersion; |
| 7 | +const CT_PACKAGE_SPEC = `${CT_PACKAGE_NAME}@${CT_PACKAGE_VERSION}`; |
5 | 8 |
|
6 | 9 | function hasCtFlag(args) { |
7 | 10 | return args.includes('--ct'); |
@@ -46,16 +49,27 @@ function patchPackageJson(projectDir) { |
46 | 49 | const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); |
47 | 50 | packageJson.devDependencies ??= {}; |
48 | 51 | delete packageJson.devDependencies.undefined; |
49 | | - packageJson.devDependencies[CT_PACKAGE_NAME] = 'latest'; |
| 52 | + packageJson.devDependencies[CT_PACKAGE_NAME] = CT_PACKAGE_VERSION; |
50 | 53 |
|
51 | 54 | fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`); |
52 | 55 | return true; |
53 | 56 | } |
54 | 57 |
|
| 58 | +function installArgsForPackageManager(packageManager) { |
| 59 | + if (packageManager === 'pnpm') |
| 60 | + return ['add', '--save-dev', '--save-exact', CT_PACKAGE_SPEC]; |
| 61 | + if (packageManager === 'yarn') |
| 62 | + return ['add', '--dev', '--exact', CT_PACKAGE_SPEC]; |
| 63 | + return ['install', '--save-dev', '--save-exact', CT_PACKAGE_SPEC]; |
| 64 | +} |
| 65 | + |
55 | 66 | module.exports = { |
56 | 67 | CT_PACKAGE_NAME, |
| 68 | + CT_PACKAGE_VERSION, |
| 69 | + CT_PACKAGE_SPEC, |
57 | 70 | hasCtFlag, |
58 | 71 | targetDirFromArgs, |
59 | 72 | detectPackageManager, |
60 | 73 | patchPackageJson, |
| 74 | + installArgsForPackageManager, |
61 | 75 | }; |
0 commit comments