frontfire 0.7.0 → 0.8.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 +6 -2
- package/src/DefaultConfig.js +0 -9
- package/src/FrontFire.js +1 -1
- package/src/index.js +110 -23
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frontfire",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"start": "node src/index.js",
|
|
9
|
+
"start -version": "node src/index.js version",
|
|
10
|
+
"create in test": "node src/index.js create \"Hello World\"",
|
|
9
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
12
|
},
|
|
11
13
|
"repository": {
|
|
@@ -23,6 +25,7 @@
|
|
|
23
25
|
"chalk": "^5.2.0",
|
|
24
26
|
"commander": "^10.0.0",
|
|
25
27
|
"conf": "^11.0.1",
|
|
28
|
+
"download-git-repo": "^3.0.2",
|
|
26
29
|
"ejs": "^3.1.10",
|
|
27
30
|
"esbuild": "^0.19.5",
|
|
28
31
|
"esbuild-copy-static-files": "^0.1.0",
|
|
@@ -31,7 +34,8 @@
|
|
|
31
34
|
"lodash": "^4.17.21",
|
|
32
35
|
"luxon": "^3.5.0",
|
|
33
36
|
"php-server": "^1.0.0",
|
|
34
|
-
"prettier": "^2.8.4"
|
|
37
|
+
"prettier": "^2.8.4",
|
|
38
|
+
"slugify": "^1.6.6"
|
|
35
39
|
},
|
|
36
40
|
"bin": {
|
|
37
41
|
"frontfire": "src/index.js"
|
package/src/DefaultConfig.js
CHANGED
|
@@ -48,14 +48,6 @@ for ( let ri = 0; ri < rootFiles.length; ri++ )
|
|
|
48
48
|
|
|
49
49
|
const buildDir = `build`;
|
|
50
50
|
const entryPoints = [
|
|
51
|
-
/*
|
|
52
|
-
"src/app/main.js",
|
|
53
|
-
"src/app/main.css"
|
|
54
|
-
*/
|
|
55
|
-
/*
|
|
56
|
-
path.resolve( './src/app/main.js' ),
|
|
57
|
-
path.resolve( './src/app/main.css' )
|
|
58
|
-
*/
|
|
59
51
|
`./src/app/main.js`,
|
|
60
52
|
`./src/app/main.css`
|
|
61
53
|
];
|
|
@@ -139,7 +131,6 @@ export default {
|
|
|
139
131
|
recursive: true
|
|
140
132
|
})
|
|
141
133
|
]
|
|
142
|
-
|
|
143
134
|
}
|
|
144
135
|
}
|
|
145
136
|
};
|
package/src/FrontFire.js
CHANGED
|
@@ -127,7 +127,7 @@ export default async function frontFire( isWatch, cfg = {} )
|
|
|
127
127
|
|
|
128
128
|
// CACHEBREAK
|
|
129
129
|
let indexContent = fs.readFileSync( `${rootBuildDir}${path.sep}release${path.sep}index.html`, { encoding: 'utf8', flag: 'r' } );
|
|
130
|
-
const changedContent = indexContent.replace( /
|
|
130
|
+
const changedContent = indexContent.replace( /INFRONTCACHEBREAK/g, (DateTime.now()).valueOf() );
|
|
131
131
|
fs.writeFileSync( `${rootBuildDir}${path.sep}release${path.sep}index.html`, changedContent );
|
|
132
132
|
}
|
|
133
133
|
};
|
package/src/index.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
|
-
import { readdir, readFile } from 'node:fs/promises';
|
|
4
|
+
import { readdir, readFile, writeFile, unlink } from 'node:fs/promises';
|
|
5
5
|
import ejs from "ejs";
|
|
6
6
|
import chalk from "chalk";
|
|
7
|
+
import download from "download-git-repo";
|
|
8
|
+
import { promisify } from "util";
|
|
9
|
+
import { exec } from "child_process";
|
|
10
|
+
import pkg from "./../package.json" with { type: "json" };
|
|
7
11
|
|
|
8
12
|
import _ from "lodash";
|
|
9
13
|
import prettier from "prettier";
|
|
10
14
|
import { program } from "commander";
|
|
11
15
|
import path from "node:path";
|
|
16
|
+
import { createInterface } from "readline";
|
|
17
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
18
|
+
import slugify from "slugify";
|
|
12
19
|
|
|
13
20
|
import frontFire from "./FrontFire.js";
|
|
14
21
|
import defaultConfig from "./DefaultConfig.js";
|
|
@@ -20,8 +27,19 @@ import stateTemplate from "./templates/state-template.html.js";
|
|
|
20
27
|
import poIndex from "./templates/po-index.js";
|
|
21
28
|
import dictTemplate from "./templates/dictionary.js";
|
|
22
29
|
|
|
30
|
+
async function askYesNo(question) {
|
|
31
|
+
const rl = createInterface({ input, output });
|
|
32
|
+
const answer = await new Promise((resolve) => {
|
|
33
|
+
rl.question(question, (ans) => resolve(ans.trim()));
|
|
34
|
+
});
|
|
35
|
+
rl.close();
|
|
36
|
+
return /^(y|yes)$/i.test(answer);
|
|
37
|
+
}
|
|
38
|
+
|
|
23
39
|
async function performInit()
|
|
24
40
|
{
|
|
41
|
+
const { default: defaultConfig } = await import("./DefaultConfig.js" );
|
|
42
|
+
|
|
25
43
|
// Deep Copy
|
|
26
44
|
const initConfig = JSON.parse( JSON.stringify( defaultConfig ) );
|
|
27
45
|
|
|
@@ -45,26 +63,67 @@ async function performInit()
|
|
|
45
63
|
}
|
|
46
64
|
}
|
|
47
65
|
|
|
48
|
-
async function createInfrontJsStarter( appName
|
|
66
|
+
async function createInfrontJsStarter( appName, appPath )
|
|
49
67
|
{
|
|
68
|
+
// Callback → Promise
|
|
69
|
+
const downloadAsync = promisify(download);
|
|
70
|
+
|
|
71
|
+
async function downloadRepo(repo, targetDir) {
|
|
72
|
+
try {
|
|
73
|
+
await downloadAsync(repo, targetDir, { clone: false });
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.error("❌ Fehler beim Laden des Repos:", err);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function updatePackageName(newName, packagePath = "./package.json") {
|
|
80
|
+
try {
|
|
81
|
+
const fullPath = path.resolve(packagePath);
|
|
82
|
+
|
|
83
|
+
// read package.json
|
|
84
|
+
const data = await readFile(fullPath, "utf-8");
|
|
85
|
+
const pkg = JSON.parse(data);
|
|
86
|
+
|
|
87
|
+
// replace if it matches the source name
|
|
88
|
+
if (pkg.name === "infrontjs-starter") {
|
|
89
|
+
pkg.name = newName;
|
|
90
|
+
|
|
91
|
+
await writeFile(fullPath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
|
|
92
|
+
} else {
|
|
93
|
+
console.log(`ℹ️ package.json name is not "infrontjs-starter" (found "${pkg.name}"), no change made.`);
|
|
94
|
+
}
|
|
95
|
+
} catch (err) {
|
|
96
|
+
console.error("❌ Failed to update package.json:", err);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
50
101
|
// Deep Copy
|
|
102
|
+
/*
|
|
51
103
|
const initConfig = JSON.parse( JSON.stringify( defaultConfig ) );
|
|
52
104
|
|
|
53
105
|
_.unset( initConfig, 'debug.esbuild.plugins' );
|
|
54
106
|
_.unset( initConfig, 'release.esbuild.plugins' );
|
|
107
|
+
*/
|
|
55
108
|
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
}
|
|
109
|
+
await downloadRepo("github:infrontjs/starter", appPath );
|
|
110
|
+
await updatePackageName( appName, `${appPath}/package.json` );
|
|
111
|
+
await unlink( `${appPath}/LICENSE` );
|
|
60
112
|
|
|
61
|
-
const
|
|
113
|
+
const execAsync = promisify(exec);
|
|
114
|
+
await execAsync( "frontfire init", { cwd: appPath } );
|
|
115
|
+
|
|
116
|
+
//await writeFile( `${appPath}/frontfire.json`, JSON.stringify(initConfig, null, 2) + "\n", "utf8");
|
|
117
|
+
|
|
118
|
+
console.log(chalk.green.bold(`\nInfrontJS project "${appName}" successfully created at ${appPath}\n`));
|
|
119
|
+
|
|
120
|
+
console.log(chalk.cyan.bold("Next steps:"));
|
|
121
|
+
console.log(` ${chalk.yellow("1.")} Change directory to ${chalk.magenta(path.resolve(appPath))}`);
|
|
122
|
+
console.log(` ${chalk.yellow("2.")} Modify ${chalk.magenta(path.join(appPath, "frontfire.config"))} and ${chalk.magenta(path.join(appPath, "package.json"))} to your needs`);
|
|
123
|
+
console.log(` ${chalk.yellow("3.")} Run ${chalk.blueBright("npm install")}`);
|
|
124
|
+
console.log(` ${chalk.yellow("4.")} Run ${chalk.blueBright("frontfire start-dev")} to start development`);
|
|
125
|
+
console.log(` ${chalk.yellow("5.")} Alternatively run ${chalk.blueBright("frontfire build")} to build your minified project before deployment\n`);
|
|
62
126
|
|
|
63
|
-
if ( true === fs.existsSync( srcFolder ) )
|
|
64
|
-
{
|
|
65
|
-
console.warn( `Sourcefolder ${srcFolder} already exists!` );
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
127
|
}
|
|
69
128
|
|
|
70
129
|
async function generatesPathObject( name )
|
|
@@ -125,7 +184,7 @@ async function generatesState( name, options )
|
|
|
125
184
|
|
|
126
185
|
console.log( chalk.green.bold( `State ${stateName} successfully generated.`) );
|
|
127
186
|
console.log( chalk.italic( 'Dont forget to add the state to your states instance, e.g.' ) );
|
|
128
|
-
console.log( chalk.italic.bgWhite( `myApp.states.add( ${stateName}
|
|
187
|
+
console.log( chalk.italic.bgWhite( `myApp.states.add( ${stateName}State);`) );
|
|
129
188
|
}
|
|
130
189
|
|
|
131
190
|
async function generatesWebComponent( name = null )
|
|
@@ -134,15 +193,9 @@ async function generatesWebComponent( name = null )
|
|
|
134
193
|
let className = null;
|
|
135
194
|
let wcName = null;
|
|
136
195
|
|
|
137
|
-
// Deep Copy
|
|
138
|
-
const initConfig = JSON.parse( JSON.stringify( defaultConfig ) );
|
|
139
|
-
|
|
140
|
-
_.unset( initConfig, 'debug.esbuild.plugins' );
|
|
141
|
-
_.unset( initConfig, 'release.esbuild.plugins' );
|
|
142
|
-
|
|
143
196
|
if ( null === name || name.length === 0 )
|
|
144
197
|
{
|
|
145
|
-
console.error( '
|
|
198
|
+
console.error( 'Empty web component name.')
|
|
146
199
|
}
|
|
147
200
|
|
|
148
201
|
fileName = name.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
|
|
@@ -303,9 +356,38 @@ program
|
|
|
303
356
|
.action( function() { performInit(); } );
|
|
304
357
|
|
|
305
358
|
program
|
|
306
|
-
.command(
|
|
307
|
-
.description(
|
|
308
|
-
.
|
|
359
|
+
.command("create")
|
|
360
|
+
.description("Create a new InfrontJS project")
|
|
361
|
+
.argument("[appName]", "Application name", "InfrontJS Starter")
|
|
362
|
+
.argument("[appPath]", "Target directory")
|
|
363
|
+
.action(async ( appName, appPath) => {
|
|
364
|
+
const finalName = appName ?? "InfrontJS Starter";
|
|
365
|
+
if ( !appPath )
|
|
366
|
+
{
|
|
367
|
+
appPath = process.cwd();
|
|
368
|
+
appPath = path.join( appPath, slugify( finalName, { lower: true , strict: true } ) );
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const resolvedPath = path.resolve(appPath ?? process.cwd());
|
|
372
|
+
|
|
373
|
+
console.log(chalk.cyan(`\nAbout to create:`));
|
|
374
|
+
console.log(` ${chalk.bold("Name:")} ${finalName}`);
|
|
375
|
+
console.log(` ${chalk.bold("Path:")} ${resolvedPath}\n`);
|
|
376
|
+
|
|
377
|
+
const confirmed = await askYesNo(
|
|
378
|
+
chalk.yellow("Do you really want to create the project in this directory? (y/N) ")
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
if (!confirmed) {
|
|
382
|
+
console.log(chalk.red("Aborted."));
|
|
383
|
+
process.exitCode = 1;
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
console.log(chalk.green("Starting..."));
|
|
388
|
+
await createInfrontJsStarter( finalName, resolvedPath );
|
|
389
|
+
console.log(chalk.green("Done."));
|
|
390
|
+
});
|
|
309
391
|
|
|
310
392
|
program
|
|
311
393
|
.command( 'gwc' )
|
|
@@ -340,5 +422,10 @@ program
|
|
|
340
422
|
.description( 'Building for production.' )
|
|
341
423
|
.action( function() { frontFire( false, customConfig ); } );
|
|
342
424
|
|
|
425
|
+
program
|
|
426
|
+
.command( 'version' )
|
|
427
|
+
.description( 'Prints the version number.' )
|
|
428
|
+
.action( function() { console.log( pkg.version ); } );
|
|
429
|
+
|
|
343
430
|
|
|
344
431
|
program.parse();
|