@makano/rew 1.2.31 → 1.2.32
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/rew/cli/cli.js +10 -2
- package/lib/rew/cli/utils.js +28 -13
- package/package.json +1 -1
package/lib/rew/cli/cli.js
CHANGED
@@ -214,11 +214,19 @@ yargs(hideBin(process.argv))
|
|
214
214
|
alias: 'r',
|
215
215
|
describe: 'Install requirements of the app',
|
216
216
|
type: 'boolean',
|
217
|
+
}).option('update', {
|
218
|
+
alias: 'u',
|
219
|
+
describe: 'Update the app',
|
220
|
+
type: 'boolean',
|
221
|
+
}).option('yes', {
|
222
|
+
alias: 'y',
|
223
|
+
describe: 'Auto yes',
|
224
|
+
type: 'boolean',
|
217
225
|
});
|
218
226
|
},
|
219
227
|
async (argv) => {
|
220
|
-
if(argv.requirements) utils.installReq(argv.path);
|
221
|
-
else utils.installAppFrom(argv.path);
|
228
|
+
if(argv.requirements) utils.installReq(argv.path, argv);
|
229
|
+
else utils.installAppFrom(argv.path, argv);
|
222
230
|
},
|
223
231
|
)
|
224
232
|
.command(
|
package/lib/rew/cli/utils.js
CHANGED
@@ -16,6 +16,7 @@ const { watch } = require('chokidar');
|
|
16
16
|
const { execRewFile } = require('./run');
|
17
17
|
|
18
18
|
const binpath = path.join(conf({}).create('').root, '.bin');
|
19
|
+
const logspath = path.join(conf({}).create('').root, '.logs');
|
19
20
|
const localBinPath = path.join(binpath, '../../../', 'bin');
|
20
21
|
|
21
22
|
module.exports = {
|
@@ -176,7 +177,7 @@ module.exports = {
|
|
176
177
|
}
|
177
178
|
}
|
178
179
|
},
|
179
|
-
installApp(pathname, rmidir, rmidiri) {
|
180
|
+
installApp(pathname, opts, rmidir, rmidiri) {
|
180
181
|
if (!pathname) {
|
181
182
|
return;
|
182
183
|
}
|
@@ -197,8 +198,8 @@ module.exports = {
|
|
197
198
|
if (p.descriptiondescription) {
|
198
199
|
log(' Description'.blue + ': ' + p.description);
|
199
200
|
}
|
200
|
-
|
201
|
-
if (f.toLowerCase() == 'y') {
|
201
|
+
const done = (f) => {
|
202
|
+
if (f.toLowerCase() == 'y' || f.toLowerCase() == 'yes') {
|
202
203
|
if (fs.existsSync(installPath)) {
|
203
204
|
execSync(`rm -r ${installPath}`);
|
204
205
|
}
|
@@ -218,7 +219,13 @@ module.exports = {
|
|
218
219
|
}
|
219
220
|
if (c.install.commands) {
|
220
221
|
for (let command of c.install.commands) {
|
221
|
-
|
222
|
+
try{
|
223
|
+
execSync(command.replace(/\$installPath/g, installPath), { stdio: 'inherit' });
|
224
|
+
} catch(e){
|
225
|
+
const logFile = path.join(logspath, 'logs-'+Date.now()+'.log');
|
226
|
+
fs.writeFileSync(logFile, e.toString() +'\n'+ e.stack);
|
227
|
+
log(` Command Failed: ${command}, check logs at ${logFile}`, ':end');
|
228
|
+
}
|
222
229
|
}
|
223
230
|
}
|
224
231
|
if (c.install.file) {
|
@@ -250,12 +257,19 @@ module.exports = {
|
|
250
257
|
log(' Canceled install'.red.bold, ':end');
|
251
258
|
rl.close();
|
252
259
|
}
|
253
|
-
}
|
260
|
+
};
|
261
|
+
if (fs.existsSync(installPath) && !opts.update) {
|
262
|
+
rl.close();
|
263
|
+
log(` App Already Installed`.green.bold);
|
264
|
+
return log(` Run With --update or -u to update.`.green.bold, ':end');
|
265
|
+
}
|
266
|
+
if(opts.yes) done('y');
|
267
|
+
else rl.question(logget('Install '.blue + pname.green.bold + '? (y/N) '), done);
|
254
268
|
} else {
|
255
269
|
log(' Path is not a rew app'.red.bold, ':end');
|
256
270
|
}
|
257
271
|
},
|
258
|
-
installReq(config) {
|
272
|
+
installReq(config, opts) {
|
259
273
|
if (typeof config !== "object") {
|
260
274
|
const confPath = path.join(config, './app.yaml');
|
261
275
|
if (!fs.existsSync(confPath)) return log(' Path is not a rew app'.red.bold, ':end');
|
@@ -265,7 +279,7 @@ module.exports = {
|
|
265
279
|
if (!Array.isArray(config.install.requirements)) return log(' Requirements must be an array'.red.bold, ':end');
|
266
280
|
config.install.requirements.forEach(req => {
|
267
281
|
log('Finding '.cyan + req.green);
|
268
|
-
this.installAppFrom(req);
|
282
|
+
this.installAppFrom(req, opts);
|
269
283
|
});
|
270
284
|
}
|
271
285
|
},
|
@@ -362,10 +376,10 @@ module.exports = {
|
|
362
376
|
const repos = conf({}).create('').optionCenter('repos');
|
363
377
|
return repos.get(repo);
|
364
378
|
},
|
365
|
-
async installAppFrom(path) {
|
366
|
-
if (path.startsWith('github:')) this.installApp(await this.cloneGit(path), true, true);
|
367
|
-
else if (path.startsWith('@')) this.fromRepo(path);
|
368
|
-
else this.installApp(path);
|
379
|
+
async installAppFrom(path, opts) {
|
380
|
+
if (path.startsWith('github:')) this.installApp(await this.cloneGit(path), opts, true, true);
|
381
|
+
else if (path.startsWith('@')) this.fromRepo(path, opts);
|
382
|
+
else this.installApp(path, opts, null, null);
|
369
383
|
},
|
370
384
|
uninstall(packageName, all) {
|
371
385
|
const confPath = path.join(CONFIG_PATH, packageName);
|
@@ -409,7 +423,7 @@ module.exports = {
|
|
409
423
|
return {};
|
410
424
|
}
|
411
425
|
},
|
412
|
-
async fromRepo(repoAndPkg) {
|
426
|
+
async fromRepo(repoAndPkg, opts) {
|
413
427
|
const [repo, pkg] = repoAndPkg.slice(1).split('/');
|
414
428
|
const repoUrl = this.findRepo(repo);
|
415
429
|
if (!repoUrl) {
|
@@ -418,7 +432,7 @@ module.exports = {
|
|
418
432
|
} else {
|
419
433
|
const repoJson = await this.getRepoJson(repoUrl);
|
420
434
|
if (repoJson?.packages?.[pkg]) {
|
421
|
-
await this.installAppFrom(repoJson.packages[pkg]);
|
435
|
+
await this.installAppFrom(repoJson.packages[pkg], opts);
|
422
436
|
} else {
|
423
437
|
log(` Package "${pkg.cyan}" is not in repo "${repo.green}"`.red.bold, ":end");
|
424
438
|
}
|
@@ -457,5 +471,6 @@ module.exports = {
|
|
457
471
|
log('First time init')
|
458
472
|
conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
|
459
473
|
fs.mkdirSync(binpath, { recursive: true });
|
474
|
+
fs.mkdirSync(logspath, { recursive: true });
|
460
475
|
}
|
461
476
|
};
|