create-lupine 1.0.28 → 1.0.29

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
@@ -280,7 +280,9 @@ async function init() {
280
280
  version: '0.0.0',
281
281
  private: true,
282
282
  workspaces: ['apps/*', 'apps/*/*', 'packages/*'],
283
+ '//desktop': 'If you want to build desktop applications, please run `npm run add-electron` first.',
283
284
  scripts: {
285
+ 'add-electron': 'npm install -D electron@^35.2.0 electron-builder@^26.0.12',
284
286
  'app1:build-win': `electron-builder --win --config apps/${appName}/electron/builder.json`,
285
287
  'app1:build-linux': `electron-builder --linux --config apps/${appName}/electron/builder.json`,
286
288
  'app1:build-mac': `export CSC_IDENTITY_AUTO_DISCOVERY=true && electron-builder --mac --x64 --config apps/${appName}/electron/builder.json`,
@@ -291,9 +293,9 @@ async function init() {
291
293
  'app1:sync': `npm run sync --workspace=${appName}-web`,
292
294
  'app1:open-ios': `npm run open-ios --workspace=${appName}-web`,
293
295
  'app1:open-android': `npm run open-android --workspace=${appName}-web`,
294
- dev: 'node ./dev/dev-watch --env=.env.development --dev=1 --cmd=start-dev',
295
- build: 'node ./dev/dev-watch --env=.env.production --dev=0 --obfuscate=0',
296
- 'build-mobile': 'node ./dev/dev-watch --env=.env.mobile --dev=0 --mobile=1',
296
+ dev: 'lupine-build --env=.env.development --dev=1 --cmd=start-dev',
297
+ build: 'lupine-build --env=.env.production --dev=0 --obfuscate=0',
298
+ 'build-mobile': 'lupine-build --env=.env.mobile --dev=0 --mobile=1',
297
299
  'start-dev': 'node dist/server_root/server/server-loader.js --env=.env.development',
298
300
  'start-production': 'node dist/server_root/server/server-loader.js --env=.env.production',
299
301
  format: 'prettier --write "**/*.{js,json,css,scss,md,html,yaml,ts,jsx,tsx}"',
@@ -302,9 +304,6 @@ async function init() {
302
304
  'lupine.api': 'file:packages/lupine.api',
303
305
  },
304
306
  devDependencies: {
305
- esbuild: '^0.24.2',
306
- electron: '^35.2.0',
307
- 'electron-builder': '^26.0.12',
308
307
  typescript: '^5.7.2',
309
308
  '@types/node': '^22.10.5',
310
309
  prettier: '^2.7.1',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-lupine",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "Scaffolding tool for Lupine.js projects",
5
5
  "bin": {
6
6
  "create-lupine": "index.js"
@@ -17,22 +17,24 @@
17
17
  }
18
18
  ],
19
19
  "apiEntryPoint": "api/src/index.ts",
20
- "watchFiles": ["web/markdown/**/*.md"],
20
+ "watchFiles": [
21
+ "web/markdown/**/*.md"
22
+ ],
21
23
  "copyFiles": [
22
24
  {
23
- "type": "web",
25
+ "env": "all",
24
26
  "from": "web/assets",
25
- "to": "assets"
27
+ "to": "web/assets"
26
28
  },
27
29
  {
28
- "type": "web",
30
+ "env": "all",
29
31
  "from": "web/src/lupine-template-cv-starter/404.html",
30
- "to": "lupine-template-cv-starter/404.html"
32
+ "to": "web/lupine-template-cv-starter/404.html"
31
33
  },
32
34
  {
33
- "type": "data",
35
+ "env": "all",
34
36
  "from": "api/resources",
35
- "to": "resources"
37
+ "to": "data/resources"
36
38
  }
37
39
  ]
38
- }
40
+ }
@@ -17,22 +17,24 @@
17
17
  }
18
18
  ],
19
19
  "apiEntryPoint": "api/src/index.ts",
20
- "watchFiles": ["web/markdown/**/*.md"],
20
+ "watchFiles": [
21
+ "web/markdown/**/*.md"
22
+ ],
21
23
  "copyFiles": [
22
24
  {
23
- "type": "web",
25
+ "env": "all",
24
26
  "from": "web/assets",
25
- "to": "assets"
27
+ "to": "web/assets"
26
28
  },
27
29
  {
28
- "type": "web",
30
+ "env": "all",
29
31
  "from": "web/src/lupine-template-doc-starter/404.html",
30
- "to": "lupine-template-doc-starter/404.html"
32
+ "to": "web/lupine-template-doc-starter/404.html"
31
33
  },
32
34
  {
33
- "type": "data",
35
+ "env": "all",
34
36
  "from": "api/resources",
35
- "to": "resources"
37
+ "to": "data/resources"
36
38
  }
37
39
  ]
