@makano/rew 1.2.31 → 1.2.33
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/lib/rew/functions/require.js +34 -12
- 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
|
};
|
@@ -3,6 +3,7 @@ const path = require('path');
|
|
3
3
|
|
4
4
|
module.exports.customRequire = function customRequire(modulePath, filePath) {
|
5
5
|
const resolvedPath = resolveModulePath(modulePath, filePath);
|
6
|
+
if(!resolvedPath) throw new Error('Module '+modulePath+' not found');
|
6
7
|
return require(resolvedPath);
|
7
8
|
};
|
8
9
|
|
@@ -20,19 +21,40 @@ function resolveModulePath(modulePath, filePath) {
|
|
20
21
|
if (fs.existsSync(fullPath + '.json')) {
|
21
22
|
return fullPath + '.json';
|
22
23
|
}
|
24
|
+
|
23
25
|
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
const indexPath = path.join(fullPath, 'index.js');
|
33
|
-
if (fs.existsSync(indexPath)) {
|
34
|
-
return indexPath;
|
35
|
-
}
|
26
|
+
return searchInPath(fullPath);
|
27
|
+
}
|
28
|
+
|
29
|
+
const rootPath = modulePath.split('/').shift();
|
30
|
+
const halfFullPath = path.join(basePath, rootPath);
|
31
|
+
if (fs.existsSync(halfFullPath) && fs.statSync(halfFullPath).isDirectory()) {
|
32
|
+
return searchInPath(halfFullPath, ['.'].concat(fullPath.split('/').slice(1)).join('/'));
|
36
33
|
}
|
37
34
|
}
|
38
35
|
}
|
36
|
+
|
37
|
+
function searchInPath(fullPath, exportses){
|
38
|
+
const packageJsonPath = path.join(fullPath, 'package.json');
|
39
|
+
if (fs.existsSync(packageJsonPath)) {
|
40
|
+
const packageJson = require(packageJsonPath);
|
41
|
+
let main = packageJson.main || 'index.js';
|
42
|
+
if(exportses){
|
43
|
+
if(packageJson.exports){
|
44
|
+
if(exportses in packageJson.exports) main = packageJson.exports[exportses];
|
45
|
+
}
|
46
|
+
}
|
47
|
+
if(typeof main == "object"){
|
48
|
+
if(Array.isArray(main)) main = main[0].require;
|
49
|
+
else main = main.require;
|
50
|
+
}
|
51
|
+
const mainPath = path.join(fullPath, main);
|
52
|
+
if (fs.existsSync(mainPath)) {
|
53
|
+
return mainPath;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
const indexPath = path.join(fullPath, 'index.js');
|
57
|
+
if (fs.existsSync(indexPath)) {
|
58
|
+
return indexPath;
|
59
|
+
}
|
60
|
+
}
|