frontfire 0.1.0 → 0.1.1
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/package.json +8 -1
- package/src/FrontFire.js +107 -0
- package/src/index.js +19 -0
- 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/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frontfire",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
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,107 @@
|
|
|
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
|
+
|
|
6
|
+
const rootBuildDir = 'build';
|
|
7
|
+
|
|
8
|
+
// @todo Add PATH_SEPERATOR for paths
|
|
9
|
+
|
|
10
|
+
async function frontFire( isWatch )
|
|
11
|
+
{
|
|
12
|
+
let opts = {
|
|
13
|
+
// esbuild options
|
|
14
|
+
bundle: true,
|
|
15
|
+
sourcemap: true,
|
|
16
|
+
minify: isWatch ? false : true,
|
|
17
|
+
logLevel: isWatch ? "info" : "error",
|
|
18
|
+
entryPoints : [ 'src/main.js', 'src/style.css' ],
|
|
19
|
+
outdir : isWatch ? `${rootBuildDir}/debug/bundles/` : `${rootBuildDir}/release/bundles`,
|
|
20
|
+
loader: {
|
|
21
|
+
".html" : "text",
|
|
22
|
+
".png" : "file"
|
|
23
|
+
},
|
|
24
|
+
plugins: [
|
|
25
|
+
copy({
|
|
26
|
+
resolveFrom : 'cwd',
|
|
27
|
+
assets: [
|
|
28
|
+
{
|
|
29
|
+
from: [ 'src/index.html' ],
|
|
30
|
+
to: [ isWatch ? `${rootBuildDir}/debug/` : `${rootBuildDir}/release/` ]
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}),
|
|
34
|
+
copyStaticFiles({
|
|
35
|
+
src: 'src/assets',
|
|
36
|
+
dest: isWatch ? `${rootBuildDir}/debug/assets` : `${rootBuildDir}/release/assets`,
|
|
37
|
+
dereference: true,
|
|
38
|
+
errorOnExist: false,
|
|
39
|
+
preserveTimestamps: true,
|
|
40
|
+
recursive: true
|
|
41
|
+
})
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if ( true === isWatch )
|
|
47
|
+
{
|
|
48
|
+
opts[ "banner" ] = {
|
|
49
|
+
js: "(() => { (new EventSource(\"/esbuild\")).addEventListener('change', () => location.reload()); })();"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let ctx = await esbuild.context( opts );
|
|
54
|
+
|
|
55
|
+
if ( true === isWatch )
|
|
56
|
+
{
|
|
57
|
+
await ctx.watch();
|
|
58
|
+
let { host, port } = await ctx.serve(
|
|
59
|
+
{
|
|
60
|
+
servedir : `./${rootBuildDir}/debug`
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// Then start a proxy server on port 3000
|
|
65
|
+
http.createServer((req, res) => {
|
|
66
|
+
|
|
67
|
+
const options = {
|
|
68
|
+
hostname: host,
|
|
69
|
+
port: port,
|
|
70
|
+
path: req.url,
|
|
71
|
+
method: req.method,
|
|
72
|
+
headers: req.headers,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Check if path is a valid state route
|
|
76
|
+
// then pass it as "index.html" to the server
|
|
77
|
+
|
|
78
|
+
// Forward each incoming request to esbuild
|
|
79
|
+
const proxyReq = http.request(options, proxyRes => {
|
|
80
|
+
// If esbuild returns "not found", send a custom 404 page
|
|
81
|
+
if (proxyRes.statusCode === 404) {
|
|
82
|
+
res.writeHead(404, { 'Content-Type': 'text/html' })
|
|
83
|
+
res.end('<h1>A custom 404 page</h1>')
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Otherwise, forward the response from esbuild to the client
|
|
88
|
+
res.writeHead(proxyRes.statusCode, proxyRes.headers)
|
|
89
|
+
|
|
90
|
+
proxyRes.pipe(res, { end: true })
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
// Forward the body of the request to esbuild
|
|
94
|
+
req.pipe(proxyReq, { end: true })
|
|
95
|
+
|
|
96
|
+
}).listen(3000);
|
|
97
|
+
|
|
98
|
+
console.log( '> InfrontJS:http://localhost:3000' );
|
|
99
|
+
}
|
|
100
|
+
else
|
|
101
|
+
{
|
|
102
|
+
await ctx.rebuild();
|
|
103
|
+
ctx.dispose();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
module.exports = frontFire;
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
const { program } = require( 'commander' );
|
|
3
|
+
const frontFire = require( "./FrontFire.js" );
|
|
4
|
+
|
|
5
|
+
program
|
|
6
|
+
.command( 'run-dev' )
|
|
7
|
+
.description( 'Running development server.' )
|
|
8
|
+
.action( function() {frontFire( true ); } );
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.command( 'build' )
|
|
12
|
+
.description( 'Building for production.' )
|
|
13
|
+
.action( function() {frontFire( false ); } );
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
program.parse();
|
|
17
|
+
|
|
18
|
+
/*
|
|
1
19
|
import * as esbuild from 'esbuild';
|
|
2
20
|
import { copy } from "esbuild-plugin-copy";
|
|
3
21
|
import copyStaticFiles from "esbuild-copy-static-files";
|
|
@@ -100,3 +118,4 @@ else
|
|
|
100
118
|
await ctx.rebuild();
|
|
101
119
|
ctx.dispose();
|
|
102
120
|
}
|
|
121
|
+
*/
|
|
@@ -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>
|