moontraze 1.0.8 → 1.0.9

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 CHANGED
@@ -4,6 +4,7 @@ const chalk = require('chalk');
4
4
  const { login } = require('../lib/auth');
5
5
  const { getConfig, setConfig, getProject, setProject } = require('../lib/config');
6
6
  const { deploy } = require('../lib/deploy');
7
+ const { selfUpdate } = require('../lib/selfUpdate');
7
8
 
8
9
  const program = new Command();
9
10
 
@@ -15,9 +16,9 @@ const domain = process.env.MOON_DOMAIN || getConfig().domain || 'moontraze.com';
15
16
  program
16
17
  .name(platformName)
17
18
  .description(`Deploy sites using ${platformName}`)
18
- .version('1.0.5');
19
+ .version('1.0.6');
19
20
 
20
- // login
21
+ // ---------- login ----------
21
22
  program
22
23
  .command('login')
23
24
  .description('Log in with email/password or token')
@@ -25,14 +26,14 @@ program
25
26
  .action(async (opts) => {
26
27
  try {
27
28
  await login(opts.token, { apiUrl });
28
- console.log(chalk.green(`✓ Logged in to ${platformName}`));
29
+ // auth.js already prints ✓ Logged in avoid double line if you want
29
30
  } catch (e) {
30
31
  console.error(chalk.red('Login failed:'), e.message);
31
32
  process.exit(1);
32
33
  }
33
34
  });
34
35
 
35
- // link
36
+ // ---------- link ----------
36
37
  program
37
38
  .command('link [name]')
38
39
  .description('Link this folder to a hosting project name')
@@ -63,7 +64,40 @@ program
63
64
  }
64
65
  });
65
66
 
