@gxp-dev/tools 2.0.34 ā 2.0.35
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/lib/cli.js +6 -0
- package/bin/lib/commands/init.js +75 -50
- package/bin/lib/utils/files.js +8 -3
- package/package.json +1 -1
package/bin/lib/cli.js
CHANGED
package/bin/lib/commands/init.js
CHANGED
|
@@ -41,8 +41,9 @@ const {
|
|
|
41
41
|
* Copy template files to project
|
|
42
42
|
* @param {string} projectPath - Target project path
|
|
43
43
|
* @param {object} paths - Resolved GxP paths
|
|
44
|
+
* @param {boolean} overwrite - If true, overwrite existing files
|
|
44
45
|
*/
|
|
45
|
-
function copyTemplateFiles(projectPath, paths) {
|
|
46
|
+
function copyTemplateFiles(projectPath, paths, overwrite = false) {
|
|
46
47
|
const filesToCopy = [
|
|
47
48
|
{
|
|
48
49
|
src: "theme-layouts/SystemLayout.vue",
|
|
@@ -133,7 +134,7 @@ function copyTemplateFiles(projectPath, paths) {
|
|
|
133
134
|
filesToCopy.forEach((file) => {
|
|
134
135
|
const srcPath = path.join(paths.templateDir, file.src);
|
|
135
136
|
const destPath = path.join(projectPath, file.dest);
|
|
136
|
-
safeCopyFile(srcPath, destPath, file.desc);
|
|
137
|
+
safeCopyFile(srcPath, destPath, file.desc, overwrite);
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
|
|
@@ -141,8 +142,9 @@ function copyTemplateFiles(projectPath, paths) {
|
|
|
141
142
|
* Copy extension scripts to project
|
|
142
143
|
* @param {string} projectPath - Target project path
|
|
143
144
|
* @param {object} paths - Resolved GxP paths
|
|
145
|
+
* @param {boolean} overwrite - If true, overwrite existing files
|
|
144
146
|
*/
|
|
145
|
-
function copyExtensionScripts(projectPath, paths) {
|
|
147
|
+
function copyExtensionScripts(projectPath, paths, overwrite = false) {
|
|
146
148
|
const scriptsDir = path.join(projectPath, "scripts");
|
|
147
149
|
if (!fs.existsSync(scriptsDir)) {
|
|
148
150
|
fs.mkdirSync(scriptsDir, { recursive: true });
|
|
@@ -155,7 +157,7 @@ function copyExtensionScripts(projectPath, paths) {
|
|
|
155
157
|
);
|
|
156
158
|
const launchChromeDest = path.join(scriptsDir, "launch-chrome.js");
|
|
157
159
|
if (fs.existsSync(launchChromeSource)) {
|
|
158
|
-
safeCopyFile(launchChromeSource, launchChromeDest, "Chrome launcher script");
|
|
160
|
+
safeCopyFile(launchChromeSource, launchChromeDest, "Chrome launcher script", overwrite);
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
// Copy pack-chrome.js script
|
|
@@ -165,7 +167,7 @@ function copyExtensionScripts(projectPath, paths) {
|
|
|
165
167
|
);
|
|
166
168
|
const packChromeDest = path.join(scriptsDir, "pack-chrome.js");
|
|
167
169
|
if (fs.existsSync(packChromeSource)) {
|
|
168
|
-
safeCopyFile(packChromeSource, packChromeDest, "Chrome packaging script");
|
|
170
|
+
safeCopyFile(packChromeSource, packChromeDest, "Chrome packaging script", overwrite);
|
|
169
171
|
}
|
|
170
172
|
|
|
171
173
|
// Copy socket events directory
|
|
@@ -182,7 +184,7 @@ function copyExtensionScripts(projectPath, paths) {
|
|
|
182
184
|
eventFiles.forEach((file) => {
|
|
183
185
|
const srcPath = path.join(socketEventsSource, file);
|
|
184
186
|
const destPath = path.join(socketEventsDest, file);
|
|
185
|
-
safeCopyFile(srcPath, destPath, `Socket event: ${file}
|
|
187
|
+
safeCopyFile(srcPath, destPath, `Socket event: ${file}`, overwrite);
|
|
186
188
|
});
|
|
187
189
|
}
|
|
188
190
|
}
|
|
@@ -291,8 +293,9 @@ function launchBrowserExtension(projectPath, browser) {
|
|
|
291
293
|
* Run interactive configuration after project creation
|
|
292
294
|
* @param {string} projectPath - Path to project directory
|
|
293
295
|
* @param {string} initialName - Initial project name from CLI
|
|
296
|
+
* @param {boolean} isLocal - Whether initialized in current directory
|
|
294
297
|
*/
|
|
295
|
-
async function runInteractiveConfig(projectPath, initialName) {
|
|
298
|
+
async function runInteractiveConfig(projectPath, initialName, isLocal = false) {
|
|
296
299
|
console.log("");
|
|
297
300
|
console.log("ā".repeat(50));
|
|
298
301
|
console.log("š Configure Your Plugin");
|
|
@@ -466,7 +469,7 @@ async function runInteractiveConfig(projectPath, initialName) {
|
|
|
466
469
|
devProcess = launchDevServer(projectPath, { withMock: true, noHttps: !sslSetup });
|
|
467
470
|
} else {
|
|
468
471
|
// Print final instructions
|
|
469
|
-
printFinalInstructions(projectPath, appName, sslSetup);
|
|
472
|
+
printFinalInstructions(projectPath, appName, sslSetup, isLocal);
|
|
470
473
|
}
|
|
471
474
|
|
|
472
475
|
return devProcess;
|
|
@@ -477,8 +480,9 @@ async function runInteractiveConfig(projectPath, initialName) {
|
|
|
477
480
|
* @param {string} projectPath - Project path
|
|
478
481
|
* @param {string} projectName - Project name
|
|
479
482
|
* @param {boolean} sslSetup - Whether SSL was set up
|
|
483
|
+
* @param {boolean} isLocal - Whether initialized in current directory
|
|
480
484
|
*/
|
|
481
|
-
function printFinalInstructions(projectPath, projectName, sslSetup) {
|
|
485
|
+
function printFinalInstructions(projectPath, projectName, sslSetup, isLocal = false) {
|
|
482
486
|
console.log("");
|
|
483
487
|
console.log("ā".repeat(50));
|
|
484
488
|
console.log("ā
Project setup complete!");
|
|
@@ -496,7 +500,9 @@ function printFinalInstructions(projectPath, projectName, sslSetup) {
|
|
|
496
500
|
console.log(" ⢠app-manifest.json - Plugin configuration");
|
|
497
501
|
console.log("");
|
|
498
502
|
console.log("š To start development:");
|
|
499
|
-
|
|
503
|
+
if (!isLocal) {
|
|
504
|
+
console.log(` cd ${projectName}`);
|
|
505
|
+
}
|
|
500
506
|
if (sslSetup) {
|
|
501
507
|
console.log(" npm run dev # HTTPS with TUI");
|
|
502
508
|
console.log(" npm run dev-http # HTTP only");
|
|
@@ -517,56 +523,75 @@ async function initCommand(argv) {
|
|
|
517
523
|
const hasPackageJson = fs.existsSync(path.join(currentDir, "package.json"));
|
|
518
524
|
let projectPath = currentDir;
|
|
519
525
|
let projectName;
|
|
526
|
+
const overwrite = argv.local && argv.yes;
|
|
520
527
|
|
|
521
|
-
// Handle
|
|
522
|
-
if (
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
console.log("ā
Project updated!");
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
+
// Handle --local flag: initialize in current directory
|
|
529
|
+
if (argv.local) {
|
|
530
|
+
projectPath = currentDir;
|
|
531
|
+
projectName = argv.name || path.basename(currentDir);
|
|
528
532
|
|
|
529
|
-
// New project - require a name
|
|
530
|
-
if (!argv.name) {
|
|
531
|
-
// In non-interactive mode, name is required
|
|
532
|
-
if (argv.yes) {
|
|
533
|
-
console.error("ā Project name is required when using --yes flag!");
|
|
534
|
-
console.error(" Usage: gxdev init <project-name> --yes");
|
|
535
|
-
process.exit(1);
|
|
536
|
-
}
|
|
537
533
|
console.log("");
|
|
538
|
-
console.log(
|
|
534
|
+
console.log(`š Initializing project in current directory: ${projectName}`);
|
|
535
|
+
if (overwrite) {
|
|
536
|
+
console.log("ā ļø Overwrite mode enabled - existing files will be replaced");
|
|
537
|
+
}
|
|
539
538
|
console.log("ā".repeat(40));
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
if (!
|
|
543
|
-
console.
|
|
539
|
+
} else {
|
|
540
|
+
// Handle existing project update
|
|
541
|
+
if (hasPackageJson && !argv.name) {
|
|
542
|
+
console.log("Updating existing project...");
|
|
543
|
+
updateExistingProject(projectPath);
|
|
544
|
+
console.log("ā
Project updated!");
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// New project - require a name
|
|
549
|
+
if (!argv.name) {
|
|
550
|
+
// In non-interactive mode, name is required
|
|
551
|
+
if (argv.yes) {
|
|
552
|
+
console.error("ā Project name is required when using --yes flag!");
|
|
553
|
+
console.error(" Usage: gxdev init <project-name> --yes");
|
|
554
|
+
process.exit(1);
|
|
555
|
+
}
|
|
556
|
+
console.log("");
|
|
557
|
+
console.log("š GxP Plugin Creator");
|
|
558
|
+
console.log("ā".repeat(40));
|
|
559
|
+
console.log("");
|
|
560
|
+
projectName = await promptUser("š Project name: ");
|
|
561
|
+
if (!projectName) {
|
|
562
|
+
console.error("ā Project name is required!");
|
|
563
|
+
process.exit(1);
|
|
564
|
+
}
|
|
565
|
+
} else {
|
|
566
|
+
projectName = argv.name;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// Create project directory
|
|
570
|
+
projectPath = path.join(currentDir, projectName);
|
|
571
|
+
if (fs.existsSync(projectPath)) {
|
|
572
|
+
console.error(`\nā Directory ${projectName} already exists!`);
|
|
544
573
|
process.exit(1);
|
|
545
574
|
}
|
|
546
|
-
} else {
|
|
547
|
-
projectName = argv.name;
|
|
548
|
-
}
|
|
549
575
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
process.exit(1);
|
|
576
|
+
console.log("");
|
|
577
|
+
console.log(`š Creating project: ${projectName}`);
|
|
578
|
+
console.log("ā".repeat(40));
|
|
579
|
+
fs.mkdirSync(projectPath, { recursive: true });
|
|
555
580
|
}
|
|
556
581
|
|
|
557
|
-
|
|
558
|
-
console.log(`š Creating project: ${projectName}`);
|
|
559
|
-
console.log("ā".repeat(40));
|
|
560
|
-
fs.mkdirSync(projectPath, { recursive: true });
|
|
561
|
-
|
|
562
|
-
// Create package.json
|
|
582
|
+
// Create package.json (only if it doesn't exist or overwrite is enabled)
|
|
563
583
|
const initialDescription = argv.description || "A GxP kiosk plugin";
|
|
564
|
-
|
|
584
|
+
const packageJsonPath = path.join(projectPath, "package.json");
|
|
585
|
+
if (!fs.existsSync(packageJsonPath) || overwrite) {
|
|
586
|
+
createPackageJson(projectPath, projectName, initialDescription);
|
|
587
|
+
} else {
|
|
588
|
+
console.log("āļø Skipping package.json (already exists)");
|
|
589
|
+
}
|
|
565
590
|
|
|
566
591
|
// Copy template files
|
|
567
592
|
const paths = resolveGxPaths();
|
|
568
|
-
copyTemplateFiles(projectPath, paths);
|
|
569
|
-
copyExtensionScripts(projectPath, paths);
|
|
593
|
+
copyTemplateFiles(projectPath, paths, overwrite);
|
|
594
|
+
copyExtensionScripts(projectPath, paths, overwrite);
|
|
570
595
|
createSupportingFiles(projectPath);
|
|
571
596
|
|
|
572
597
|
// Install dependencies
|
|
@@ -581,19 +606,19 @@ async function initCommand(argv) {
|
|
|
581
606
|
updateAppManifest(projectPath, projectName, initialDescription);
|
|
582
607
|
const provider = argv.provider || "gemini"; // Default to gemini for backward compatibility
|
|
583
608
|
await runAIScaffolding(projectPath, projectName, initialDescription, argv.build, provider);
|
|
584
|
-
printFinalInstructions(projectPath, projectName, false);
|
|
609
|
+
printFinalInstructions(projectPath, projectName, false, argv.local);
|
|
585
610
|
return;
|
|
586
611
|
}
|
|
587
612
|
|
|
588
613
|
// If --yes flag provided, skip interactive configuration
|
|
589
614
|
if (argv.yes) {
|
|
590
615
|
updateAppManifest(projectPath, projectName, initialDescription);
|
|
591
|
-
printFinalInstructions(projectPath, projectName, false);
|
|
616
|
+
printFinalInstructions(projectPath, projectName, false, argv.local);
|
|
592
617
|
return;
|
|
593
618
|
}
|
|
594
619
|
|
|
595
620
|
// Run interactive configuration
|
|
596
|
-
await runInteractiveConfig(projectPath, projectName);
|
|
621
|
+
await runInteractiveConfig(projectPath, projectName, argv.local);
|
|
597
622
|
}
|
|
598
623
|
|
|
599
624
|
module.exports = {
|
package/bin/lib/utils/files.js
CHANGED
|
@@ -16,10 +16,15 @@ const { loadGlobalConfig } = require("./paths");
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Copies a file from source to destination, creating directories if needed
|
|
19
|
+
* @param {string} src - Source file path
|
|
20
|
+
* @param {string} dest - Destination file path
|
|
21
|
+
* @param {string} description - Description for logging
|
|
22
|
+
* @param {boolean} overwrite - If true, overwrite existing files
|
|
19
23
|
*/
|
|
20
|
-
function safeCopyFile(src, dest, description) {
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
function safeCopyFile(src, dest, description, overwrite = false) {
|
|
25
|
+
const exists = fs.existsSync(dest);
|
|
26
|
+
if (!exists || overwrite) {
|
|
27
|
+
console.log(`${exists ? 'Overwriting' : 'Creating'} ${description}`);
|
|
23
28
|
const destDir = path.dirname(dest);
|
|
24
29
|
if (!fs.existsSync(destDir)) {
|
|
25
30
|
fs.mkdirSync(destDir, { recursive: true });
|