@pictogrammers/element-esbuild 0.0.1 → 0.0.2

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