ota-manager 1.0.6 → 1.0.7

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.
Files changed (2) hide show
  1. package/lib/ota-main.js +216 -214
  2. package/package.json +1 -1
package/lib/ota-main.js CHANGED
@@ -1,214 +1,216 @@
1
- import { execSync } from 'child_process';
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
4
- import fs from 'fs';
5
- import OTA_CONFIG from './ota-config.js';
6
- import { listConfigs, useConfig, registerConfig, testConnection } from './ota-manager.js';
7
-
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = path.dirname(__filename);
10
- const rootDir = process.cwd();
11
-
12
- const command = process.argv[2];
13
- const subArg = process.argv[3];
14
- const versionArg = process.argv[4];
15
-
16
- const TOOL_VERSION = '1.2.0';
17
-
18
- const scripts = {
19
- version: path.join(__dirname, 'ota-version.js'),
20
- deploy: path.join(__dirname, 'ota-deploy.js'),
21
- verify: path.join(__dirname, 'verify-dist.cjs'),
22
- security: path.join(__dirname, 'ota-security.js'),
23
- build: path.join(__dirname, 'ota-build.cjs'),
24
- };
25
-
26
- function showHelp() {
27
- console.log(`
28
- ╔════════════════════════════════════════════════════════════╗
29
- ║ OTA MANAGER ║
30
- ║ Version ${TOOL_VERSION} ║
31
- ╚════════════════════════════════════════════════════════════╝
32
-
33
- Usage: npx ota-manager <command> [sub-command] [version]
34
-
35
- Management Commands:
36
- list : Show all registered infrastructures.
37
- use <id> : Set default infrastructure (e.g., use gitlab).
38
- register <id> : Register or update infrastructure (e.g., register s3).
39
- verify : Verify active infrastructure connectivity.
40
- audit : Audit public token for security leaks.
41
- test : Run E2E simulation (Push & Read).
42
-
43
- Operational Commands:
44
- status : Check local vs remote version.
45
- deploy training : Deploy update to TRAINING channel.
46
- deploy live : Deploy update to LIVE channel.
47
-
48
- Active Infrastructure:
49
- Strategy : ${OTA_CONFIG.strategy.toUpperCase()}
50
- Repo : ${OTA_CONFIG[OTA_CONFIG.strategy]?.repo || 'Not Configured'}
51
- ──────────────────────────────────────────────────────────────
52
- `);
53
- }
54
-
55
- import readline from 'readline';
56
-
57
- function confirm(message) {
58
- return new Promise((resolve) => {
59
- const rl = readline.createInterface({
60
- input: process.stdin,
61
- output: process.stdout
62
- });
63
- rl.question(`\n⚠️ ${message} [y/N]: `, (answer) => {
64
- rl.close();
65
- resolve(answer.toLowerCase() === 'y');
66
- });
67
- });
68
- }
69
-
70
- async function run() {
71
- try {
72
- switch (command) {
73
- case 'list':
74
- await listConfigs();
75
- process.exit(0);
76
- break;
77
-
78
- case 'use':
79
- if (!subArg) {
80
- console.log('❌ Error: Please specify the infrastructure ID (e.g., use gitlab).');
81
- process.exit(1);
82
- }
83
- await useConfig(subArg);
84
- process.exit(0);
85
- break;
86
-
87
- case 'register':
88
- if (!subArg) {
89
- console.log('❌ Error: Please specify the ID (e.g., register gitlab).');
90
- process.exit(1);
91
- }
92
- await registerConfig(subArg);
93
- process.exit(0);
94
- break;
95
-
96
- case 'help':
97
- case '-h':
98
- case '--help':
99
- showHelp();
100
- process.exit(0);
101
- break;
102
-
103
- case '-v':
104
- case '--version':
105
- console.log(`OTA Manager v${TOOL_VERSION}`);
106
- process.exit(0);
107
- break;
108
-
109
- case 'status':
110
- case 'version':
111
- execSync(`node "${scripts.version}"`, { stdio: 'inherit' });
112
- process.exit(0);
113
- break;
114
-
115
- case 'verify':
116
- execSync(`node "${scripts.verify}"`, { stdio: 'inherit' });
117
- process.exit(0);
118
- break;
119
-
120
- case 'test':
121
- await testConnection();
122
- process.exit(0);
123
- break;
124
-
125
- case 'build':
126
- execSync(`node "${scripts.build}" ${subArg || ''}`, { stdio: 'inherit' });
127
- process.exit(0);
128
- break;
129
-
130
- case 'audit':
131
- case 'security-check':
132
- case 'security':
133
- execSync(`node "${scripts.security}"`, { stdio: 'inherit' });
134
- process.exit(0);
135
- break;
136
-
137
- case 'training':
138
- execSync(`node "${scripts.version}"`, { stdio: 'inherit' });
139
- execSync(`node "${scripts.verify}"`, { stdio: 'inherit' });
140
-
141
- console.log(`\n📋 DEPLOYMENT PLAN [TRAINING]`);
142
- console.log(`🔹 Infra : ${OTA_CONFIG.strategy.toUpperCase()}`);
143
- console.log(`🔹 Action : Build & Push to Training Channel`);
144
-
145
- if (await confirm('Proceed with TRAINING deployment?')) {
146
- execSync(`node "${scripts.deploy}" training ${subArg || ''}`, { stdio: 'inherit' });
147
- } else {
148
- console.log(' Deployment cancelled.');
149
- }
150
- process.exit(0);
151
- break;
152
-
153
- case 'live':
154
- execSync(`node "${scripts.version}"`, { stdio: 'inherit' });
155
- execSync(`node "${scripts.verify}"`, { stdio: 'inherit' });
156
-
157
- console.log(`\n🚨 WARNING: DEPLOYMENT KE LIVE [PRODUCTION]`);
158
- console.log(`🔹 Infra : ${OTA_CONFIG.strategy.toUpperCase()}`);
159
- console.log(`🔹 Action : Build & Push to LIVE Channel`);
160
-
161
- if (await confirm('ARE YOU SURE you want to deploy to LIVE?')) {
162
- execSync(`node "${scripts.deploy}" live ${subArg || ''}`, { stdio: 'inherit' });
163
- } else {
164
- console.log(' LIVE Deployment cancelled.');
165
- }
166
- process.exit(0);
167
- break;
168
-
169
- case '-d':
170
- case 'deploy':
171
- if (!subArg) {
172
- console.log('❌ Error: Mohon tentukan channel (e.g., deploy training atau deploy live).');
173
- process.exit(1);
174
- }
175
- const channel = subArg.toLowerCase();
176
- if (channel !== 'training' && channel !== 'live') {
177
- console.log(`❌ Error: Channel "${channel}" tidak dikenal. Gunakan 'training' atau 'live'.`);
178
- process.exit(1);
179
- }
180
-
181
- execSync(`node "${scripts.version}"`, { stdio: 'inherit' });
182
- execSync(`node "${scripts.verify}"`, { stdio: 'inherit' });
183
-
184
- if (channel === 'training') {
185
- console.log(`\n📋 DEPLOYMENT PLAN [TRAINING]`);
186
- console.log(`🔹 Infra : ${OTA_CONFIG.strategy.toUpperCase()}`);
187
- console.log(`🔹 Action : Build & Push to Training Channel`);
188
- } else {
189
- console.log(`\n🚨 WARNING: DEPLOYMENT KE LIVE [PRODUCTION]`);
190
- console.log(`🔹 Infra : ${OTA_CONFIG.strategy.toUpperCase()}`);
191
- console.log(`🔹 Action : Build & Push to LIVE Channel`);
192
- }
193
-
194
- if (await confirm(`Proceed with ${channel.toUpperCase()} deployment?`)) {
195
- execSync(`node "${scripts.deploy}" ${channel} ${versionArg || ''}`, { stdio: 'inherit' });
196
- } else {
197
- console.log(' Deployment cancelled.');
198
- }
199
- process.exit(0);
200
- break;
201
-
202
- default:
203
- console.log(`\n❓ Unknown command: "${command || ''}"`);
204
- showHelp();
205
- process.exit(0);
206
- break;
207
- }
208
- } catch (error) {
209
- console.log(`\n❌ Process stopped due to error or cancellation.`);
210
- process.exit(1);
211
- }
212
- }
213
-
214
- run();
1
+ import { execSync } from 'child_process';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import fs from 'fs';
5
+ import OTA_CONFIG from './ota-config.js';
6
+ import { listConfigs, useConfig, registerConfig, testConnection } from './ota-manager.js';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ const rootDir = process.cwd();
11
+
12
+ const command = process.argv[2];
13
+ const subArg = process.argv[3];
14
+ const versionArg = process.argv[4];
15
+
16
+ const packageJsonPath = path.join(__dirname, '..', 'package.json');
17
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
18
+ const TOOL_VERSION = pkg.version;
19
+
20
+ const scripts = {
21
+ version: path.join(__dirname, 'ota-version.js'),
22
+ deploy: path.join(__dirname, 'ota-deploy.js'),
23
+ verify: path.join(__dirname, 'verify-dist.cjs'),
24
+ security: path.join(__dirname, 'ota-security.js'),
25
+ build: path.join(__dirname, 'ota-build.cjs'),
26
+ };
27
+
28
+ function showHelp() {
29
+ console.log(`
30
+ ╔════════════════════════════════════════════════════════════╗
31
+ ║ OTA MANAGER ║
32
+ ║ Version ${TOOL_VERSION} ║
33
+ ╚════════════════════════════════════════════════════════════╝
34
+
35
+ Usage: npx ota-manager <command> [sub-command] [version]
36
+
37
+ Management Commands:
38
+ list : Show all registered infrastructures.
39
+ use <id> : Set default infrastructure (e.g., use gitlab).
40
+ register <id> : Register or update infrastructure (e.g., register s3).
41
+ verify : Verify active infrastructure connectivity.
42
+ audit : Audit public token for security leaks.
43
+ test : Run E2E simulation (Push & Read).
44
+
45
+ Operational Commands:
46
+ status : Check local vs remote version.
47
+ deploy training : Deploy update to TRAINING channel.
48
+ deploy live : Deploy update to LIVE channel.
49
+
50
+ Active Infrastructure:
51
+ Strategy : ${OTA_CONFIG.strategy.toUpperCase()}
52
+ Repo : ${OTA_CONFIG[OTA_CONFIG.strategy]?.repo || 'Not Configured'}
53
+ ──────────────────────────────────────────────────────────────
54
+ `);
55
+ }
56
+
57
+ import readline from 'readline';
58
+
59
+ function confirm(message) {
60
+ return new Promise((resolve) => {
61
+ const rl = readline.createInterface({
62
+ input: process.stdin,
63
+ output: process.stdout
64
+ });
65
+ rl.question(`\n⚠️ ${message} [y/N]: `, (answer) => {
66
+ rl.close();
67
+ resolve(answer.toLowerCase() === 'y');
68
+ });
69
+ });
70
+ }
71
+
72
+ async function run() {
73
+ try {
74
+ switch (command) {
75
+ case 'list':
76
+ await listConfigs();
77
+ process.exit(0);
78
+ break;
79
+
80
+ case 'use':
81
+ if (!subArg) {
82
+ console.log('❌ Error: Please specify the infrastructure ID (e.g., use gitlab).');
83
+ process.exit(1);
84
+ }
85
+ await useConfig(subArg);
86
+ process.exit(0);
87
+ break;
88
+
89
+ case 'register':
90
+ if (!subArg) {
91
+ console.log('❌ Error: Please specify the ID (e.g., register gitlab).');
92
+ process.exit(1);
93
+ }
94
+ await registerConfig(subArg);
95
+ process.exit(0);
96
+ break;
97
+
98
+ case 'help':
99
+ case '-h':
100
+ case '--help':
101
+ showHelp();
102
+ process.exit(0);
103
+ break;
104
+
105
+ case '-v':
106
+ case '--version':
107
+ console.log(`OTA Manager v${TOOL_VERSION}`);
108
+ process.exit(0);
109
+ break;
110
+
111
+ case 'status':
112
+ case 'version':
113
+ execSync(`node "${scripts.version}"`, { stdio: 'inherit' });
114
+ process.exit(0);
115
+ break;
116
+
117
+ case 'verify':
118
+ execSync(`node "${scripts.verify}"`, { stdio: 'inherit' });
119
+ process.exit(0);
120
+ break;
121
+
122
+ case 'test':
123
+ await testConnection();
124
+ process.exit(0);
125
+ break;
126
+
127
+ case 'build':
128
+ execSync(`node "${scripts.build}" ${subArg || ''}`, { stdio: 'inherit' });
129
+ process.exit(0);
130
+ break;
131
+
132
+ case 'audit':
133
+ case 'security-check':
134
+ case 'security':
135
+ execSync(`node "${scripts.security}"`, { stdio: 'inherit' });
136
+ process.exit(0);
137
+ break;
138
+
139
+ case 'training':
140
+ execSync(`node "${scripts.version}"`, { stdio: 'inherit' });
141
+ execSync(`node "${scripts.verify}"`, { stdio: 'inherit' });
142
+
143
+ console.log(`\n📋 DEPLOYMENT PLAN [TRAINING]`);
144
+ console.log(`🔹 Infra : ${OTA_CONFIG.strategy.toUpperCase()}`);
145
+ console.log(`🔹 Action : Build & Push to Training Channel`);
146
+
147
+ if (await confirm('Proceed with TRAINING deployment?')) {
148
+ execSync(`node "${scripts.deploy}" training ${subArg || ''}`, { stdio: 'inherit' });
149
+ } else {
150
+ console.log('❌ Deployment cancelled.');
151
+ }
152
+ process.exit(0);
153
+ break;
154
+
155
+ case 'live':
156
+ execSync(`node "${scripts.version}"`, { stdio: 'inherit' });
157
+ execSync(`node "${scripts.verify}"`, { stdio: 'inherit' });
158
+
159
+ console.log(`\n🚨 WARNING: DEPLOYMENT KE LIVE [PRODUCTION]`);
160
+ console.log(`🔹 Infra : ${OTA_CONFIG.strategy.toUpperCase()}`);
161
+ console.log(`🔹 Action : Build & Push to LIVE Channel`);
162
+
163
+ if (await confirm('ARE YOU SURE you want to deploy to LIVE?')) {
164
+ execSync(`node "${scripts.deploy}" live ${subArg || ''}`, { stdio: 'inherit' });
165
+ } else {
166
+ console.log('❌ LIVE Deployment cancelled.');
167
+ }
168
+ process.exit(0);
169
+ break;
170
+
171
+ case '-d':
172
+ case 'deploy':
173
+ if (!subArg) {
174
+ console.log('❌ Error: Mohon tentukan channel (e.g., deploy training atau deploy live).');
175
+ process.exit(1);
176
+ }
177
+ const channel = subArg.toLowerCase();
178
+ if (channel !== 'training' && channel !== 'live') {
179
+ console.log(`❌ Error: Channel "${channel}" tidak dikenal. Gunakan 'training' atau 'live'.`);
180
+ process.exit(1);
181
+ }
182
+
183
+ execSync(`node "${scripts.version}"`, { stdio: 'inherit' });
184
+ execSync(`node "${scripts.verify}"`, { stdio: 'inherit' });
185
+
186
+ if (channel === 'training') {
187
+ console.log(`\n📋 DEPLOYMENT PLAN [TRAINING]`);
188
+ console.log(`🔹 Infra : ${OTA_CONFIG.strategy.toUpperCase()}`);
189
+ console.log(`🔹 Action : Build & Push to Training Channel`);
190
+ } else {
191
+ console.log(`\n🚨 WARNING: DEPLOYMENT KE LIVE [PRODUCTION]`);
192
+ console.log(`🔹 Infra : ${OTA_CONFIG.strategy.toUpperCase()}`);
193
+ console.log(`🔹 Action : Build & Push to LIVE Channel`);
194
+ }
195
+
196
+ if (await confirm(`Proceed with ${channel.toUpperCase()} deployment?`)) {
197
+ execSync(`node "${scripts.deploy}" ${channel} ${versionArg || ''}`, { stdio: 'inherit' });
198
+ } else {
199
+ console.log('❌ Deployment cancelled.');
200
+ }
201
+ process.exit(0);
202
+ break;
203
+
204
+ default:
205
+ console.log(`\n❓ Unknown command: "${command || ''}"`);
206
+ showHelp();
207
+ process.exit(0);
208
+ break;
209
+ }
210
+ } catch (error) {
211
+ console.log(`\n❌ Process stopped due to error or cancellation.`);
212
+ process.exit(1);
213
+ }
214
+ }
215
+
216
+ run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ota-manager",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Multi-provider OTA update manager for Astro and static web projects.",
5
5
  "type": "module",
6
6
  "main": "index.js",