@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 CHANGED
@@ -63,6 +63,12 @@ yargs
63
63
  alias: "y",
64
64
  default: false,
65
65
  },
66
+ local: {
67
+ describe: "Initialize in current directory instead of creating a new one",
68
+ type: "boolean",
69
+ alias: "l",
70
+ default: false,
71
+ },
66
72
  },
67
73
  initCommand
68
74
  )
@@ -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
- console.log(` cd ${projectName}`);
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 existing project update
522
- if (hasPackageJson && !argv.name) {
523
- console.log("Updating existing project...");
524
- updateExistingProject(projectPath);
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("šŸš€ GxP Plugin Creator");
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
- console.log("");
541
- projectName = await promptUser("šŸ“ Project name: ");
542
- if (!projectName) {
543
- console.error("āŒ Project name is required!");
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
- // Create project directory
551
- projectPath = path.join(currentDir, projectName);
552
- if (fs.existsSync(projectPath)) {
553
- console.error(`\nāŒ Directory ${projectName} already exists!`);
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
- console.log("");
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
- createPackageJson(projectPath, projectName, initialDescription);
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 = {
@@ -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
- if (!fs.existsSync(dest)) {
22
- console.log(`Creating ${description}`);
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 });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gxp-dev/tools",
3
- "version": "2.0.34",
3
+ "version": "2.0.35",
4
4
  "description": "Dev tools to create platform plugins",
5
5
  "type": "commonjs",
6
6
  "publishConfig": {