MCPcopy
hub / github.com/google/gts / addScripts

Function addScripts

src/init.ts:77–117  ·  view source on GitHub ↗
(
  packageJson: PackageJSON,
  options: Options,
)

Source from the content-addressed store, hash-verified

75}
76
77export 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
119export async function addDependencies(
120 packageJson: PackageJSON,

Callers 1

initFunction · 0.85

Calls 2

getPkgManagerCommandFunction · 0.90
queryFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…