frontfire 0.1.1 → 0.1.4

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/README.md CHANGED
@@ -1 +1,16 @@
1
- # frontfire
1
+ # Frontfire
2
+
3
+ Welcome to Frontfire. Frontfire is the development and build environment created for InfrontJS projects.
4
+
5
+ It is entirely built upon the great esbuild ecosystem.
6
+
7
+ ## Logic
8
+
9
+ Structure
10
+
11
+ - src/assets/**/*
12
+ - src/app/main.js
13
+ - src/app/app.css
14
+ - src/index.html
15
+
16
+ Entrypoint for building is main.js and app.css
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontfire",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/FrontFire.js CHANGED
@@ -2,10 +2,38 @@ const esbuild = require( "esbuild" );
2
2
  const { copy } = require( "esbuild-plugin-copy" );
3
3
  const copyStaticFiles = require( "esbuild-copy-static-files" );
4
4
  const http = require( "node:http" );
5
+ const fs = require( 'node:fs' );
6
+ const path = require( 'node:path' );
5
7
 
6
8
  const rootBuildDir = 'build';
7
9
 
8
- // @todo Add PATH_SEPERATOR for paths
10
+ try
11
+ {
12
+ if ( fs.statSync( rootBuildDir ) )
13
+ {
14
+ console.log( "Cleaning build directory: " + rootBuildDir );
15
+ fs.rmSync( rootBuildDir, { recursive: true, force: true } );
16
+ }
17
+ }
18
+ catch( ie )
19
+ {
20
+ // Fail silently
21
+ console.error( ie );
22
+ }
23
+
24
+ const rootFiles = fs.readdirSync( `src${path.sep}`, { withFileTypes : true } );
25
+ const rootFilesToCopy = [];
26
+ for ( let ri = 0; ri < rootFiles.length; ri++ )
27
+ {
28
+ if ( rootFiles[ ri ].isDirectory() )
29
+ {
30
+ continue;
31
+ }
32
+
33
+ // Note
34
+ // It seems that the copy plugin requires normal slashes no matter what OS we are on
35
+ rootFilesToCopy.push( `src/` + rootFiles[ ri ].name );
36
+ }
9
37
 
10
38
  async function frontFire( isWatch )
11
39
  {
@@ -15,8 +43,8 @@ async function frontFire( isWatch )
15
43
  sourcemap: true,
16
44
  minify: isWatch ? false : true,
17
45
  logLevel: isWatch ? "info" : "error",
18
- entryPoints : [ 'src/main.js', 'src/style.css' ],
19
- outdir : isWatch ? `${rootBuildDir}/debug/bundles/` : `${rootBuildDir}/release/bundles`,
46
+ entryPoints : [ `src${path.sep}app${path.sep}main.js`, `src${path.sep}app${path.sep}app.css` ],
47
+ outdir : isWatch ? `${rootBuildDir}${path.sep}debug${path.sep}app${path.sep}` : `${rootBuildDir}${path.sep}release${path.sep}app${path.sep}`,
20
48
  loader: {
21
49
  ".html" : "text",
22
50
  ".png" : "file"
@@ -26,14 +54,14 @@ async function frontFire( isWatch )
26
54
  resolveFrom : 'cwd',
27
55
  assets: [
28
56
  {
29
- from: [ 'src/index.html' ],
30
- to: [ isWatch ? `${rootBuildDir}/debug/` : `${rootBuildDir}/release/` ]
57
+ from: rootFilesToCopy,
58
+ to: [ isWatch ? `${rootBuildDir}${path.sep}debug` : `${rootBuildDir}${path.sep}release` ]
31
59
  }
32
60
  ]
33
61
  }),
34
62
  copyStaticFiles({
35
63
  src: 'src/assets',
36
- dest: isWatch ? `${rootBuildDir}/debug/assets` : `${rootBuildDir}/release/assets`,
64
+ dest: isWatch ? `${rootBuildDir}${path.sep}debug${path.sep}assets` : `${rootBuildDir}${path.sep}release${path.sep}assets`,
37
65
  dereference: true,
38
66
  errorOnExist: false,
39
67
  preserveTimestamps: true,
@@ -46,7 +74,7 @@ async function frontFire( isWatch )
46
74
  if ( true === isWatch )
47
75
  {
48
76
  opts[ "banner" ] = {
49
- js: "(() => { (new EventSource(\"/esbuild\")).addEventListener('change', () => location.reload()); })();"
77
+ js: "(() => { (new EventSource(\"/esbuild\")).addEventListener('change', () => location.reload() ); })();"
50
78
  };
51
79
  }
52
80
 
@@ -54,13 +82,31 @@ async function frontFire( isWatch )
54
82
 
55
83
  if ( true === isWatch )
56
84
  {
85
+ console.log( "Adding additional watcher..." );
86
+ fs.watchFile( `src${path.sep}index.html`, async ( curr, prev ) =>
87
+ {
88
+ console.log( "Index.html changed..." );
89
+ const result = await ctx.rebuild();
90
+ console.log( result );
91
+ });
57
92
  await ctx.watch();
58
93
  let { host, port } = await ctx.serve(
59
94
  {
60
- servedir : `./${rootBuildDir}/debug`
95
+ servedir : `.${path.sep}${rootBuildDir}${path.sep}debug`
61
96
  }
62
97
  );
63
98
 
99
+
100
+ let sseResponse = null;
101
+ /*
102
+ // DOES NOT WORK
103
+ setInterval( () =>
104
+ {
105
+ console.log( "Sending sse..." );
106
+ sseResponse.write( 'data: esbuild' );
107
+ }, 5000 );
108
+ */
109
+
64
110
  // Then start a proxy server on port 3000
65
111
  http.createServer((req, res) => {
66
112
 
@@ -72,6 +118,7 @@ async function frontFire( isWatch )
72
118
  headers: req.headers,
73
119
  }
74
120
 
121
+
75
122
  // Check if path is a valid state route
76
123
  // then pass it as "index.html" to the server
77
124
 
@@ -87,8 +134,13 @@ async function frontFire( isWatch )
87
134
  // Otherwise, forward the response from esbuild to the client
88
135
  res.writeHead(proxyRes.statusCode, proxyRes.headers)
89
136
 
137
+ if ( req.url === '/esbuild' )
138
+ {
139
+ sseResponse = res;
140
+ }
141
+
90
142
  proxyRes.pipe(res, { end: true })
91
- })
143
+ });
92
144
 
