@codemoreira/esad 1.4.6-2 → 1.4.6-20
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/README.md +82 -96
- package/bin/esad.js +88 -88
- package/package.json +9 -8
- package/src/cli/commands/build.js +1 -7
- package/src/cli/commands/createCdn.js +44 -45
- package/src/cli/commands/deploy.js +112 -118
- package/src/cli/commands/dev.js +42 -82
- package/src/cli/commands/host.js +4 -4
- package/src/cli/utils/config.js +11 -37
- package/src/cli/utils/process.js +20 -20
- package/src/cli/utils/scaffold.js +96 -96
- package/src/client/index.js +69 -82
- package/src/plugin/index.js +15 -20
|
@@ -1,118 +1,112 @@
|
|
|
1
|
-
const fs = require('fs-extra');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const AdmZip = require('adm-zip');
|
|
4
|
-
const chalk = require('chalk');
|
|
5
|
-
const { getWorkspaceConfig
|
|
6
|
-
const { resolveModuleMetadata, listAvailableModules } = require('../utils/resolution');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
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
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
} catch (err) {
|
|
114
|
-
console.error(chalk.red(`❌ Error during upload: ${err.message}`));
|
|
115
|
-
} finally {
|
|
116
|
-
fs.unlinkSync(zipPath);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const AdmZip = require('adm-zip');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const { getWorkspaceConfig } = require('../utils/config');
|
|
6
|
+
const { resolveModuleMetadata, listAvailableModules } = require('../utils/resolution');
|
|
7
|
+
|
|
8
|
+
module.exports = async (options) => {
|
|
9
|
+
let cwd = process.cwd();
|
|
10
|
+
let pkgPath = path.join(cwd, 'package.json');
|
|
11
|
+
|
|
12
|
+
// Enforce Workspace Root
|
|
13
|
+
const configObj = getWorkspaceConfig();
|
|
14
|
+
if (!configObj) {
|
|
15
|
+
console.error(chalk.red(`❌ Error: Call this command from the project root (esad.config.json not found).`));
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const workspaceRoot = path.dirname(configObj.path);
|
|
20
|
+
const { projectName } = configObj.data;
|
|
21
|
+
|
|
22
|
+
let moduleId = options.id;
|
|
23
|
+
|
|
24
|
+
if (moduleId) {
|
|
25
|
+
const meta = resolveModuleMetadata(moduleId, configObj);
|
|
26
|
+
if (!meta) {
|
|
27
|
+
console.error(chalk.red(`\n❌ Error: Module not found: ${moduleId}`));
|
|
28
|
+
listAvailableModules(configObj);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
cwd = meta.path;
|
|
32
|
+
moduleId = meta.id; // Correct fully qualified ID
|
|
33
|
+
pkgPath = path.join(cwd, 'package.json');
|
|
34
|
+
console.log(`📂 Module detected for Deploy: ${path.basename(cwd)}`);
|
|
35
|
+
} else {
|
|
36
|
+
// Target host by default if in root
|
|
37
|
+
const hostDir = path.join(workspaceRoot, `${projectName}-host`);
|
|
38
|
+
if (fs.existsSync(hostDir)) {
|
|
39
|
+
cwd = hostDir;
|
|
40
|
+
pkgPath = path.join(cwd, 'package.json');
|
|
41
|
+
console.log(chalk.green(`📂 Host detected for Deploy: ${path.basename(cwd)}`));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!fs.existsSync(pkgPath)) {
|
|
46
|
+
console.error(chalk.red(`❌ Error: package.json not found in ${cwd}.`));
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const pkg = fs.readJsonSync(pkgPath);
|
|
51
|
+
moduleId = moduleId || pkg.name;
|
|
52
|
+
const version = options.version || pkg.version;
|
|
53
|
+
const entry = options.entry || 'index.bundle';
|
|
54
|
+
|
|
55
|
+
console.log(`\n☁️ Starting ESAD Deploy for ${moduleId} (v${version})\n`);
|
|
56
|
+
|
|
57
|
+
const config = configObj ? configObj.data : null;
|
|
58
|
+
if (!config?.deployEndpoint) {
|
|
59
|
+
console.error(`❌ Error: 'deployEndpoint' not configured in esad.config.json.`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const deployUrl = config.deployEndpoint.replace('{{moduleId}}', moduleId);
|
|
64
|
+
console.log(`📡 Deployment Endpoint Resolved: ${deployUrl}`);
|
|
65
|
+
|
|
66
|
+
const distPath = path.join(cwd, 'build');
|
|
67
|
+
if (!fs.existsSync(distPath)) {
|
|
68
|
+
console.error(`❌ Error: build/ directory not found in ${cwd}. Did you run the build command?`);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const zip = new AdmZip();
|
|
73
|
+
zip.addLocalFolder(distPath);
|
|
74
|
+
|
|
75
|
+
const zipPath = path.join(cwd, `bundle-${moduleId}-${version}.zip`);
|
|
76
|
+
zip.writeZip(zipPath);
|
|
77
|
+
console.log(`🗜️ Zipped output to ${zipPath}`);
|
|
78
|
+
|
|
79
|
+
console.log(`🚀 Uploading to CDN via multipart POST...`);
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const FormData = require('form-data'); // Standard in Node versions, or use native if available
|
|
83
|
+
const form = new FormData();
|
|
84
|
+
form.append('version', version);
|
|
85
|
+
form.append('bundle', fs.createReadStream(zipPath));
|
|
86
|
+
|
|
87
|
+
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
|
88
|
+
|
|
89
|
+
// Simple CDN expects POST /api/admin/assets/:id/versions
|
|
90
|
+
const uploadUrl = deployUrl.includes('/versions') ? deployUrl : `${deployUrl}/versions`;
|
|
91
|
+
|
|
92
|
+
const response = await fetch(uploadUrl, {
|
|
93
|
+
method: 'POST',
|
|
94
|
+
body: form,
|
|
95
|
+
headers: form.getHeaders(),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (response.ok) {
|
|
99
|
+
const result = await response.json();
|
|
100
|
+
console.log(chalk.green(`✅ Successfully uploaded ${moduleId} v${version} to CDN!`));
|
|
101
|
+
console.log(`📄 Active Version is now: ${result.active_version}`);
|
|
102
|
+
} else {
|
|
103
|
+
const errorText = await response.text();
|
|
104
|
+
console.error(chalk.red(`❌ Failed to upload: ${response.status} ${response.statusText}`));
|
|
105
|
+
console.error(errorText);
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
console.error(chalk.red(`❌ Error during upload: ${err.message}`));
|
|
109
|
+
} finally {
|
|
110
|
+
fs.unlinkSync(zipPath);
|
|
111
|
+
}
|
|
112
|
+
};
|
package/src/cli/commands/dev.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
const { spawn } = require('cross-spawn');
|
|
2
|
-
const { getWorkspaceConfig
|
|
2
|
+
const { getWorkspaceConfig } = require('../utils/config');
|
|
3
3
|
const fs = require('fs-extra');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const chalk = require('chalk');
|
|
6
|
-
const { resolveModuleMetadata, listAvailableModules, resolveProjectDir } = require('../utils/resolution');
|
|
7
|
-
const { runProcess } = require('../utils/process');
|
|
8
6
|
const { prepareNative } = require('../utils/scaffold');
|
|
9
|
-
const
|
|
7
|
+
const { resolveProjectDir, listAvailableModules } = require('../utils/resolution');
|
|
10
8
|
|
|
11
9
|
module.exports = async (options) => {
|
|
12
10
|
let cwd = process.cwd();
|
|
@@ -22,108 +20,70 @@ module.exports = async (options) => {
|
|
|
22
20
|
const workspaceRoot = path.dirname(configObj.path);
|
|
23
21
|
const { projectName } = configObj.data;
|
|
24
22
|
|
|
25
|
-
// Synchronize Host Config
|
|
26
|
-
syncHostConfig(configObj);
|
|
27
|
-
|
|
28
23
|
if (options.id) {
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
24
|
+
const targetDir = resolveProjectDir(options.id, configObj);
|
|
25
|
+
if (!targetDir) {
|
|
31
26
|
console.error(chalk.red(`\n❌ Error: Module not found: ${options.id}`));
|
|
32
27
|
listAvailableModules(configObj);
|
|
33
28
|
process.exit(1);
|
|
34
29
|
}
|
|
35
|
-
cwd =
|
|
36
|
-
moduleId = metadata.id;
|
|
30
|
+
cwd = targetDir;
|
|
37
31
|
pkgPath = path.join(cwd, 'package.json');
|
|
38
|
-
console.log(chalk.green(`📂 Module detected: ${path.relative(workspaceRoot, cwd)}
|
|
32
|
+
console.log(chalk.green(`📂 Module detected: ${path.relative(workspaceRoot, cwd)}`));
|
|
39
33
|
} else {
|
|
40
34
|
// Target host by default if in root
|
|
41
35
|
const hostDir = path.join(workspaceRoot, `${projectName}-host`);
|
|
42
36
|
if (fs.existsSync(hostDir)) {
|
|
43
37
|
cwd = hostDir;
|
|
44
|
-
moduleId = pkg.name; // Fallback to package name if in host
|
|
45
38
|
pkgPath = path.join(cwd, 'package.json');
|
|
46
39
|
console.log(chalk.green(`📂 Host detected: ${path.relative(workspaceRoot, cwd)}`));
|
|
47
40
|
}
|
|
48
41
|
}
|
|
49
42
|
|
|
50
|
-
if (!fs.existsSync(pkgPath)) {
|
|
51
|
-
console.error(chalk.red(`❌ Error: package.json not found in ${cwd}.`));
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
43
|
const pkg = fs.readJsonSync(pkgPath);
|
|
56
|
-
|
|
57
|
-
const
|
|
44
|
+
const moduleId = options.id || pkg.name;
|
|
45
|
+
const port = options.port || '8081';
|
|
58
46
|
|
|
59
|
-
|
|
47
|
+
// Determine if it's a Host or Module
|
|
48
|
+
const isHost = pkg.name.endsWith('-host') || pkg.dependencies?.['@callstack/repack'];
|
|
60
49
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!devUrlBase) {
|
|
65
|
-
console.error(chalk.red(`❌ Error: 'devModeEndpoint' or 'deployEndpoint' not configured in esad.config.json.`));
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
50
|
+
// 1. Initial Checks & Automated Native Preparation
|
|
51
|
+
await prepareNative(cwd, 'all');
|
|
68
52
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
53
|
+
if (isHost && !options.id) {
|
|
54
|
+
console.log(`\n🚀 Starting Host App Dev Server (Re.Pack/Rspack)...\n`);
|
|
55
|
+
await spawn('npx', ['react-native', 'webpack-start'], { cwd, stdio: 'inherit', shell: true });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
74
58
|
|
|
75
|
-
|
|
76
|
-
console.log(`\n🏗️ Step 1/3: Building bundle...`);
|
|
77
|
-
const bundleOutput = path.join(cwd, 'build', platform, 'index.bundle');
|
|
78
|
-
await fs.ensureDir(path.dirname(bundleOutput));
|
|
59
|
+
console.log(`\n⚡ Starting ESAD Dev Server for ${moduleId} on port ${port}...\n`);
|
|
79
60
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
'react-native',
|
|
83
|
-
'webpack-bundle',
|
|
84
|
-
'--platform', platform,
|
|
85
|
-
'--dev', 'false',
|
|
86
|
-
'--bundle-output', bundleOutput,
|
|
87
|
-
'--assets-dest', path.dirname(bundleOutput)
|
|
88
|
-
], cwd);
|
|
89
|
-
} catch (err) {
|
|
90
|
-
console.error(chalk.red(`❌ Build failed.`));
|
|
91
|
-
process.exit(1);
|
|
92
|
-
}
|
|
61
|
+
const config = configObj ? configObj.data : null;
|
|
62
|
+
let devApiUrl = config?.devModeEndpoint ? config.devModeEndpoint.replace('{{moduleId}}', moduleId) : null;
|
|
93
63
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
64
|
+
const setDevMode = async (isActive) => {
|
|
65
|
+
if (!devApiUrl) return;
|
|
66
|
+
try {
|
|
67
|
+
const body = {
|
|
68
|
+
is_dev_mode: isActive,
|
|
69
|
+
...(isActive && { dev_url: `http://localhost:${port}/index.bundle` })
|
|
70
|
+
};
|
|
71
|
+
const res = await fetch(devApiUrl, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
72
|
+
if (res.ok) console.log(`📡 Registry Sync: Dev Override is ${isActive ? 'ON' : 'OFF'} for module ${moduleId}`);
|
|
73
|
+
} catch(e) { /* ignore */ }
|
|
74
|
+
};
|
|
101
75
|
|
|
102
|
-
|
|
103
|
-
console.log(`\n🚀 Step 3/3: Pushing to Dev-Cloud...`);
|
|
104
|
-
try {
|
|
105
|
-
const FormData = require('form-data');
|
|
106
|
-
const form = new FormData();
|
|
107
|
-
form.append('bundle', fs.createReadStream(zipPath));
|
|
76
|
+
await setDevMode(true);
|
|
108
77
|
|
|
109
|
-
|
|
110
|
-
const response = await fetch(devUploadUrl, {
|
|
111
|
-
method: 'POST',
|
|
112
|
-
body: form,
|
|
113
|
-
headers: form.getHeaders(),
|
|
114
|
-
});
|
|
78
|
+
const proc = spawn('npx', ['react-native', 'webpack-start', '--port', port], { cwd, stdio: 'inherit', shell: true });
|
|
115
79
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
console.error(chalk.red(`❌ Error during sync: ${err.message}`));
|
|
126
|
-
} finally {
|
|
127
|
-
if (fs.existsSync(zipPath)) fs.unlinkSync(zipPath);
|
|
128
|
-
}
|
|
80
|
+
const shutdown = async () => {
|
|
81
|
+
console.log(`\n🛑 Stopping ESAD Dev Server and reverting registry status...`);
|
|
82
|
+
await setDevMode(false);
|
|
83
|
+
proc.kill();
|
|
84
|
+
process.exit(0);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
process.on('SIGINT', shutdown);
|
|
88
|
+
process.on('SIGTERM', shutdown);
|
|
129
89
|
};
|
package/src/cli/commands/host.js
CHANGED
|
@@ -122,10 +122,10 @@ module.exports = async (subcommand) => {
|
|
|
122
122
|
// 6. Launch Native App
|
|
123
123
|
if (choice === 'a') {
|
|
124
124
|
console.log(`🤖 Compiling and launching on Android...`);
|
|
125
|
-
await runProcess('npx', ['
|
|
125
|
+
await runProcess('npx', ['react-native', 'run-android', '--no-packager'], cwd);
|
|
126
126
|
} else if (choice === 'i') {
|
|
127
127
|
console.log(`🍎 Compiling and launching on iOS...`);
|
|
128
|
-
await runProcess('npx', ['
|
|
128
|
+
await runProcess('npx', ['react-native', 'run-ios', '--no-packager'], cwd);
|
|
129
129
|
} else if (choice === 'b') {
|
|
130
130
|
if (portBusy) {
|
|
131
131
|
console.log(`✨ Bundler is already active. You can launch manual native runs.`);
|
|
@@ -139,9 +139,9 @@ module.exports = async (subcommand) => {
|
|
|
139
139
|
// Other subcommands (android, ios directly)
|
|
140
140
|
try {
|
|
141
141
|
if (subcommand === 'android') {
|
|
142
|
-
await runProcess('npx', ['
|
|
142
|
+
await runProcess('npx', ['react-native', 'run-android', '--no-packager'], cwd);
|
|
143
143
|
} else if (subcommand === 'ios') {
|
|
144
|
-
await runProcess('npx', ['
|
|
144
|
+
await runProcess('npx', ['react-native', 'run-ios', '--no-packager'], cwd);
|
|
145
145
|
}
|
|
146
146
|
} catch (err) {
|
|
147
147
|
console.error(`❌ Error running host command: ${err.message}`);
|
package/src/cli/utils/config.js
CHANGED
|
@@ -1,37 +1,11 @@
|
|
|
1
|
-
const fs = require('fs-extra');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const getWorkspaceConfig = () => {
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!fs.existsSync(configPath)) return null;
|
|
13
|
-
return { path: configPath, data: fs.readJsonSync(configPath) };
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const syncHostConfig = (configObj) => {
|
|
17
|
-
if (!configObj) return;
|
|
18
|
-
const { projectName } = configObj.data;
|
|
19
|
-
const workspaceRoot = path.dirname(configObj.path);
|
|
20
|
-
const hostDir = path.join(workspaceRoot, `${projectName}-host`);
|
|
21
|
-
|
|
22
|
-
if (fs.existsSync(hostDir)) {
|
|
23
|
-
const hostConfigPath = path.join(hostDir, 'esad.config.json');
|
|
24
|
-
|
|
25
|
-
// Only pass client-safe fields
|
|
26
|
-
const clientConfig = {
|
|
27
|
-
projectName: configObj.data.projectName,
|
|
28
|
-
registryUrl: configObj.data.registryUrl,
|
|
29
|
-
devModeFor: configObj.data.devModeFor || []
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
fs.writeJsonSync(hostConfigPath, clientConfig, { spaces: 2 });
|
|
33
|
-
console.log(`\n🔄 Sync: Config propagated to ${path.relative(workspaceRoot, hostConfigPath)}`);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
module.exports = { getWorkspaceConfig, syncHostConfig };
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const getWorkspaceConfig = () => {
|
|
5
|
+
let configPath = path.join(process.cwd(), 'esad.config.json');
|
|
6
|
+
if (!fs.existsSync(configPath)) configPath = path.join(process.cwd(), '../esad.config.json');
|
|
7
|
+
if (!fs.existsSync(configPath)) return null;
|
|
8
|
+
return { path: configPath, data: fs.readJsonSync(configPath) };
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
module.exports = { getWorkspaceConfig };
|
package/src/cli/utils/process.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const { spawn } = require('cross-spawn');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Helper to spawn commands synchronously
|
|
5
|
-
* @param {string} cmd
|
|
6
|
-
* @param {string[]} args
|
|
7
|
-
* @param {string} cwd
|
|
8
|
-
* @returns {Promise<void>}
|
|
9
|
-
*/
|
|
10
|
-
const runProcess = (cmd, args, cwd = process.cwd()) => {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
const child = spawn(cmd, args, { stdio: 'inherit', cwd, shell: true });
|
|
13
|
-
child.on('close', code => {
|
|
14
|
-
if (code !== 0) reject(new Error(`Command ${cmd} ${args.join(' ')} failed`));
|
|
15
|
-
else resolve();
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
module.exports = { runProcess };
|
|
1
|
+
const { spawn } = require('cross-spawn');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Helper to spawn commands synchronously
|
|
5
|
+
* @param {string} cmd
|
|
6
|
+
* @param {string[]} args
|
|
7
|
+
* @param {string} cwd
|
|
8
|
+
* @returns {Promise<void>}
|
|
9
|
+
*/
|
|
10
|
+
const runProcess = (cmd, args, cwd = process.cwd()) => {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const child = spawn(cmd, args, { stdio: 'inherit', cwd, shell: true });
|
|
13
|
+
child.on('close', code => {
|
|
14
|
+
if (code !== 0) reject(new Error(`Command ${cmd} ${args.join(' ')} failed`));
|
|
15
|
+
else resolve();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports = { runProcess };
|