38
- }
40
+ }
@@ -10,14 +10,14 @@
10
10
  "apiEntryPoint": "api/src/index.ts",
11
11
  "copyFiles": [
12
12
  {
13
- "type": "web",
13
+ "env": "all",
14
14
  "from": "web/assets",
15
- "to": "assets"
15
+ "to": "web/assets"
16
16
  },
17
17
  {
18
- "type": "data",
18
+ "env": "all",
19
19
  "from": "api/resources",
20
- "to": "resources"
20
+ "to": "data/resources"
21
21
  }
22
22
  ]
23
- }
23
+ }
@@ -15,19 +15,19 @@
15
15
  "apiEntryPoint": "api/src/index.ts",
16
16
  "copyFiles": [
17
17
  {
18
- "type": "web",
18
+ "env": "all",
19
19
  "from": "web/assets",
20
- "to": "assets"
20
+ "to": "web/assets"
21
21
  },
22
22
  {
23
- "type": "web",
23
+ "env": "all",
24
24
  "from": "web/src/lupine-template-responsive-starter/404.html",
25
- "to": "lupine-template-responsive-starter/404.html"
25
+ "to": "web/lupine-template-responsive-starter/404.html"
26
26
  },
27
27
  {
28
- "type": "data",
28
+ "env": "all",
29
29
  "from": "api/resources",
30
- "to": "resources"
30
+ "to": "data/resources"
31
31
  }
32
32
  ]
