electrobun 0.0.19-beta.111 → 0.0.19-beta.112

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electrobun",
3
- "version": "0.0.19-beta.111",
3
+ "version": "0.0.19-beta.112",
4
4
  "description": "Build ultra fast, tiny, and cross-platform desktop apps with Typescript.",
5
5
  "license": "MIT",
6
6
  "author": "Blackboard Technologies Inc.",
package/src/cli/index.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  copyFileSync,
16
16
  } from "fs";
17
17
  import { execSync } from "child_process";
18
+ import * as readline from "readline";
18
19
  import tar from "tar";
19
20
  import archiver from "archiver";
20
21
  import { ZstdInit } from "@oneidentity/zstd-js/wasm";
@@ -702,57 +703,117 @@ const bundleFileName = targetOS === 'macos' ? `${appFileName}.app` : appFileName
702
703
  let proc = null;
703
704
 
704
705
  if (commandArg === "init") {
705
- const projectName = process.argv[indexOfElectrobun + 2] || "my-electrobun-app";
706
- const templateName = process.argv.find(arg => arg.startsWith("--template="))?.split("=")[1] || "hello-world";
707
-
708
- console.log(`🚀 Initializing Electrobun project: ${projectName}`);
709
-
710
- // Validate template name
711
- const availableTemplates = getTemplateNames();
712
- if (!availableTemplates.includes(templateName)) {
713
- console.error(`❌ Template "${templateName}" not found.`);
714
- console.log(`Available templates: ${availableTemplates.join(", ")}`);
715
- process.exit(1);
716
- }
717
-
718
- const template = getTemplate(templateName);
719
- if (!template) {
720
- console.error(`❌ Could not load template "${templateName}"`);
721
- process.exit(1);
722
- }
723
-
724
- // Create project directory
725
- const projectPath = join(process.cwd(), projectName);
726
- if (existsSync(projectPath)) {
727
- console.error(`❌ Directory "${projectName}" already exists.`);
728
- process.exit(1);
729
- }
730
-
731
- mkdirSync(projectPath, { recursive: true });
732
-
733
- // Extract template files
734
- let fileCount = 0;
735
- for (const [relativePath, content] of Object.entries(template.files)) {
736
- const fullPath = join(projectPath, relativePath);
737
- const dir = dirname(fullPath);
706
+ await (async () => {
707
+ const secondArg = process.argv[indexOfElectrobun + 2];
708
+ const availableTemplates = getTemplateNames();
738
709
 
739
- // Create directory if it doesn't exist
740
- mkdirSync(dir, { recursive: true });
710
+ let projectName: string;
711
+ let templateName: string;
741
712
 
742
- // Write file
743
- writeFileSync(fullPath, content, 'utf-8');
744
- fileCount++;
745
- }
746
-
747
- console.log(`✅ Created ${fileCount} files from "${templateName}" template`);
748
- console.log(`📁 Project created at: ${projectPath}`);
749
- console.log("");
750
- console.log("📦 Next steps:");
751
- console.log(` cd ${projectName}`);
752
- console.log(" bun install");
753
- console.log(" bunx electrobun dev");
754
- console.log("");
755
- console.log("🎉 Happy building with Electrobun!");
713
+ // Check if --template= flag is used
714
+ const templateFlag = process.argv.find(arg => arg.startsWith("--template="));
715
+ if (templateFlag) {
716
+ // Traditional usage: electrobun init my-project --template=photo-booth
717
+ projectName = secondArg || "my-electrobun-app";
718
+ templateName = templateFlag.split("=")[1];
719
+ } else if (secondArg && availableTemplates.includes(secondArg)) {
720
+ // New intuitive usage: electrobun init photo-booth
721
+ projectName = secondArg; // Use template name as project name
722
+ templateName = secondArg;
723
+ } else {
724
+ // Interactive menu when no template specified
725
+ console.log("🚀 Welcome to Electrobun!");
726
+ console.log("");
727
+ console.log("Available templates:");
728
+ availableTemplates.forEach((template, index) => {
729
+ console.log(` ${index + 1}. ${template}`);
730
+ });
731
+ console.log("");
732
+
733
+ // Simple CLI selection using readline
734
+ const rl = readline.createInterface({
735
+ input: process.stdin,
736
+ output: process.stdout
737
+ });
738
+
739
+ const choice = await new Promise<string>((resolve) => {
740
+ rl.question('Select a template (enter number): ', (answer) => {
741
+ rl.close();
742
+ resolve(answer.trim());
743
+ });
744
+ });
745
+
746
+ const templateIndex = parseInt(choice) - 1;
747
+ if (templateIndex < 0 || templateIndex >= availableTemplates.length) {
748
+ console.error(`❌ Invalid selection. Please enter a number between 1 and ${availableTemplates.length}.`);
749
+ process.exit(1);
750
+ }
751
+
752
+ templateName = availableTemplates[templateIndex];
753
+
754
+ // Ask for project name
755
+ const rl2 = readline.createInterface({
756
+ input: process.stdin,
757
+ output: process.stdout
758
+ });
759
+
760
+ projectName = await new Promise<string>((resolve) => {
761
+ rl2.question(`Enter project name (default: my-${templateName}-app): `, (answer) => {
762
+ rl2.close();
763
+ resolve(answer.trim() || `my-${templateName}-app`);
764
+ });
765
+ });
766
+ }
767
+
768
+ console.log(`🚀 Initializing Electrobun project: ${projectName}`);
769
+ console.log(`📋 Using template: ${templateName}`);
770
+
771
+ // Validate template name
772
+ if (!availableTemplates.includes(templateName)) {
773
+ console.error(`❌ Template "${templateName}" not found.`);
774
+ console.log(`Available templates: ${availableTemplates.join(", ")}`);
775
+ process.exit(1);
776
+ }
777
+
778
+ const template = getTemplate(templateName);
779
+ if (!template) {
780
+ console.error(`❌ Could not load template "${templateName}"`);
781
+ process.exit(1);
782
+ }
783
+
784
+ // Create project directory
785
+ const projectPath = join(process.cwd(), projectName);
786
+ if (existsSync(projectPath)) {
787
+ console.error(`❌ Directory "${projectName}" already exists.`);
788
+ process.exit(1);
789
+ }
790
+
791
+ mkdirSync(projectPath, { recursive: true });
792
+
793
+ // Extract template files
794
+ let fileCount = 0;
795
+ for (const [relativePath, content] of Object.entries(template.files)) {
796
+ const fullPath = join(projectPath, relativePath);
797
+ const dir = dirname(fullPath);
798
+
799
+ // Create directory if it doesn't exist
800
+ mkdirSync(dir, { recursive: true });
801
+
802
+ // Write file
803
+ writeFileSync(fullPath, content, 'utf-8');
804
+ fileCount++;
805
+ }
806
+
807
+ console.log(`✅ Created ${fileCount} files from "${templateName}" template`);
808
+ console.log(`📁 Project created at: ${projectPath}`);
809
+ console.log("");
810
+ console.log("📦 Next steps:");
811
+ console.log(` cd ${projectName}`);
812
+ console.log(" bun install");
813
+ console.log(" bunx electrobun dev");
814
+ console.log("");
815
+ console.log("🎉 Happy building with Electrobun!");
816
+ })();
756
817
  } else if (commandArg === "build") {
757
818
  // Ensure core binaries are available for the target platform before starting build
758
819
  await ensureCoreDependencies(currentTarget.os, currentTarget.arch);
@@ -5,6 +5,16 @@
5
5
  "version": "0.0.1"
6
6
  },
7
7
  "build": {
8
+ "views": {
9
+ "mainview": {
10
+ "entrypoint": "src/mainview/index.ts",
11
+ "external": []
12
+ }
13
+ },
14
+ "copy": {
15
+ "src/mainview/index.html": "views/mainview/index.html",
16
+ "src/mainview/index.css": "views/mainview/index.css"
17
+ },
8
18
  "mac": {
9
19
  "bundleCEF": true
10
20
  },