-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (47 loc) · 1.83 KB
/
index.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
#!/usr/bin/env node
const { Command } = require('commander');
const { version } = require('./package.json');
const runConfigShow = require('./config');
const { runDoctor } = require('./doctor');
const runGenerator = require('./generator');
const axios = require('axios');
const semver = require('semver');
const program = new Command();
program
.option('-v, --version', 'output the current version and check for updates')
.action(async () => {
const chalk = await import('chalk');
if (program.opts().version) {
console.log('Version:', version);
try {
const { data } = await axios.get('https://registry.npmjs.org/dapp-shell');
const latestVersion = data['dist-tags'].latest;
if (semver.lt(version, latestVersion)) {
console.log(chalk.default.yellow(`A newer version of dapp-shell is available (${latestVersion}). Please consider upgrading.`));
} else {
console.log(chalk.default.green('🎉 You are using the latest version!'));
}
} catch (error) {
console.error('Failed to check for updates:', error);
}
}
});
const service = new Command('init')
.action(async (options) => {
const chalk = await import('chalk');
console.log(chalk.default.cyan('⭐️ Hi,welcome to create your app by dapp-shell'));
await runGenerator();
});
const doctor = new Command('doctor')
.action(async (options) => {
const chalk = await import('chalk');
console.log(chalk.default.cyan('🔍 Starting project validation...'));
runDoctor();
});
const configShow = new Command('config')
.action(async (options) => {
const chalk = await import('chalk');
console.log(chalk.default.cyan('🔍 Starting project validation...'));
runConfigShow();
});
program.addCommand(service).addCommand(doctor).addCommand(configShow).parse(process.argv);