66
- // deploy
67
+ // ---------- list ----------
68
+ program
69
+ .command('list')
70
+ .description('Show login + linked project status')
71
+ .action(() => {
72
+ const cfg = getConfig();
73
+ const proj = getProject();
74
+ console.log('');
75
+ console.log(chalk.bold('Moontraze'));
76
+ console.log(` API: ${cfg.apiUrl || apiUrl}`);
77
+ console.log(` Domain: ${cfg.domain || domain}`);
78
+ console.log(` Logged in: ${cfg.token ? 'yes' : 'no'}`);
79
+ console.log(
80
+ ` Linked project: ${
81
+ proj?.projectName || '(none — run: moon moontraze link <name>)'
82
+ }`
83
+ );
84
+ console.log('');
85
+ });
86
+
87
+ // ---------- update (own server tarball — no npm registry for code) ----------
88
+ program
89
+ .command('update')
90
+ .description('Download latest Moontraze CLI from api.moontraze.com')
91
+ .action(async () => {
92
+ try {
93
+ await selfUpdate();
94
+ } catch (e) {
95
+ console.error(chalk.red('Update failed:'), e.message);
96
+ process.exit(1);
97
+ }
98
+ });
99
+
100
+ // ---------- deploy ----------
67
101
  async function runDeploy(opts) {
68
102
  try {
69
103
  await deploy({
@@ -105,8 +139,13 @@ program.addHelpText(
105
139
  Examples:
106
140
  moon ${platformName} login
107
141
  moon ${platformName} link my-site
142
+ moon ${platformName} list
108
143
  moon ${platformName} deploy --prod
144
+ moon ${platformName} update
109
145
  moon ${platformName} --prod
146
+
147
+ npx moontraze login
148
+ npx moontraze deploy --prod
110
149
  `
111
150
  );
112
151
 
@@ -0,0 +1,152 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const os = require('os');
4
+ const { execSync } = require('child_process');
5
+ const fetch = require('node-fetch');
6
+ const chalk = require('chalk');
7
+
8
+ const API = process.env.MOON_API || 'https://api.moontraze.com';
9
+
10
+ // Moontraze platform ka apna install folder
11
+ const INSTALL_DIR = path.join(os.homedir(), '.moontraze', 'cli');
12
+ const MOON_CFG = path.join(os.homedir(), '.moon', 'config.json');
13
+
14
+ // ★ Sirf yahan change — moontraze ka apna manifest
15
+ async function fetchManifest() {
16
+ const res = await fetch(`${API}/cli/platforms/moontraze/manifest.json`);
17
+ if (!res.ok) {
18
+ throw new Error(`Could not fetch moontraze manifest (${res.status})`);
19
+ }
20
+ return res.json();
21
+ }
22
+
23
+ async function downloadTo(url, dest) {
24
+ const res = await fetch(url);
25
+ if (!res.ok) throw new Error('Download failed: ' + url);
26
+ const buf = Buffer.from(await res.arrayBuffer());
27
+ fs.writeFileSync(dest, buf);
28
+ }
29
+
30
+ function extractTarball(tgz, destDir) {
31
+ const tmp = path.join(os.tmpdir(), 'moontraze-extract-' + Date.now());
32
+ fs.mkdirSync(tmp, { recursive: true });
33
+
34
+ execSync(`tar -xzf "${tgz}" -C "${tmp}"`, { stdio: 'inherit', shell: true });
35
+
36
+ const entries = fs.readdirSync(tmp).map(n => path.join(tmp, n));
37
+ const pkg = entries.find(p => fs.statSync(p).isDirectory());
38
+
39
+ if (!pkg) {
40
+ console.error('Extracted contents:', entries);
41
+ throw new Error('Invalid tarball layout (expected package/ directory)');
42
+ }
43
+
44
+ if (fs.existsSync(destDir)) {
45
+ fs.rmSync(destDir, { recursive: true, force: true });
46
+ }
47
+ fs.mkdirSync(path.dirname(destDir), { recursive: true });
48
+ fs.renameSync(pkg, destDir);
49
+
50
+ fs.rmSync(tmp, { recursive: true, force: true });
51
+ }
52
+
53
+ function pointMoonPlatformToInstall() {
54
+ const pkgJsonPath = path.join(INSTALL_DIR, 'package.json');
55
+ if (!fs.existsSync(pkgJsonPath)) {
56
+ throw new Error('package.json missing after extract');
57
+ }
58
+
59
+ const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
60
+
61
+ // bin field se runner path nikaalo
62
+ let runnerRel = 'bin/moontraze.js';
63
+ if (pkg.bin) {
64
+ if (typeof pkg.bin === 'string') {
65
+ runnerRel = pkg.bin;
66
+ } else if (pkg.bin.moontraze) {
67
+ runnerRel = pkg.bin.moontraze;
68
+ } else {
69
+ const first = Object.values(pkg.bin)[0];
70
+ if (first) runnerRel = first;
71
+ }
72
+ }
73
+
74
+ const runner = path.join(INSTALL_DIR, runnerRel);
75
+
76
+ if (!fs.existsSync(runner)) {
77
+ console.error(chalk.red('\n--- Debug: files after extract ---'));
78
+ console.error('INSTALL_DIR:', INSTALL_DIR);
79
+ try {
80
+ console.error(fs.readdirSync(INSTALL_DIR));
81
+ const binDir = path.join(INSTALL_DIR, 'bin');
82
+ if (fs.existsSync(binDir)) {
83
+ console.error('bin/ →', fs.readdirSync(binDir));
84
+ }
85
+ } catch (_) {}
86
+ console.error('----------------------------------\n');
87
+ throw new Error('Runner missing after extract: ' + runner);
88
+ }
89
+
90
+ // moon global config update (sirf moontraze entry)
91
+ let cfg = { defaultPlatform: null, platforms: {} };
92
+ try {
93
+ if (fs.existsSync(MOON_CFG)) {
94
+ cfg = JSON.parse(fs.readFileSync(MOON_CFG, 'utf8'));
95
+ }
96
+ } catch (_) {}
97
+
98
+ if (!cfg.platforms) cfg.platforms = {};
99
+
100
+ cfg.platforms.moontraze = {
101
+ label: 'Moontraze',
102
+ runner,
103
+ apiUrl: API,
104
+ addedAt: new Date().toISOString(),
105
+ };
106
+
107
+ if (!cfg.defaultPlatform) {
108
+ cfg.defaultPlatform = 'moontraze';
109
+ }
110
+
111
+ fs.mkdirSync(path.dirname(MOON_CFG), { recursive: true });
112
+ fs.writeFileSync(MOON_CFG, JSON.stringify(cfg, null, 2));
113
+
114
+ return runner;
115
+ }
116
+
117
+ async function selfUpdate() {
118
+ console.log(chalk.cyan('Checking Moontraze CLI updates...'));
119
+
120
+ const manifest = await fetchManifest();
121
+ const ver = manifest.version;
122
+ const url = manifest.tarball;
123
+
124
+ console.log(chalk.gray(` Latest: v${ver}`));
125
+ console.log(chalk.gray(` ${url}`));
126
+
127
+ const tgz = path.join(os.tmpdir(), `moontraze-${ver}.tgz`);
128
+ await downloadTo(url, tgz);
129
+
130
+ console.log(chalk.cyan('Extracting...'));
131
+ extractTarball(tgz, INSTALL_DIR);
132
+
133
+ console.log(chalk.cyan('Installing dependencies...'));
134
+ execSync('npm install --omit=dev', {
135
+ cwd: INSTALL_DIR,
136
+ stdio: 'inherit',
137
+ shell: true,
138
+ });
139
+
140
+ const runner = pointMoonPlatformToInstall();
141
+
142
+ try { fs.unlinkSync(tgz); } catch (_) {}
143
+
144
+ console.log('');
145
+ console.log(chalk.green(`✓ Moontraze CLI v${ver} installed`));
146
+ console.log(chalk.gray(` ${INSTALL_DIR}`));
147
+ console.log(chalk.gray(` Runner: ${runner}`));
148
+ console.log(chalk.gray(' Try: moon moontraze list'));
149
+ console.log('');
150
+ }
151
+
152
+ module.exports = { selfUpdate, INSTALL_DIR };
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "moontraze",
3
- "version": "1.0.8",
4
- "description": "Deploy to Moontraze hosting — like vercel CLI",
3
+ "version": "1.0.9",
4
+ "description": "Deploy to Moontraze hosting",
5
5
  "bin": {
6
- "moon": "./bin/moon.js",
7
6
  "moontraze": "./bin/moontraze.js"
8
7
  },
9
8
  "files": [