93
145
  // Forward the body of the request to esbuild
94
146
  req.pipe(proxyReq, { end: true })
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #! /usr/bin/env node
1
+ #! /usr/bin/env node
2
2
  const { program } = require( 'commander' );
3
3
  const frontFire = require( "./FrontFire.js" );
4
4
 
@@ -14,108 +14,3 @@ program
14
14
 
15
15
 
16
16
  program.parse();
17
-
18
- /*
19
- import * as esbuild from 'esbuild';
20
- import { copy } from "esbuild-plugin-copy";
21
- import copyStaticFiles from "esbuild-copy-static-files";
22
- import http from 'node:http';
23
-
24
- const isWatch = process.argv.includes('-w');
25
- const rootBuildDir = 'build';
26
-
27
- // @todo Add PATH_SEPERATOR for paths
28
-
29
- let opts = {
30
- // esbuild options
31
- bundle: true,
32
- sourcemap: true,
33
- minify: isWatch ? false : true,
34
- logLevel: isWatch ? "info" : "error",
35
- entryPoints : [ 'src/main.js', 'src/style.css' ],
36
- outdir : isWatch ? `${rootBuildDir}/debug/bundles/` : `${rootBuildDir}/release/bundles`,
37
- loader: {
38
- ".html" : "text"
39
- },
40
- plugins: [
41
- copy({
42
- resolveFrom : 'cwd',
43
- assets: [
44
- {
45
- from: [ 'src/index.html' ],
46
- to: [ isWatch ? `${rootBuildDir}/debug/` : `${rootBuildDir}/release/` ]
47
- }
48
- ]
49
- }),
50
- copyStaticFiles({
51
- src: 'src/assets',
52
- dest: isWatch ? `${rootBuildDir}/debug/assets` : `${rootBuildDir}/release/assets`,
53
- dereference: true,
54
- errorOnExist: false,
55
- preserveTimestamps: true,
56
- recursive: true
57
- })
58
- ]
59
-
60
- };
61
-
62
- if ( true === isWatch )
63
- {
64
- opts[ "banner" ] = {
65
- js: "(() => { (new EventSource(\"/esbuild\")).addEventListener('change', () => location.reload()); })();"
66
- };
67
- }
68
-
69
- let ctx = await esbuild.context( opts );
70
-
71
- if ( true === isWatch )
72
- {
73
- await ctx.watch();
74
- let { host, port } = await ctx.serve(
75
- {
76
- servedir : `./${rootBuildDir}/debug`
77
- }
78
- );
79
-
80
- // Then start a proxy server on port 3000
81
- http.createServer((req, res) => {
82
-
83
- const options = {
84
- hostname: host,
85
- port: port,
86
- path: req.url,
87
- method: req.method,
88
- headers: req.headers,
89
- }
90
-
91
- // Check if path is a valid state route
92
- // then pass it as "index.html" to the server
93
-
94
- // Forward each incoming request to esbuild
95
- const proxyReq = http.request(options, proxyRes => {
96
- // If esbuild returns "not found", send a custom 404 page
97
- if (proxyRes.statusCode === 404) {
98
- res.writeHead(404, { 'Content-Type': 'text/html' })
99
- res.end('<h1>A custom 404 page</h1>')
100
- return
101
- }
102
-
103
- // Otherwise, forward the response from esbuild to the client
104
- res.writeHead(proxyRes.statusCode, proxyRes.headers)
105
-
106
- proxyRes.pipe(res, { end: true })
107
- })
108
-
109
- // Forward the body of the request to esbuild
110
- req.pipe(proxyReq, { end: true })
111
-
112
- }).listen(3000);
113
-
114
- console.log( '> InfrontJS:http://localhost:3000' );
115
- }
116
- else
117
- {
118
- await ctx.rebuild();
119
- ctx.dispose();
120
- }
121
- */