MCPcopy
hub / github.com/toeverything/AFFiNE / runScript

Method runScript

tools/cli/src/run.ts:105–165  ·  view source on GitHub ↗
(
    pkg: Package,
    scriptName: string,
    args: string[],
    opts: RunScriptOptions = {}
  )

Source from the content-addressed store, hash-verified

103 }
104
105 async runScript(
106 pkg: Package,
107 scriptName: string,
108 args: string[],
109 opts: RunScriptOptions = {}
110 ) {
111 const rawScript = pkg.scripts[scriptName];
112
113 if (!rawScript) {
114 if (opts.ignoreIfNotFound) {
115 return;
116 }
117
118 throw new Error(`Script ${scriptName} not found in ${pkg.name}`);
119 }
120
121 const rawArgs = [...rawScript.split(' '), ...args];
122
123 const { args: extractedArgs, envs } = this.extractEnvs(rawArgs);
124
125 args = extractedArgs;
126
127 if (opts.includeDependencies) {
128 const depsRun = Promise.all(
129 pkg.deps.map(dep => {
130 return this.runScript(
131 pkg.workspace.getPackage(dep.name),
132 scriptName,
133 [],
134 {
135 ...opts,
136 ignoreIfNotFound: true,
137 }
138 );
139 })
140 );
141
142 if (opts.waitDependencies) {
143 await depsRun;
144 } else {
145 depsRun.catch(e => {
146 this.logger.error(e);
147 });
148 }
149 }
150
151 const isAFFiNECommand = args[0] === 'affine';
152 if (isAFFiNECommand) {
153 // remove 'affine' from 'affine xxx' command
154 args.shift();
155 args.push('-p', pkg.name);
156
157 process.env = {
158 ...process.env,
159 ...envs,
160 };
161 await this.cli.run(args);
162 } else {

Callers 1

runMethod · 0.95

Calls 11

extractEnvsMethod · 0.95
runCommandMethod · 0.95
splitMethod · 0.80
mapMethod · 0.80
getPackageMethod · 0.80
catchMethod · 0.80
shiftMethod · 0.80
allMethod · 0.65
pushMethod · 0.65
runMethod · 0.65
errorMethod · 0.45

Tested by

no test coverage detected