cloud-ide-cide 2.0.34
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/buildAllProjects.js +131 -0
- package/buildProject.js +209 -0
- package/buildWorkspace.js +225 -0
- package/cideShell.js +1292 -0
- package/cli.js +521 -0
- package/createProject.js +71 -0
- package/deployer/node/upload-api.js +265 -0
- package/deployer/php/setup.php +332 -0
- package/deployer/php/upload-ui.php +294 -0
- package/package.json +53 -0
- package/publishPackage.js +969 -0
- package/resolveNgProjectName.js +94 -0
- package/serverInit.js +665 -0
- package/startProject.js +57 -0
- package/uploadProject.js +727 -0
- package/watchLinkProject.js +40 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const { execSync } = require('child_process');
|
|
2
|
+
const { readFileSync, existsSync } = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Build all Cloud IDE projects
|
|
7
|
+
* This function reads package.json scripts and runs all build-<project> commands
|
|
8
|
+
* excluding the main 'build' command
|
|
9
|
+
*
|
|
10
|
+
* @param {boolean} shouldInstall - Whether to install packages after building
|
|
11
|
+
*/
|
|
12
|
+
async function buildAllProjects(shouldInstall = false) {
|
|
13
|
+
console.log('š Building all Cloud IDE projects...\n');
|
|
14
|
+
|
|
15
|
+
// Store the original working directory
|
|
16
|
+
const originalCwd = process.cwd();
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
// Read package.json to get all build scripts
|
|
20
|
+
const packageJsonPath = path.join(originalCwd, 'package.json');
|
|
21
|
+
|
|
22
|
+
if (!existsSync(packageJsonPath)) {
|
|
23
|
+
console.error('ā package.json not found in current directory!');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, { encoding: 'utf-8' }));
|
|
28
|
+
const scripts = packageJson.scripts || {};
|
|
29
|
+
|
|
30
|
+
// Filter scripts that start with 'build-' but exclude 'build' itself
|
|
31
|
+
const buildScripts = Object.keys(scripts)
|
|
32
|
+
.filter(script => script.startsWith('build-') && script !== 'build')
|
|
33
|
+
.sort(); // Sort alphabetically for consistent execution order
|
|
34
|
+
|
|
35
|
+
if (buildScripts.length === 0) {
|
|
36
|
+
console.warn('ā ļø No build-<project> scripts found in package.json');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
console.log(`š¦ Found ${buildScripts.length} projects to build:\n`);
|
|
41
|
+
buildScripts.forEach((script, index) => {
|
|
42
|
+
console.log(` ${index + 1}. ${script}`);
|
|
43
|
+
});
|
|
44
|
+
console.log('');
|
|
45
|
+
|
|
46
|
+
// Build each project sequentially
|
|
47
|
+
const results = [];
|
|
48
|
+
for (let i = 0; i < buildScripts.length; i++) {
|
|
49
|
+
const script = buildScripts[i];
|
|
50
|
+
const projectName = script.replace('build-', '');
|
|
51
|
+
|
|
52
|
+
console.log(`\n${'='.repeat(60)}`);
|
|
53
|
+
console.log(`šØ [${i + 1}/${buildScripts.length}] Building: ${projectName}`);
|
|
54
|
+
console.log(`${'='.repeat(60)}\n`);
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
// Run the build script
|
|
58
|
+
execSync(`npm run ${script}`, {
|
|
59
|
+
stdio: 'inherit',
|
|
60
|
+
cwd: originalCwd
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
results.push({ project: projectName, status: 'success' });
|
|
64
|
+
console.log(`\nā
Successfully built: ${projectName}\n`);
|
|
65
|
+
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(`\nā Failed to build: ${projectName}`);
|
|
68
|
+
console.error(`Error: ${error.message}\n`);
|
|
69
|
+
results.push({ project: projectName, status: 'failed', error: error.message });
|
|
70
|
+
|
|
71
|
+
// Ask user if they want to continue with remaining builds
|
|
72
|
+
const readline = require('readline');
|
|
73
|
+
const rl = readline.createInterface({
|
|
74
|
+
input: process.stdin,
|
|
75
|
+
output: process.stdout
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const continueBuild = await new Promise((resolve) => {
|
|
79
|
+
rl.question('Continue with remaining builds? (yes/no): ', (answer) => {
|
|
80
|
+
rl.close();
|
|
81
|
+
resolve(answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (!continueBuild) {
|
|
86
|
+
console.log('\nā ļø Build process stopped by user.');
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Print summary
|
|
93
|
+
console.log(`\n${'='.repeat(60)}`);
|
|
94
|
+
console.log('š Build Summary');
|
|
95
|
+
console.log(`${'='.repeat(60)}\n`);
|
|
96
|
+
|
|
97
|
+
const successful = results.filter(r => r.status === 'success').length;
|
|
98
|
+
const failed = results.filter(r => r.status === 'failed').length;
|
|
99
|
+
|
|
100
|
+
results.forEach((result, index) => {
|
|
101
|
+
const icon = result.status === 'success' ? 'ā
' : 'ā';
|
|
102
|
+
console.log(`${icon} ${index + 1}. ${result.project}: ${result.status}`);
|
|
103
|
+
if (result.error) {
|
|
104
|
+
console.log(` Error: ${result.error}`);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
console.log(`\nš Total: ${results.length} | ā
Success: ${successful} | ā Failed: ${failed}\n`);
|
|
109
|
+
|
|
110
|
+
if (failed === 0) {
|
|
111
|
+
console.log('š All projects built successfully!\n');
|
|
112
|
+
} else {
|
|
113
|
+
console.log(`ā ļø ${failed} project(s) failed to build.\n`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error('ā Error during build-all process:', error.message);
|
|
118
|
+
} finally {
|
|
119
|
+
// Always return to original directory
|
|
120
|
+
process.chdir(originalCwd);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = buildAllProjects;
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
package/buildProject.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
const { execSync } = require('child_process');
|
|
2
|
+
const { readFileSync, writeFileSync, existsSync } = require('fs');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { resolveNgProjectNameForPackageDir } = require('./resolveNgProjectName');
|
|
6
|
+
|
|
7
|
+
function readJsonSafe(p) {
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(readFileSync(p, { encoding: 'utf-8' }));
|
|
10
|
+
} catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** e.g. "@cloudidesys/cloud-ide-element" -> "cloud-ide-element" (folder under projects/) */
|
|
16
|
+
function folderNameFromProjectArg(projectName) {
|
|
17
|
+
const s = String(projectName).trim();
|
|
18
|
+
if (!s) return s;
|
|
19
|
+
const parts = s.split(/[/\\]/);
|
|
20
|
+
return parts[parts.length - 1] || s;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function resolveAngularDistFromNgPackage(projectAbsDir, workspaceRoot, distPathDefault) {
|
|
24
|
+
const ngPkgPath = path.join(projectAbsDir, 'ng-package.json');
|
|
25
|
+
if (existsSync(ngPkgPath)) {
|
|
26
|
+
const ngPkg = readJsonSafe(ngPkgPath);
|
|
27
|
+
if (ngPkg && ngPkg.dest) {
|
|
28
|
+
return path.resolve(projectAbsDir, ngPkg.dest);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const folderName = path.basename(projectAbsDir);
|
|
32
|
+
const scoped = path.join(workspaceRoot, distPathDefault || 'dist', '@cloudidesys', folderName);
|
|
33
|
+
if (existsSync(scoped)) return scoped;
|
|
34
|
+
return path.join(workspaceRoot, distPathDefault || 'dist', folderName);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function buildProject(projectName, shouldInstall = false, options = {}) {
|
|
38
|
+
const force = !!options.force;
|
|
39
|
+
console.log(`Building project: ${projectName}`);
|
|
40
|
+
|
|
41
|
+
// Store the original working directory
|
|
42
|
+
const originalCwd = process.cwd();
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
// For Angular workspaces, check if we're in the root workspace
|
|
46
|
+
// Projects are typically in the 'projects' folder
|
|
47
|
+
const projectsPath = path.join(originalCwd, 'projects');
|
|
48
|
+
const folderName = folderNameFromProjectArg(projectName);
|
|
49
|
+
const projectPath = path.join(projectsPath, folderName);
|
|
50
|
+
|
|
51
|
+
// Check if projects folder exists (Angular workspace structure)
|
|
52
|
+
if (!existsSync(projectsPath)) {
|
|
53
|
+
console.error(`Projects folder not found! Make sure you're in an Angular workspace root.`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Check if specific project exists in projects folder
|
|
58
|
+
if (!existsSync(projectPath)) {
|
|
59
|
+
console.error(`Project '${projectName}' not found in projects folder!`);
|
|
60
|
+
console.log(`Available projects: ${fs.readdirSync(projectsPath).join(', ')}`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.log(`Found Angular project: ${projectPath}`);
|
|
65
|
+
console.log(`Working from Angular workspace root: ${originalCwd}`);
|
|
66
|
+
|
|
67
|
+
// Read project configuration from workspace root
|
|
68
|
+
const cidePath = path.join(originalCwd, 'cide.json');
|
|
69
|
+
if (!existsSync(cidePath)) {
|
|
70
|
+
console.error(`cide.json not found in workspace root!`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const cide = JSON.parse(readFileSync(cidePath, { encoding: 'utf-8' }));
|
|
75
|
+
const packageJsonPath = path.join(projectPath, 'package.json');
|
|
76
|
+
const ngProjectName = resolveNgProjectNameForPackageDir(originalCwd, path.resolve(projectPath), packageJsonPath);
|
|
77
|
+
|
|
78
|
+
// Step 1: Increment version in project's package.json
|
|
79
|
+
await incrementVersion(projectPath);
|
|
80
|
+
|
|
81
|
+
// Step 2: Run build command
|
|
82
|
+
await runBuildCommand(cide, ngProjectName);
|
|
83
|
+
|
|
84
|
+
// Step 3: Navigate to dist folder and publish
|
|
85
|
+
await publishFromDist(originalCwd, projectPath, cide);
|
|
86
|
+
|
|
87
|
+
// Step 4: Install at root if --install flag is provided
|
|
88
|
+
if (shouldInstall) {
|
|
89
|
+
const pkg = readJsonSafe(path.join(projectPath, 'package.json'));
|
|
90
|
+
const depName = (pkg && pkg.name) ? pkg.name : folderName;
|
|
91
|
+
await installAtRoot(originalCwd, depName, force);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.log(`ā
Project '${projectName}' built and published successfully!`);
|
|
95
|
+
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('Error during build process:', error.message);
|
|
98
|
+
} finally {
|
|
99
|
+
// Always return to original directory
|
|
100
|
+
process.chdir(originalCwd);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function incrementVersion(projectPath) {
|
|
105
|
+
const packageJsonPath = path.join(projectPath, 'package.json');
|
|
106
|
+
|
|
107
|
+
if (!existsSync(packageJsonPath)) {
|
|
108
|
+
console.warn('package.json not found, skipping version increment');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, { encoding: 'utf-8' }));
|
|
113
|
+
|
|
114
|
+
if (!packageJson.version) {
|
|
115
|
+
console.warn('No version found in package.json, skipping version increment');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Parse current version
|
|
120
|
+
const versionParts = packageJson.version.split('.');
|
|
121
|
+
const patch = parseInt(versionParts[2]) || 0;
|
|
122
|
+
|
|
123
|
+
// Increment patch version
|
|
124
|
+
versionParts[2] = (patch + 1).toString();
|
|
125
|
+
packageJson.version = versionParts.join('.');
|
|
126
|
+
|
|
127
|
+
// Write updated package.json
|
|
128
|
+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
129
|
+
console.log(`š¦ Version incremented to: ${packageJson.version}`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function runBuildCommand(cide, projectName) {
|
|
133
|
+
let buildCommand = "";
|
|
134
|
+
|
|
135
|
+
if (cide?.templete === 'node') {
|
|
136
|
+
buildCommand = "npx tsc";
|
|
137
|
+
} else if (cide?.templete === 'react') {
|
|
138
|
+
buildCommand = "npm run build";
|
|
139
|
+
} else if (cide?.templete === 'angular') {
|
|
140
|
+
// For Angular projects, build specific library/project
|
|
141
|
+
buildCommand = `ng build --project ${projectName}`;
|
|
142
|
+
} else {
|
|
143
|
+
// Try to use custom build command from cide.json
|
|
144
|
+
buildCommand = cide?.build_command || `npm run build ${projectName}`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (buildCommand) {
|
|
148
|
+
console.log(`šØ Running build command: ${buildCommand}`);
|
|
149
|
+
try {
|
|
150
|
+
execSync(buildCommand, { stdio: 'inherit', shell: true });
|
|
151
|
+
console.log('ā
Build completed successfully');
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error('ā Build failed:', error.message);
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
console.warn('No build command specified in cide.json');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function publishFromDist(workspaceRoot, projectAbsDir, cide) {
|
|
162
|
+
const distPath = cide?.dist_path || 'dist';
|
|
163
|
+
const fullDistPath = resolveAngularDistFromNgPackage(projectAbsDir, workspaceRoot, distPath);
|
|
164
|
+
|
|
165
|
+
if (!existsSync(fullDistPath)) {
|
|
166
|
+
console.error(`Dist folder '${fullDistPath}' not found!`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
console.log(`š Navigating to dist folder: ${fullDistPath}`);
|
|
171
|
+
process.chdir(fullDistPath);
|
|
172
|
+
|
|
173
|
+
// Check if package.json exists in dist folder
|
|
174
|
+
const distPackageJsonPath = path.join(fullDistPath, 'package.json');
|
|
175
|
+
if (!existsSync(distPackageJsonPath)) {
|
|
176
|
+
console.warn('package.json not found in dist folder, skipping publish');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Publish the package
|
|
181
|
+
console.log('š¤ Publishing package from dist folder...');
|
|
182
|
+
try {
|
|
183
|
+
execSync('npm publish', { stdio: 'inherit' });
|
|
184
|
+
console.log('ā
Package published successfully');
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.error('ā Package publish failed:', error.message);
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function installAtRoot(rootPath, projectName, force = false) {
|
|
192
|
+
console.log(`š„ Updating package '${projectName}' at root...`);
|
|
193
|
+
|
|
194
|
+
// Return to root directory
|
|
195
|
+
process.chdir(rootPath);
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
// Update the package and save to package.json dependencies
|
|
199
|
+
const forceFlag = force ? ' --force' : '';
|
|
200
|
+
console.log(force ? `npm update --save ${projectName} --force` : `npm update --save ${projectName}`);
|
|
201
|
+
execSync(`npm update --save ${projectName}${forceFlag}`, { stdio: 'inherit' });
|
|
202
|
+
console.log(`ā
Package '${projectName}' updated successfully at root`);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
console.error(`ā Failed to update package '${projectName}' at root:`, error.message);
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
module.exports = buildProject;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cide build ā same numbered package list as publish; runs ng build / npm run build only (no bump, no registry publish).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { execSync } = require('child_process');
|
|
8
|
+
const readline = require('readline');
|
|
9
|
+
const publishPackage = require('./publishPackage');
|
|
10
|
+
const { resolveNgProjectNameForPackageDir } = require('./resolveNgProjectName');
|
|
11
|
+
|
|
12
|
+
const loadCideConfig = publishPackage.loadCideConfig;
|
|
13
|
+
const discoverPublishablePackages = publishPackage.discoverPublishablePackages;
|
|
14
|
+
const parsePackagePublishSpec = publishPackage.parsePackagePublishSpec;
|
|
15
|
+
|
|
16
|
+
function question(rl, prompt) {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
rl.question(prompt, (answer) => resolve(answer));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function printBuildUsageBox() {
|
|
23
|
+
console.log(`
|
|
24
|
+
----------------------------------------------------------------
|
|
25
|
+
HOW TO BUILD (workspace) ā same numbers as cide publish
|
|
26
|
+
----------------------------------------------------------------
|
|
27
|
+
Builds only (no version bump, no npm publish):
|
|
28
|
+
1 single package
|
|
29
|
+
1,3,5 several
|
|
30
|
+
1-5 range
|
|
31
|
+
all every package in the list
|
|
32
|
+
|
|
33
|
+
CANCEL: q
|
|
34
|
+
|
|
35
|
+
Non-interactive:
|
|
36
|
+
cide build -p 1
|
|
37
|
+
cide build -p all --continue-on-error
|
|
38
|
+
|
|
39
|
+
After a failure (interactive):
|
|
40
|
+
[r] re-runs the same ng build / npm run build for that package, then continues to the next on success.
|
|
41
|
+
[y] skips to the next package. [N] stops and prints resume commands.
|
|
42
|
+
|
|
43
|
+
Non-interactive after a failure:
|
|
44
|
+
cide build -p all --resume-from 5
|
|
45
|
+
----------------------------------------------------------------
|
|
46
|
+
`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {object} [options]
|
|
51
|
+
* @param {string} [options.packages] - -p / --packages
|
|
52
|
+
* @param {import('readline').Interface} [options.readlineInterface]
|
|
53
|
+
* @param {boolean} [options.continueOnError]
|
|
54
|
+
* @param {string|number} [options.resumeFrom]
|
|
55
|
+
*/
|
|
56
|
+
async function buildWorkspace(options = {}) {
|
|
57
|
+
const cliPackages = options.packages != null ? String(options.packages).trim() : '';
|
|
58
|
+
const fromCli = cliPackages.length > 0;
|
|
59
|
+
|
|
60
|
+
const angularRoot = process.cwd();
|
|
61
|
+
const { cide, monorepoRoot } = loadCideConfig(angularRoot);
|
|
62
|
+
|
|
63
|
+
if (!fs.existsSync(path.join(angularRoot, 'cide.json'))) {
|
|
64
|
+
console.warn('No cide.json in current directory ā using cwd as both angular and monorepo root.');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log('\nScanning workspace for buildable packages (same list as publish)...\n');
|
|
68
|
+
const packages = discoverPublishablePackages({ cide, angularRoot, monorepoRoot });
|
|
69
|
+
if (!packages.length) {
|
|
70
|
+
console.error('No publishable packages found (same discovery as publish ā need publishConfig.registry ā GitHub Packages).');
|
|
71
|
+
console.error('Check cide.json workspace_root / sibling_packages and package publishConfig.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!fromCli) {
|
|
76
|
+
printBuildUsageBox();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
console.log('Buildable packages:\n');
|
|
80
|
+
packages.forEach((p, i) => {
|
|
81
|
+
const rel = p.labelRel || p.folderName;
|
|
82
|
+
console.log(` [${i + 1}] ${p.name.padEnd(42)} v${p.version} (${rel})`);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const ownsReadline = !options.readlineInterface;
|
|
86
|
+
const rl = options.readlineInterface || readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
let parsed;
|
|
90
|
+
if (fromCli) {
|
|
91
|
+
parsed = parsePackagePublishSpec(cliPackages, packages.length);
|
|
92
|
+
if (!parsed.ok) {
|
|
93
|
+
if (parsed.error !== 'cancelled') console.error(parsed.error || 'Invalid --packages');
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
const raw = await question(rl, '\nYour choice (see HOW TO BUILD above): ');
|
|
98
|
+
parsed = parsePackagePublishSpec(raw, packages.length);
|
|
99
|
+
if (!parsed.ok) {
|
|
100
|
+
if (parsed.error !== 'cancelled') console.error(parsed.error || 'Invalid input.');
|
|
101
|
+
console.log('Aborted.');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const { indices } = parsed;
|
|
107
|
+
|
|
108
|
+
const rawResume = options.resumeFrom != null ? String(options.resumeFrom).trim() : '';
|
|
109
|
+
const parsedResume = rawResume === '' ? 1 : parseInt(rawResume, 10);
|
|
110
|
+
const startStep = Number.isFinite(parsedResume) && parsedResume >= 1 ? parsedResume : 1;
|
|
111
|
+
if (startStep > indices.length) {
|
|
112
|
+
console.error(
|
|
113
|
+
`--resume-from ${startStep} is past the end of this batch (${indices.length} step(s)). Nothing to do.`
|
|
114
|
+
);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (startStep > 1) {
|
|
118
|
+
console.log(
|
|
119
|
+
`\n(Resuming: skipping batch steps 1..${startStep - 1}, starting at step ${startStep}/${indices.length})\n`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const continueOnError = !!options.continueOnError;
|
|
124
|
+
|
|
125
|
+
let builtOk = 0;
|
|
126
|
+
let skippedAfterFailure = 0;
|
|
127
|
+
|
|
128
|
+
function printBuildResumeHints(failedStep, nextStep, total) {
|
|
129
|
+
const pSpec = fromCli && cliPackages ? cliPackages : '<same -p as before (e.g. all)>';
|
|
130
|
+
console.log('\nAfter fixing the issue:');
|
|
131
|
+
console.log(` ⢠Retry same step: cide build -p ${pSpec} --resume-from ${failedStep}`);
|
|
132
|
+
if (nextStep <= total) {
|
|
133
|
+
console.log(` ⢠Continue from next: cide build -p ${pSpec} --resume-from ${nextStep}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
for (let k = startStep - 1; k < indices.length; k++) {
|
|
138
|
+
const idx = indices[k];
|
|
139
|
+
const entry = packages[idx];
|
|
140
|
+
const n = k + 1;
|
|
141
|
+
const total = indices.length;
|
|
142
|
+
|
|
143
|
+
let stepComplete = false;
|
|
144
|
+
while (!stepComplete) {
|
|
145
|
+
console.log(`\n--- Building ${n}/${total}: ${entry.name} ---`);
|
|
146
|
+
|
|
147
|
+
const originalCwd = process.cwd();
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
if (entry.kind === 'angular-lib') {
|
|
151
|
+
if (cide.templete !== 'angular') {
|
|
152
|
+
console.warn(' Warning: cide.templete is not "angular"; still running ng build.');
|
|
153
|
+
}
|
|
154
|
+
const ngProjectName = resolveNgProjectNameForPackageDir(
|
|
155
|
+
angularRoot,
|
|
156
|
+
entry.absDir,
|
|
157
|
+
entry.packageJsonPath
|
|
158
|
+
);
|
|
159
|
+
console.log(` ng build --project "${ngProjectName}"`);
|
|
160
|
+
execSync(`ng build --project "${ngProjectName}"`, { cwd: angularRoot, stdio: 'inherit', shell: true });
|
|
161
|
+
} else if (entry.hasBuildScript) {
|
|
162
|
+
console.log(' npm run build');
|
|
163
|
+
execSync('npm run build', { cwd: entry.absDir, stdio: 'inherit' });
|
|
164
|
+
} else {
|
|
165
|
+
console.warn(' ā Skipping (no ng project and no build script).');
|
|
166
|
+
throw new Error('No build script for this package.');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
builtOk++;
|
|
170
|
+
stepComplete = true;
|
|
171
|
+
} catch (err) {
|
|
172
|
+
console.error(` ā Failed: ${err.message}`);
|
|
173
|
+
process.chdir(originalCwd);
|
|
174
|
+
|
|
175
|
+
const nextStep = k + 2;
|
|
176
|
+
const canAsk =
|
|
177
|
+
rl && (process.stdin.isTTY || options.readlineInterface) && !continueOnError;
|
|
178
|
+
|
|
179
|
+
if (continueOnError) {
|
|
180
|
+
skippedAfterFailure++;
|
|
181
|
+
console.log(' (--continue-on-error: continuing with remaining packages.)');
|
|
182
|
+
stepComplete = true;
|
|
183
|
+
} else if (!canAsk) {
|
|
184
|
+
console.error('\nStopped.');
|
|
185
|
+
console.error('(Non-interactive: add --continue-on-error to keep going, or use --resume-from.)');
|
|
186
|
+
printBuildResumeHints(n, nextStep, total);
|
|
187
|
+
throw err;
|
|
188
|
+
} else {
|
|
189
|
+
const ans = await question(
|
|
190
|
+
rl,
|
|
191
|
+
'\n[y] skip to next package / [r]etry this step (re-run same command) / [N] stop: '
|
|
192
|
+
);
|
|
193
|
+
const a = String(ans).trim().toLowerCase();
|
|
194
|
+
if (a === 'r' || a === 'retry') {
|
|
195
|
+
console.log(`\n ā» Retrying step ${n}/${total} (${entry.name})...\n`);
|
|
196
|
+
continue;
|
|
197
|
+
} else if (/^y(es)?$/i.test(a)) {
|
|
198
|
+
skippedAfterFailure++;
|
|
199
|
+
console.log('\n (Skipping failed package; continuing with the rest.)');
|
|
200
|
+
stepComplete = true;
|
|
201
|
+
} else {
|
|
202
|
+
console.log('\nStopped.');
|
|
203
|
+
printBuildResumeHints(n, nextStep, total);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
} finally {
|
|
208
|
+
process.chdir(originalCwd);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (skippedAfterFailure === 0) {
|
|
214
|
+
console.log(`\nā
Built ${builtOk} package(s) successfully.\n`);
|
|
215
|
+
} else {
|
|
216
|
+
console.log(
|
|
217
|
+
`\nā ļø Batch finished: ${builtOk} built OK, ${skippedAfterFailure} failed (skipped).\n`
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
} finally {
|
|
221
|
+
if (ownsReadline) rl.close();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
module.exports = buildWorkspace;
|