@pictogrammers/element-esbuild 0.0.1 → 0.0.3

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.
@@ -1,22 +1,92 @@
1
1
  #!/usr/bin/env node
2
- // Build
3
- console.log('build');
4
2
 
5
- // import { build } from 'esbuild';
6
- /*
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
+ import { build } from 'esbuild';
5
+
6
+ import { htmlDependentsPlugin } from '../scripts/htmlDependentsPlugin.ts';
7
+ import { rebuildNotifyPlugin } from '../scripts/rebuildNotifyPlugin.ts';
8
+ import { fileExists } from '../scripts/fileExists.ts';
9
+ import { copyFile } from 'node:fs/promises';
10
+ import { dirname, join } from 'node:path';
11
+ import { playgroundPlugin } from '../scripts/playgroundPlugin.ts';
12
+
13
+ const plugins = [htmlDependentsPlugin, rebuildNotifyPlugin];
14
+ const entryPoints: string[] = [];
15
+
16
+ const green = (text: string) => `\x1b[32m${text}\x1b[0m`;
17
+ const red = (text: string) => `\x1b[31m${text}\x1b[0m`;
18
+
19
+ const __filename = fileURLToPath(import.meta.url);
20
+ const __dirname = dirname(__filename);
21
+ const defaultDir = join(__dirname, '..', 'default');
22
+ const indexFile = 'index.html';
23
+ const distDir = 'dist';
24
+ const srcDir = 'src';
25
+ const componentsDir = 'components';
26
+ const configFile = 'element.config.ts';
27
+ const rootDir = process.cwd();
28
+ const buildDir = 'build';
29
+ const fullConfigPath = pathToFileURL(configFile);
30
+ if (!(await fileExists(configFile))) {
31
+ console.log(red('Missing element.config.ts in root.'), 'Add with content:');
32
+ console.log('export default {');
33
+ console.log(` namespace: 'hello',`);
34
+ console.log('}');
35
+ process.exit();
36
+ }
37
+
38
+ const config = await import(fullConfigPath.href);
39
+ const {
40
+ namespace,
41
+ } = config.default;
42
+
43
+ if (namespace) {
44
+ console.log(green('Building app...'));
45
+ entryPoints.push(`./${srcDir}/${componentsDir}/${namespace}/app/app.ts`);
46
+ } else {
47
+ // dynamically resolve all found components
48
+ entryPoints.push('playground-entry');
49
+ plugins.push(
50
+ playgroundPlugin({
51
+ after: async (namespaces: any[]) => {
52
+ // actually build index file instead of copying from dist
53
+ }
54
+ })
55
+ );
56
+ }
57
+
7
58
  build({
8
59
  entryPoints,
9
60
  bundle: true,
10
61
  platform: 'browser',
11
- outfile: './dist/main.js',
12
- sourcemap: true,
13
- target: 'esnext',
62
+ outfile: `./${buildDir}/main.js`,
63
+ sourcemap: false,
64
+ minify: true, // aka production
65
+ format: 'esm', // Use ES Modules
66
+ target: 'es2024', // Target ES6 syntax
14
67
  loader: {
15
68
  '.html': 'text',
16
69
  '.css': 'text'
17
70
  },
71
+ plugins,
72
+ }).then(async () => {
73
+ if (await fileExists(join(rootDir, distDir, indexFile))) {
74
+ await copyFile(join(rootDir, distDir, indexFile), join(rootDir, buildDir, indexFile));
75
+ }
76
+ // Handle favicon.svg
77
+ const faviconSvg = 'favicon.svg';
78
+ if (await fileExists(join(rootDir, srcDir, faviconSvg))) {
79
+ await copyFile(
80
+ join(rootDir, srcDir, faviconSvg),
81
+ join(rootDir, buildDir, faviconSvg)
82
+ );
83
+ } else {
84
+ await copyFile(
85
+ join(defaultDir, faviconSvg),
86
+ join(rootDir, buildDir, faviconSvg)
87
+ );
88
+ }
18
89
  }).catch((err) => {
19
90
  process.stderr.write(err.stderr);
20
91
  process.exit(1);
21
92
  });
22
- */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pictogrammers/element-esbuild",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "description": "Element esbuild",
6
6
  "homepage": "https://github.com/Pictogrammers/Element-esbuild#readme",