-
Notifications
You must be signed in to change notification settings - Fork 2
/
leanweb.js
executable file
·63 lines (51 loc) · 2.22 KB
/
leanweb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env node
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import { createRequire } from "module";
const require = createRequire(import.meta.url);
import fs from 'fs';
import semver from 'semver';
import * as utils from './commands/utils.js';
(async () => {
const args = process.argv;
if (args.length < 3) {
utils.exec('npx leanweb help');
return;
}
let target = args[2];
const targetCandidates = Object.keys(utils.targets).filter(t => t.startsWith(target));
if (targetCandidates.length === 0) {
console.error(`Error: target ${target} not found.`);
return;
} else if (targetCandidates.length > 1) {
targetCandidates.forEach(t => {
console.log(t);
});
return;
}
target = targetCandidates[0];
const leanwebJSONExisted = fs.existsSync(`${process.cwd()}/${utils.dirs.src}/leanweb.json`);
if (!leanwebJSONExisted && target !== 'init' && target !== 'help' && target !== 'version') {
console.error('Error: leanweb.json not found.');
return;
}
if (leanwebJSONExisted && target === 'version' || target === 'serve' || target === 'dist') {
const leanwebPackageJSON = require(`${__dirname}/package.json`);
const projectLeanwebJSON = require(`${process.cwd()}/${utils.dirs.src}/leanweb.json`);
const upgradeAvailable = semver.gt(leanwebPackageJSON.version, projectLeanwebJSON.version);
if (upgradeAvailable) {
console.log(`New version of leanweb lib (${projectLeanwebJSON.version} => ${leanwebPackageJSON.version}) is available. Please consider
running 'lw upgrade' to upgrade your project leanweb lib.`);
}
const projectTooNew = semver.gt(projectLeanwebJSON.version, leanwebPackageJSON.version);
if (projectTooNew) {
console.log(`Poject version of leanweb (${projectLeanwebJSON.version} > ${leanwebPackageJSON.version}) is newer than local leanweb tools version.
Please consider running 'npm i leanweb -g' to upgrade your local leanweb tools.`);
}
}
const targetData = utils.targets[target];
const command = `node --trace-deprecation ${__dirname}/commands/${targetData.file} ${args.slice(3).join(' ')}`;
utils.exec(command);
})();