33
- }
33
+ }
@@ -1,389 +0,0 @@
1
- // esbuild command tools
2
-
3
- const esbuild = require('esbuild');
4
- const path = require('path');
5
- const fs = require('fs/promises');
6
- const {
7
- runCmd,
8
- copyFolder,
9
- sendRequest,
10
- loadEnv,
11
- readJson,
12
- pathExists,
13
- cpIndexHtml,
14
- pluginIfelse,
15
- markdownProcessOnEnd,
16
- obfuscatePlugin,
17
- sha256,
18
- } = require('lupine.api/dev');
19
-
20
- const triggerHandle = {
21
- restart: null,
22
- refresh: null,
23
- };
24
-
25
- // restart server for server code changes
26
- const triggerReStartServer = async (isDev, npmCmd, httpPort) => {
27
- if (triggerHandle.restart) {
28
- clearTimeout(triggerHandle.restart);
29
- }
30
- triggerHandle.restart = setTimeout(async () => {
31
- const token = sha256(process.env['DEV_TOKEN'] || '');
32
- const url = `http://127.0.0.1:${httpPort}/debug/shutdown?t=${token}`;
33
- await sendRequest(url, isDev ? 2 : 0);
34
- console.log('[dev-server] ReStart Server: ', url);
35
- isDev && runCmd(npmCmd);
36
- }, 500);
37
- };
38
-
39
- // refresh server for client code changes
40
- const triggerRefreshServer = async (isDev, httpPort) => {
41
- if (triggerHandle.refresh) {
42
- clearTimeout(triggerHandle.refresh);
43
- }
44
- triggerHandle.refresh = setTimeout(async () => {
45
- const token = sha256(process.env['DEV_TOKEN'] || '');
46
- const url = `http://127.0.0.1:${httpPort}/debug/refresh?t=${token}`;
47
- await sendRequest(url, isDev ? 2 : 0);
48
- console.log('[dev-server] Refresh Server: ', url);
49
- }, 500);
50
- };
51
-
52
- // watch server code changes
53
- const watchServerPlugin = (isDev, npmCmd, httpPort) => {
54
- return {
55
- name: 'watchServerPlugin',
56
- setup(build) {
57
- build.onEnd(async (res) => {
58
- // console.log(`Build meta data: `, res);
59
- console.log(`[dev-server] Build finished`);
60
- if (isDev) {
61
- await triggerReStartServer(isDev, npmCmd, httpPort);
62
- }
63
- });
64
- },
65
- };
66
- };
67
-
68
- // watch server code changes
69
- const watchServerLoader = async (isDev, npmCmd, httpPort, serverRootPath) => {
70
- const cmd = isDev ? esbuild.context : esbuild.build;
71
- const ctx = await cmd({
72
- entryPoints: ['apps/server/src/server-loader.ts'],
73
- // outdir: path.join(serverRootPath, 'server'),
74
- outfile: path.join(serverRootPath, 'server', 'server-loader.js'),
75
- platform: 'node',
76
- sourcemap: isDev ? 'inline' : false, // inline
77
- format: 'cjs',
78
- bundle: true,
79
- treeShaking: true,
80
- metafile: true,
81
- minify: !isDev,
82
- plugins: [watchServerPlugin(isDev, npmCmd, httpPort)],
83
- });
84
-
85
- isDev && (await ctx.watch());
86
- isDev && console.log('[dev-server] Watching...');
87
- };
88
-
89
- // watch server code changes
90
- const watchServer = async (isDev, npmCmd, httpPort, serverRootPath) => {
91
- const cmd = isDev ? esbuild.context : esbuild.build;
92
- const ctx = await cmd({
93
- entryPoints: ['apps/server/src/index.ts'],
94
- outdir: path.join(serverRootPath, 'server'),
95
- platform: 'node',
96
- sourcemap: isDev ? 'inline' : false, // inline
97
- format: 'cjs',
98
- bundle: true,
99
- treeShaking: true,
100
- metafile: true,
101
- external: ['better-sqlite3', 'nodemailer', 'pdfkit', 'sharp'],
102
- loader: { '.svg': 'text', '.glsl': 'text', '.png': 'file', '.gif': 'file', '.html': 'text' },
103
- minify: !isDev,
104
- plugins: [watchServerPlugin(isDev, npmCmd, httpPort)],
105
- });
106
-
107
- isDev && (await ctx.watch());
108
- isDev && console.log('[dev-server] Watching...');
109
- };
110
-
111
- // copy files to output directory
112
- const copyCache = new Map();
113
- const writeBuildTimeFiles = async (saved) => {
114
- if (!saved.webVersionFile) return;
115
- const buildTimeContent = JSON.stringify({ version: new Date().toISOString() }, null, 2) + '\n';
116
- const sourceBuildTimePath = path.join(saved.appDir, saved.webVersionFile);
117
- await fs.writeFile(sourceBuildTimePath, buildTimeContent, 'utf8');
118
- };
119
-
120
- const clientProcessOnEnd = async (saved) => {
121
- saved.indexHtml &&
122
- cpIndexHtml(
123
- saved.indexHtml,
124
- path.join(saved.outdir, 'index.html'),
125
- saved.appName,
126
- saved.isDev,
127
- saved.isMobile,
128
- saved.defaultThemeName,
129
- saved.outdirData,
130
- saved.outdirSub
131
- );
132
-
133
- const assets = saved['copyFiles'];
134
- if (assets) {
135
- for (oneDir of assets) {
136
- await copyFolder(copyCache, oneDir.from, oneDir.to, saved.isDev);
137
- }
138
- }
139
-
140
- if (saved.isDev) {
141
- await triggerRefreshServer(saved.isDev, saved.httpPort);
142
- }
143
- };
144
-
145
- // watch client code changes
146
- const watchClientPlugin = (saved) => {
147
- return {
148
- name: 'watchClientPlugin',
149
- setup(build) {
150
- build.onStart(async () => {
151
- await writeBuildTimeFiles(saved);
152
- });
153
-
154
- build.onEnd(async (res) => {
155
- // console.log(`Build meta data: `, res);
156
- console.log(`[dev-client:${saved.appName}] Build finished`);
157
- await clientProcessOnEnd(saved);
158
- });
159
- },
160
- };
161
- };
162
-
163
- // plugin for conditional code logic
164
- /*
165
- #if MOBILE && DEV
166
- console.log('this is mobile and dev');
167
- #endif
168
- */
169
- const ifPluginVars = {
170
- MOBILE: '',
171
- DEV: '',
172
- };
173
- const watchClient = async (saved, isDev, entryPoints, outbase) => {
174
- const cmd = isDev ? esbuild.context : esbuild.build;
175
- const ctx = await cmd({
176
- entryPoints,
177
- outdir: saved.outdir,
178
- outbase,
179
- // entryNames: '[name]-[hash]',
180
- platform: 'browser',
181
- sourcemap: isDev ? 'inline' : false, // inline
182
- format: 'iife',
183
- bundle: true,
184
- treeShaking: true,
185
- external: [],
186
- metafile: true,
187
- minify: !isDev,
188
- loader: { '.svg': 'text', '.glsl': 'text', '.png': 'file', '.gif': 'file', '.html': 'text' },
189
- assetNames: '/pub_assets/[name]-[hash]',
190
- publicPath: saved.outdirSub,
191
- jsxImportSource: 'lupine.web',
192
- jsx: 'automatic',
193
- target: ['chrome87'],
194
- plugins: [
195
- watchClientPlugin(saved),
196
- pluginIfelse(ifPluginVars),
197
- obfuscatePlugin(saved.isObfuscate, saved.skipObfuscateFiles || []),
198
- ],
199
- });
200
-
201
- isDev && (await ctx.watch());
202
- isDev && console.log(`[dev-client:${saved.appName}] Watching...`);
203
- };
204
-
205
- const watchApiPlugin = (isDev, httpPort) => {
206
- return {
207
- name: 'watchApiPlugin',
208
- setup(build) {
209
- build.onEnd(async (res) => {
210
- console.log(`[dev-api] Build finished`);
211
-
212
- if (isDev) {
213
- await triggerRefreshServer(isDev, httpPort);
214
- }
215
- });
216
- },
217
- };
218
- };
219
-
220
- const watchApi = async (saved, isDev, entryPoints) => {
221
- const cmd = isDev ? esbuild.context : esbuild.build;
222
- const ctx = await cmd({
223
- entryPoints,
224
- outdir: saved.outdirApi,
225
- // outbase,
226
- platform: 'node',
227
- sourcemap: isDev ? 'inline' : false, // inline
228
- format: 'cjs', // iife, cjs
229
- bundle: true,
230
- treeShaking: true,
231
- metafile: true,
232
- external: ['better-sqlite3', 'nodemailer', 'pdfkit', 'sharp'],
233
- loader: { '.svg': 'text', '.glsl': 'text', '.png': 'file', '.gif': 'file', '.html': 'text' },
234
- minify: !isDev,
235
- plugins: [watchApiPlugin(isDev, saved.httpPort)],
236
- });
237
-
238
- isDev && (await ctx.watch());
239
- isDev && console.log(`[dev-api:${saved.appName}] Watching...`);
240
- };
241
-
242
- const watchMarkdownPlugin = (saved) => {
243
- return {
244
- name: 'watchMarkdownPlugin',
245
- setup(build) {
246
- build.onEnd(async (res) => {
247
- // console.log(`Build meta data: `, res);
248
- console.log(`[dev-markdown:${saved.appName}] Build finished`);
249
- await markdownProcessOnEnd(saved.markdownEntryPoints.indir, saved.markdownEntryPoints.outdir);
250
- });
251
- },
252
- };
253
- };
254
-
255
- const watchMarkdown = async (saved, entryPoints) => {
256
- const cmd = saved.isDev ? esbuild.context : esbuild.build;
257
- const ctx = await cmd({
258
- entryPoints: [`${entryPoints.indir}/**/*.md`],
259
- outdir: entryPoints.outdir,
260
- write: false,
261
- loader: { '.md': 'empty' },
262
- plugins: [watchMarkdownPlugin({ ...saved, markdownEntryPoints: entryPoints })],
263
- });
264
-
265
- saved.isDev && (await ctx.watch());
266
- };
267
-
268
- const watchAdditionalFiles = async (saved, entryPoints) => {
269
- const cmd = saved.isDev ? esbuild.context : esbuild.build;
270
- const ctx = await cmd({
271
- entryPoints: entryPoints,
272
- outdir: 'dist/tmp',
273
- write: false,
274
- loader: { '.html': 'empty', '.css': 'empty', '.js': 'empty', '.md': 'empty' },
275
- plugins: [watchClientPlugin(saved)],
276
- });
277
-
278
- saved.isDev && (await ctx.watch());
279
- };
280
-
281
- // Add Server, API, Client and additional files entry points to esbuild
282
- const start = async () => {
283
- // Any code accessing process.env should be after loadEnv
284
- // process env files, "#!import .env" in .env file can be used to include another env file
285
- let envFile = process.argv.find((i) => i.startsWith('--env='))?.substring(6);
286
- // load env file, but don't overwrite existing env variables
287
- await loadEnv(envFile);
288
-
289
- const serverRootPathEnv = process.env['SERVER_ROOT_PATH'];
290
- if (!serverRootPathEnv) {
291
- console.error('SERVER_ROOT_PATH is not set');
292
- return 0;
293
- }
294
- const serverRootPath = path.resolve(serverRootPathEnv);
295
- await fs.mkdir(serverRootPath, { recursive: true });
296
- if (!(await pathExists(serverRootPath))) {
297
- console.error(`Can't create server root path: ${serverRootPath}`);
298
- return 0;
299
- }
300
-
301
- // command to start the server when source files are changed
302
- const npmCmd = process.argv.find((i) => i.startsWith('--cmd='))?.substring(6);
303
- const isDev = process.argv.find((i) => i === '--dev=1');
304
- const isMobile = process.argv.find((i) => i === '--mobile=1'); // when this changed, need to rebuild index.html
305
- const isObfuscate = !isDev && process.argv.find((i) => i === '--obfuscate=1');
306
- // this is for esbuild conditional compile
307
- ifPluginVars.DEV = isDev ? '1' : '';
308
- ifPluginVars.MOBILE = isMobile ? '1' : '';
309
-
310
- // All apps should be defined in .env file like this:
311
- // APPS=domain1.com,domain2.com
312
- const apps = (process.env['APPS'] || '').split(',');
313
-
314
- const httpPort = process.env['HTTP_PORT'];
315
- for (const app of apps) {
316
- const appJson = `apps/${app}/lupine.json`;
317
- const additionalFiles = [];
318
- const appCfg = await readJson(appJson);
319
- const appName = appCfg['name'];
320
- const appDir = path.dirname(appJson);
321
- if (appCfg['watchFiles']) {
322
- appCfg['watchFiles'].forEach((item) => additionalFiles.push(`${appDir}/${item}`));
323
- }
324
-
325
- // create data folder
326
- await fs.mkdir(`${serverRootPath}/${appName}_data`, { recursive: true });
327
-
328
- const saved = {
329
- isDev,
330
- isMobile,
331
- isObfuscate,
332
- defaultThemeName: 'light',
333
- appName,
334
- appDir,
335
- webVersionFile: appCfg['webVersionFile'],
336
- skipObfuscateFiles: (appCfg['skipObfuscateFiles'] || []).map((p) => path.normalize(p)),
337
- httpPort,
338
- serverRoot: serverRootPath,
339
- outdirWeb: `${serverRootPath}/${appName}_web`,
340
- outdirApi: `${serverRootPath}/${appName}_api`,
341
- outdirData: `${serverRootPath}/${appName}_data`,
342
- copyFiles: appCfg['copyFiles'].map((item) => ({
343
- from: `${appDir}/${item.from}`,
344
- to:
345
- item.type == 'data'
346
- ? `${serverRootPath}/${appName}_data/${item.to}`
347
- : `${serverRootPath}/${appName}_web/${item.to}`,
348
- })),
349
- };
350
-
351
- appCfg['webEntryPoints'].forEach((item, index) => {
352
- const entryPoint = `${appDir}/${item.index}`;
353
- const indexHtml = `${appDir}/${item.html}`;
354
- watchClient(
355
- {
356
- ...saved,
357
- outdirSub: item.outdir,
358
- outdir: `${serverRootPath}/${appName}_web/` + item.outdir,
359
- indexHtml,
360
- copyFiles: [],
361
- },
362
- isDev,
363
- [entryPoint],
364
- path.dirname(entryPoint)
365
- );
366
- additionalFiles.push(indexHtml);
367
- });
368
-
369
- if (appCfg['apiEntryPoint']) {
370
- const entryPointApi = `${appDir}/${appCfg['apiEntryPoint']}`;
371
- watchApi(saved, isDev, [entryPointApi]);
372
- }
373
- if (appCfg['markdownEntryPoints']) {
374
- const markdownEntryPoints = {
375
- indir: `${appDir}/${appCfg['markdownEntryPoints'].indir}`,
376
- outdir: `${appDir}/${appCfg['markdownEntryPoints'].outdir}`,
377
- };
378
- watchMarkdown(saved, markdownEntryPoints);
379
- }
380
- if (additionalFiles.length > 0) {
381
- // when some resources are changed, need to run command or refresh the server
382
- watchAdditionalFiles(saved, additionalFiles);
383
- }
384
- }
385
-
386
- watchServer(isDev, npmCmd, httpPort, serverRootPath);
387
- watchServerLoader(isDev, npmCmd, httpPort, serverRootPath);
388
- };
389
- start();