@lightshell/create 0.1.0

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.
Files changed (2) hide show
  1. package/index.js +140 -0
  2. package/package.json +22 -0
package/index.js ADDED
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env node
2
+
3
+ // npm create lightshell@latest my-app
4
+ // Creates a new LightShell project without requiring lightshell to be installed.
5
+
6
+ const { execSync, spawnSync } = require("child_process");
7
+ const fs = require("fs");
8
+ const path = require("path");
9
+
10
+ const name = process.argv[2];
11
+
12
+ if (!name) {
13
+ console.log(`
14
+ Usage: npm create lightshell@latest <app-name>
15
+
16
+ Example:
17
+ npm create lightshell@latest my-app
18
+ cd my-app
19
+ npx lightshell dev
20
+ `);
21
+ process.exit(1);
22
+ }
23
+
24
+ // Validate name
25
+ if (!/^[a-z0-9-]+$/.test(name)) {
26
+ console.error(
27
+ `Error: app name must contain only lowercase letters, numbers, and hyphens.`
28
+ );
29
+ process.exit(1);
30
+ }
31
+
32
+ const dir = path.resolve(name);
33
+ if (fs.existsSync(dir)) {
34
+ console.error(`Error: directory "${name}" already exists.`);
35
+ process.exit(1);
36
+ }
37
+
38
+ const title = name
39
+ .split("-")
40
+ .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
41
+ .join(" ");
42
+
43
+ // Create project structure
44
+ fs.mkdirSync(path.join(dir, "src"), { recursive: true });
45
+
46
+ // lightshell.json
47
+ fs.writeFileSync(
48
+ path.join(dir, "lightshell.json"),
49
+ JSON.stringify(
50
+ {
51
+ name,
52
+ version: "1.0.0",
53
+ entry: "src/index.html",
54
+ window: {
55
+ title,
56
+ width: 1024,
57
+ height: 768,
58
+ minWidth: 400,
59
+ minHeight: 300,
60
+ resizable: true,
61
+ },
62
+ permissions: ["fs", "dialog", "clipboard", "shell", "notification"],
63
+ build: {
64
+ appId: `com.lightshell.${name}`,
65
+ },
66
+ },
67
+ null,
68
+ 2
69
+ ) + "\n"
70
+ );
71
+
72
+ // index.html
73
+ fs.writeFileSync(
74
+ path.join(dir, "src", "index.html"),
75
+ `<!DOCTYPE html>
76
+ <html lang="en">
77
+ <head>
78
+ <meta charset="UTF-8">
79
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
80
+ <title>${title}</title>
81
+ <link rel="stylesheet" href="style.css">
82
+ </head>
83
+ <body>
84
+ <main>
85
+ <h1>${title}</h1>
86
+ <p>Edit <code>src/</code> to get started.</p>
87
+ <div id="info"></div>
88
+ </main>
89
+ <script src="app.js"></script>
90
+ </body>
91
+ </html>
92
+ `
93
+ );
94
+
95
+ // style.css
96
+ fs.writeFileSync(
97
+ path.join(dir, "src", "style.css"),
98
+ `* { margin: 0; padding: 0; box-sizing: border-box; }
99
+
100
+ body {
101
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans",
102
+ Helvetica, Arial, sans-serif;
103
+ -webkit-font-smoothing: antialiased;
104
+ background: #f5f5f7;
105
+ color: #1d1d1f;
106
+ display: flex;
107
+ align-items: center;
108
+ justify-content: center;
109
+ min-height: 100vh;
110
+ }
111
+
112
+ main { text-align: center; padding: 2rem; }
113
+ h1 { font-size: 2rem; font-weight: 600; margin-bottom: 0.5rem; }
114
+ p { color: #6e6e73; margin-bottom: 1.5rem; }
115
+ code { background: #e8e8ed; padding: 2px 6px; border-radius: 3px; font-size: 0.875em; }
116
+ #info { font-family: monospace; color: #86868b; font-size: 0.875rem; }
117
+ `
118
+ );
119
+
120
+ // app.js
121
+ fs.writeFileSync(
122
+ path.join(dir, "src", "app.js"),
123
+ `async function init() {
124
+ const platform = await lightshell.system.platform()
125
+ const arch = await lightshell.system.arch()
126
+ document.getElementById('info').textContent = \`Running on \${platform}/\${arch}\`
127
+ }
128
+
129
+ init()
130
+ `
131
+ );
132
+
133
+ console.log(`
134
+ Created ${name}!
135
+
136
+ cd ${name}
137
+ npx lightshell dev
138
+
139
+ Happy building!
140
+ `);
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@lightshell/create",
3
+ "version": "0.1.0",
4
+ "description": "Create a new LightShell desktop app",
5
+ "keywords": [
6
+ "create",
7
+ "lightshell",
8
+ "desktop",
9
+ "app"
10
+ ],
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/meherpanguluri/lightshell"
15
+ },
16
+ "bin": {
17
+ "create-lightshell": "index.js"
18
+ },
19
+ "engines": {
20
+ "node": ">=16"
21
+ }
22
+ }