frontfire 0.1.0 → 0.1.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.
- package/README.md +16 -1
- package/package.json +8 -1
- package/src/FrontFire.js +135 -0
- package/src/index.js +12 -98
- package/.idea/infrontjs-frontfire.iml +0 -8
- package/.idea/modules.xml +0 -8
- package/.idea/php.xml +0 -18
- package/.idea/vcs.xml +0 -6
package/README.md
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
#
|
|
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,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frontfire",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
+
"start": "node src/index.js",
|
|
7
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
@@ -18,8 +19,14 @@
|
|
|
18
19
|
},
|
|
19
20
|
"homepage": "https://github.com/infrontjs/frontfire#readme",
|
|
20
21
|
"dependencies": {
|
|
22
|
+
"chalk": "^5.2.0",
|
|
23
|
+
"commander": "^10.0.0",
|
|
24
|
+
"conf": "^11.0.1",
|
|
21
25
|
"esbuild": "^0.17.4",
|
|
22
26
|
"esbuild-copy-static-files": "^0.1.0",
|
|
23
27
|
"esbuild-plugin-copy": "^2.0.2"
|
|
28
|
+
},
|
|
29
|
+
"bin": {
|
|
30
|
+
"frontfire": "src/index.js"
|
|
24
31
|
}
|
|
25
32
|
}
|
package/src/FrontFire.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
const esbuild = require( "esbuild" );
|
|
2
|
+
const { copy } = require( "esbuild-plugin-copy" );
|
|
3
|
+
const copyStaticFiles = require( "esbuild-copy-static-files" );
|
|
4
|
+
const http = require( "node:http" );
|
|
5
|
+
const fs = require( 'node:fs' );
|
|
6
|
+
const path = require( 'node:path' );
|
|
7
|
+
|
|
8
|
+
const rootBuildDir = 'build';
|
|
9
|
+
|
|
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
|
+
}
|
|
37
|
+
|
|
38
|
+
async function frontFire( isWatch )
|
|
39
|
+
{
|
|
40
|
+
let opts = {
|
|
41
|
+
// esbuild options
|
|
42
|
+
bundle: true,
|
|
43
|
+
sourcemap: true,
|
|
44
|
+
minify: isWatch ? false : true,
|
|
45
|
+
logLevel: isWatch ? "info" : "error",
|
|
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}`,
|
|
48
|
+
loader: {
|
|
49
|
+
".html" : "text",
|
|
50
|
+
".png" : "file"
|
|
51
|
+
},
|
|
52
|
+
plugins: [
|
|
53
|
+
copy({
|
|
54
|
+
resolveFrom : 'cwd',
|
|
55
|
+
assets: [
|
|
56
|
+
{
|
|
57
|
+
from: rootFilesToCopy,
|
|
58
|
+
to: [ isWatch ? `${rootBuildDir}${path.sep}debug` : `${rootBuildDir}${path.sep}release` ]
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}),
|
|
62
|
+
copyStaticFiles({
|
|
63
|
+
src: 'src/assets',
|
|
64
|
+
dest: isWatch ? `${rootBuildDir}${path.sep}debug${path.sep}assets` : `${rootBuildDir}${path.sep}release${path.sep}assets`,
|
|
65
|
+
dereference: true,
|
|
66
|
+
errorOnExist: false,
|
|
67
|
+
preserveTimestamps: true,
|
|
68
|
+
recursive: true
|
|
69
|
+
})
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if ( true === isWatch )
|
|
75
|
+
{
|
|
76
|
+
opts[ "banner" ] = {
|
|
77
|
+
js: "(() => { (new EventSource(\"/esbuild\")).addEventListener('change', () => location.reload()); })();"
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let ctx = await esbuild.context( opts );
|
|
82
|
+
|
|
83
|
+
if ( true === isWatch )
|
|
84
|
+
{
|
|
85
|
+
await ctx.watch();
|
|
86
|
+
let { host, port } = await ctx.serve(
|
|
87
|
+
{
|
|
88
|
+
servedir : `.${path.sep}${rootBuildDir}${path.sep}debug`
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Then start a proxy server on port 3000
|
|
93
|
+
http.createServer((req, res) => {
|
|
94
|
+
|
|
95
|
+
const options = {
|
|
96
|
+
hostname: host,
|
|
97
|
+
port: port,
|
|
98
|
+
path: req.url,
|
|
99
|
+
method: req.method,
|
|
100
|
+
headers: req.headers,
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Check if path is a valid state route
|
|
104
|
+
// then pass it as "index.html" to the server
|
|
105
|
+
|
|
106
|
+
// Forward each incoming request to esbuild
|
|
107
|
+
const proxyReq = http.request(options, proxyRes => {
|
|
108
|
+
// If esbuild returns "not found", send a custom 404 page
|
|
109
|
+
if (proxyRes.statusCode === 404) {
|
|
110
|
+
res.writeHead(404, { 'Content-Type': 'text/html' })
|
|
111
|
+
res.end('<h1>A custom 404 page</h1>')
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Otherwise, forward the response from esbuild to the client
|
|
116
|
+
res.writeHead(proxyRes.statusCode, proxyRes.headers)
|
|
117
|
+
|
|
118
|
+
proxyRes.pipe(res, { end: true })
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// Forward the body of the request to esbuild
|
|
122
|
+
req.pipe(proxyReq, { end: true })
|
|
123
|
+
|
|
124
|
+
}).listen(3000);
|
|
125
|
+
|
|
126
|
+
console.log( '> InfrontJS:http://localhost:3000' );
|
|
127
|
+
}
|
|
128
|
+
else
|
|
129
|
+
{
|
|
130
|
+
await ctx.rebuild();
|
|
131
|
+
ctx.dispose();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports = frontFire;
|
package/src/index.js
CHANGED
|
@@ -1,102 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import http from 'node:http';
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
const { program } = require( 'commander' );
|
|
3
|
+
const frontFire = require( "./FrontFire.js" );
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
program
|
|
6
|
+
.command( 'run-dev' )
|
|
7
|
+
.description( 'Running development server.' )
|
|
8
|
+
.action( function() {frontFire( true ); } );
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
program
|
|
11
|
+
.command( 'build' )
|
|
12
|
+
.description( 'Building for production.' )
|
|
13
|
+
.action( function() {frontFire( false ); } );
|
|
10
14
|
|
|
11
|
-
let opts = {
|
|
12
|
-
// esbuild options
|
|
13
|
-
bundle: true,
|
|
14
|
-
sourcemap: true,
|
|
15
|
-
minify: isWatch ? false : true,
|
|
16
|
-
logLevel: isWatch ? "info" : "error",
|
|
17
|
-
entryPoints : [ 'src/main.js', 'src/style.css' ],
|
|
18
|
-
outdir : isWatch ? `${rootBuildDir}/debug/bundles/` : `${rootBuildDir}/release/bundles`,
|
|
19
|
-
loader: {
|
|
20
|
-
".html" : "text"
|
|
21
|
-
},
|
|
22
|
-
plugins: [
|
|
23
|
-
copy({
|
|
24
|
-
resolveFrom : 'cwd',
|
|
25
|
-
assets: [
|
|
26
|
-
{
|
|
27
|
-
from: [ 'src/index.html' ],
|
|
28
|
-
to: [ isWatch ? `${rootBuildDir}/debug/` : `${rootBuildDir}/release/` ]
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}),
|
|
32
|
-
copyStaticFiles({
|
|
33
|
-
src: 'src/assets',
|
|
34
|
-
dest: isWatch ? `${rootBuildDir}/debug/assets` : `${rootBuildDir}/release/assets`,
|
|
35
|
-
dereference: true,
|
|
36
|
-
errorOnExist: false,
|
|
37
|
-
preserveTimestamps: true,
|
|
38
|
-
recursive: true
|
|
39
|
-
})
|
|
40
|
-
]
|
|
41
15
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if ( true === isWatch )
|
|
45
|
-
{
|
|
46
|
-
opts[ "banner" ] = {
|
|
47
|
-
js: "(() => { (new EventSource(\"/esbuild\")).addEventListener('change', () => location.reload()); })();"
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let ctx = await esbuild.context( opts );
|
|
52
|
-
|
|
53
|
-
if ( true === isWatch )
|
|
54
|
-
{
|
|
55
|
-
await ctx.watch();
|
|
56
|
-
let { host, port } = await ctx.serve(
|
|
57
|
-
{
|
|
58
|
-
servedir : `./${rootBuildDir}/debug`
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
// Then start a proxy server on port 3000
|
|
63
|
-
http.createServer((req, res) => {
|
|
64
|
-
|
|
65
|
-
const options = {
|
|
66
|
-
hostname: host,
|
|
67
|
-
port: port,
|
|
68
|
-
path: req.url,
|
|
69
|
-
method: req.method,
|
|
70
|
-
headers: req.headers,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Check if path is a valid state route
|
|
74
|
-
// then pass it as "index.html" to the server
|
|
75
|
-
|
|
76
|
-
// Forward each incoming request to esbuild
|
|
77
|
-
const proxyReq = http.request(options, proxyRes => {
|
|
78
|
-
// If esbuild returns "not found", send a custom 404 page
|
|
79
|
-
if (proxyRes.statusCode === 404) {
|
|
80
|
-
res.writeHead(404, { 'Content-Type': 'text/html' })
|
|
81
|
-
res.end('<h1>A custom 404 page</h1>')
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Otherwise, forward the response from esbuild to the client
|
|
86
|
-
res.writeHead(proxyRes.statusCode, proxyRes.headers)
|
|
87
|
-
|
|
88
|
-
proxyRes.pipe(res, { end: true })
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
// Forward the body of the request to esbuild
|
|
92
|
-
req.pipe(proxyReq, { end: true })
|
|
93
|
-
|
|
94
|
-
}).listen(3000);
|
|
95
|
-
|
|
96
|
-
console.log( '> InfrontJS:http://localhost:3000' );
|
|
97
|
-
}
|
|
98
|
-
else
|
|
99
|
-
{
|
|
100
|
-
await ctx.rebuild();
|
|
101
|
-
ctx.dispose();
|
|
102
|
-
}
|
|
16
|
+
program.parse();
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$" />
|
|
5
|
-
<orderEntry type="inheritedJdk" />
|
|
6
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
-
</component>
|
|
8
|
-
</module>
|
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/infrontjs-frontfire.iml" filepath="$PROJECT_DIR$/.idea/infrontjs-frontfire.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
package/.idea/php.xml
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="MessDetectorOptionsConfiguration">
|
|
4
|
-
<option name="transferred" value="true" />
|
|
5
|
-
</component>
|
|
6
|
-
<component name="PHPCSFixerOptionsConfiguration">
|
|
7
|
-
<option name="transferred" value="true" />
|
|
8
|
-
</component>
|
|
9
|
-
<component name="PHPCodeSnifferOptionsConfiguration">
|
|
10
|
-
<option name="transferred" value="true" />
|
|
11
|
-
</component>
|
|
12
|
-
<component name="PhpStanOptionsConfiguration">
|
|
13
|
-
<option name="transferred" value="true" />
|
|
14
|
-
</component>
|
|
15
|
-
<component name="PsalmOptionsConfiguration">
|
|
16
|
-
<option name="transferred" value="true" />
|
|
17
|
-
</component>
|
|
18
|
-
</project>
|