moontraze 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/moontraze.js +28 -0
- package/lib/uninstall.js +68 -0
- package/package.json +1 -1
package/bin/moontraze.js
CHANGED
|
@@ -6,6 +6,8 @@ const { login } = require('../lib/auth');
|
|
|
6
6
|
const { getConfig, setConfig, getProject, setProject, GLOBAL_FILE } = require('../lib/config');
|
|
7
7
|
const { deploy } = require('../lib/deploy');
|
|
8
8
|
const { selfUpdate, INSTALL_DIR } = require('../lib/selfUpdate');
|
|
9
|
+
const { uninstall } = require('../lib/uninstall');
|
|
10
|
+
const { MOONTRAZE_HOME } = require('../lib/paths');
|
|
9
11
|
|
|
10
12
|
const program = new Command();
|
|
11
13
|
|
|
@@ -106,6 +108,30 @@ program
|
|
|
106
108
|
}
|
|
107
109
|
});
|
|
108
110
|
|
|
111
|
+
// ---------- uninstall ----------
|
|
112
|
+
program
|
|
113
|
+
.command('uninstall')
|
|
114
|
+
.description('Remove Moontraze CLI and data from this system')
|
|
115
|
+
.option('-y, --yes', 'Confirm uninstall')
|
|
116
|
+
.action((opts) => {
|
|
117
|
+
if (!opts.yes) {
|
|
118
|
+
console.log(chalk.yellow('This will remove Moontraze CLI and local data from your system.'));
|
|
119
|
+
console.log(chalk.gray(` Target: ${MOONTRAZE_HOME}`));
|
|
120
|
+
console.log(chalk.gray(' Also removes old ~/.moontraze if present.'));
|
|
121
|
+
console.log(chalk.gray(' Global Moon CLI is NOT deleted.'));
|
|
122
|
+
console.log('');
|
|
123
|
+
console.log(chalk.cyan('Run: moon moontraze uninstall --yes'));
|
|
124
|
+
console.log(chalk.cyan(' or: npx moontraze uninstall --yes'));
|
|
125
|
+
process.exit(0);
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
uninstall({ yes: true });
|
|
129
|
+
} catch (e) {
|
|
130
|
+
console.error(chalk.red('Uninstall failed:'), e.message);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
109
135
|
// ---------- deploy ----------
|
|
110
136
|
async function runDeploy(opts) {
|
|
111
137
|
try {
|
|
@@ -151,9 +177,11 @@ Examples:
|
|
|
151
177
|
moon ${platformName} list
|
|
152
178
|
moon ${platformName} deploy --prod
|
|
153
179
|
moon ${platformName} update
|
|
180
|
+
moon ${platformName} uninstall --yes
|
|
154
181
|
moon ${platformName} --prod
|
|
155
182
|
npx moontraze login
|
|
156
183
|
npx moontraze deploy --prod
|
|
184
|
+
npx moontraze uninstall --yes
|
|
157
185
|
`
|
|
158
186
|
);
|
|
159
187
|
|
package/lib/uninstall.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const { MOONTRAZE_HOME, MOONTRAZE_CLI, MOON_HOME } = require('./paths');
|
|
6
|
+
|
|
7
|
+
const OLD_HOME = path.join(os.homedir(), '.moontraze');
|
|
8
|
+
|
|
9
|
+
function rmDir(dir) {
|
|
10
|
+
if (!fs.existsSync(dir)) return false;
|
|
11
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Moontraze platform uninstall
|
|
17
|
+
* - removes MOONTRAZE_HOME (cli + config/token)
|
|
18
|
+
* - removes old ~/.moontraze
|
|
19
|
+
* - removes "moontraze" entry from global Moon config (agar ho)
|
|
20
|
+
* Does NOT uninstall global Moon CLI
|
|
21
|
+
*/
|
|
22
|
+
function uninstall({ yes = false } = {}) {
|
|
23
|
+
console.log(chalk.cyan('Uninstalling Moontraze CLI...'));
|
|
24
|
+
console.log(chalk.gray(` Data dir: ${MOONTRAZE_HOME}`));
|
|
25
|
+
console.log(chalk.gray(` CLI dir: ${MOONTRAZE_CLI}`));
|
|
26
|
+
|
|
27
|
+
let removed = false;
|
|
28
|
+
|
|
29
|
+
if (rmDir(MOONTRAZE_HOME)) {
|
|
30
|
+
console.log(chalk.green(`✓ Removed ${MOONTRAZE_HOME}`));
|
|
31
|
+
removed = true;
|
|
32
|
+
}
|
|
33
|
+
if (rmDir(OLD_HOME)) {
|
|
34
|
+
console.log(chalk.green(`✓ Removed old ${OLD_HOME}`));
|
|
35
|
+
removed = true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// global moon config se moontraze platform entry hatao
|
|
39
|
+
const moonCfg = path.join(MOON_HOME, 'config.json');
|
|
40
|
+
if (fs.existsSync(moonCfg)) {
|
|
41
|
+
try {
|
|
42
|
+
const cfg = JSON.parse(fs.readFileSync(moonCfg, 'utf8'));
|
|
43
|
+
if (cfg.platforms && cfg.platforms.moontraze) {
|
|
44
|
+
delete cfg.platforms.moontraze;
|
|
45
|
+
if (cfg.defaultPlatform === 'moontraze') {
|
|
46
|
+
const keys = Object.keys(cfg.platforms);
|
|
47
|
+
cfg.defaultPlatform = keys.length ? keys[0] : null;
|
|
48
|
+
}
|
|
49
|
+
fs.writeFileSync(moonCfg, JSON.stringify(cfg, null, 2));
|
|
50
|
+
console.log(chalk.green('✓ Removed moontraze from global moon platforms'));
|
|
51
|
+
}
|
|
52
|
+
} catch (_) {}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!removed) {
|
|
56
|
+
console.log(chalk.yellow('Nothing found to remove (already uninstalled?).'));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
console.log('');
|
|
60
|
+
console.log(chalk.green('Moontraze uninstalled.'));
|
|
61
|
+
console.log(chalk.gray('Global Moon CLI is still installed (if present).'));
|
|
62
|
+
console.log(chalk.gray('Open a NEW terminal if needed.'));
|
|
63
|
+
console.log('');
|
|
64
|
+
|
|
65
|
+
return { removed };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = { uninstall };
|