( packageJson: PackageJSON, options: Options, )
| 75 | } |
| 76 | |
| 77 | export async function addScripts( |
| 78 | packageJson: PackageJSON, |
| 79 | options: Options, |
| 80 | ): Promise<boolean> { |
| 81 | let edits = false; |
| 82 | const pkgManager = getPkgManagerCommand(options.yarn); |
| 83 | const scripts: Bag<string> = { |
| 84 | lint: 'gts lint', |
| 85 | clean: 'gts clean', |
| 86 | compile: 'tsc', |
| 87 | fix: 'gts fix', |
| 88 | prepare: `${pkgManager} run compile`, |
| 89 | pretest: `${pkgManager} run compile`, |
| 90 | posttest: `${pkgManager} run lint`, |
| 91 | }; |
| 92 | |
| 93 | if (!packageJson.scripts) { |
| 94 | packageJson.scripts = {}; |
| 95 | } |
| 96 | |
| 97 | for (const script of Object.keys(scripts)) { |
| 98 | let install = true; |
| 99 | const existing = packageJson.scripts[script]; |
| 100 | const target = scripts[script]; |
| 101 | |
| 102 | if (existing !== target) { |
| 103 | if (existing) { |
| 104 | const message = |
| 105 | `package.json already has a script for ${chalk.bold(script)}:\n` + |
| 106 | `-${chalk.red(existing)}\n+${chalk.green(target)}`; |
| 107 | install = await query(message, 'Replace', false, options); |
| 108 | } |
| 109 | |
| 110 | if (install) { |
| 111 | packageJson.scripts[script] = scripts[script]; |
| 112 | edits = true; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | return edits; |
| 117 | } |
| 118 | |
| 119 | export async function addDependencies( |
| 120 | packageJson: PackageJSON, |
no test coverage detected
searching dependent graphs…