frontfire 0.7.0 → 0.8.0

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 CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "frontfire",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
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/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( /IFJSCACHEBREAK/g, (DateTime.now()).valueOf() );
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,19 @@
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";
7
9
 
8
10
  import _ from "lodash";
9
11
  import prettier from "prettier";
10
12
  import { program } from "commander";
11
13
  import path from "node:path";
14
+ import { createInterface } from "readline";
15
+ import { stdin as input, stdout as output } from "node:process";
16
+ import slugify from "slugify";
12
17
 
13
18
  import frontFire from "./FrontFire.js";
14
19
  import defaultConfig from "./DefaultConfig.js";
@@ -20,6 +25,15 @@ import stateTemplate from "./templates/state-template.html.js";
20
25
  import poIndex from "./templates/po-index.js";
21
26
  import dictTemplate from "./templates/dictionary.js";
22
27
 
28
+ async function askYesNo(question) {
29
+ const rl = createInterface({ input, output });
30
+ const answer = await new Promise((resolve) => {
31
+ rl.question(question, (ans) => resolve(ans.trim()));
32
+ });
33
+ rl.close();
34
+ return /^(y|yes)$/i.test(answer);
35
+ }
36
+
23
37
  async function performInit()
24
38
  {
25
39
  // Deep Copy
@@ -45,26 +59,64 @@ async function performInit()
45
59
  }
46
60
  }
47
61
 
48
- async function createInfrontJsStarter( appName = null )
62
+ async function createInfrontJsStarter( appName, appPath )
49
63
  {
50
- // Deep Copy
64
+ // Callback → Promise
65
+ const downloadAsync = promisify(download);
66
+
67
+ async function downloadRepo(repo, targetDir) {
68
+ try {
69
+ await downloadAsync(repo, targetDir, { clone: false });
70
+ console.log(`✅ Repo erfolgreich geladen nach ${targetDir}`);
71
+ } catch (err) {
72
+ console.error("❌ Fehler beim Laden des Repos:", err);
73
+ }
74
+ }
75
+
76
+ async function updatePackageName(newName, packagePath = "./package.json") {
77
+ try {
78
+ const fullPath = path.resolve(packagePath);
79
+
80
+ // read package.json
81
+ const data = await readFile(fullPath, "utf-8");
82
+ const pkg = JSON.parse(data);
83
+
84
+ // replace if it matches the source name
85
+ if (pkg.name === "infrontjs-starter") {
86
+ pkg.name = newName;
87
+
88
+ await writeFile(fullPath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
89
+ console.log(`✅ Updated package.json name to "${newName}"`);
90
+ } else {
91
+ console.log(`ℹ️ package.json name is not "infrontjs-starter" (found "${pkg.name}"), no change made.`);
92
+ }
93
+ } catch (err) {
94
+ console.error("❌ Failed to update package.json:", err);
95
+ }
96
+ }
97
+
98
+
99
+ // Deep Copy
51
100
  const initConfig = JSON.parse( JSON.stringify( defaultConfig ) );
52
101
 
53
102
  _.unset( initConfig, 'debug.esbuild.plugins' );
54
103
  _.unset( initConfig, 'release.esbuild.plugins' );
55
104
 
56
- if ( null === appName || appName.length === 0 )
57
- {
58
- appName = 'InfrontJS Starter';
59
- }
105
+ await downloadRepo("github:infrontjs/starter", appPath );
106
+ await updatePackageName( appName, `${appPath}/package.json` );
107
+ await unlink( `${appPath}/LICENSE` );
60
108
 
61
- const srcFolder = path.resolve( '.' ) + path.separator + 'src-to-test';
109
+ await writeFile( `${appPath}/frontfire.json`, JSON.stringify(initConfig, null, 2) + "\n", "utf8");
110
+
111
+ console.log(chalk.green.bold(`\nInfrontJS project "${appName}" successfully created at ${appPath}\n`));
112
+
113
+ console.log(chalk.cyan.bold("Next steps:"));
114
+ console.log(` ${chalk.yellow("1.")} Change directory to ${chalk.magenta(path.resolve(appPath))}`);
115
+ console.log(` ${chalk.yellow("2.")} Modify ${chalk.magenta(path.join(appPath, "frontfire.config"))} and ${chalk.magenta(path.join(appPath, "package.json"))} to your needs`);
116
+ console.log(` ${chalk.yellow("3.")} Run ${chalk.blueBright("npm install")}`);
117
+ console.log(` ${chalk.yellow("4.")} Run ${chalk.blueBright("frontfire start-dev")} to start development`);
118
+ console.log(` ${chalk.yellow("5.")} Alternatively run ${chalk.blueBright("frontfire build")} to build your minified project before deployment\n`);
62
119
 
63
- if ( true === fs.existsSync( srcFolder ) )
64
- {
65
- console.warn( `Sourcefolder ${srcFolder} already exists!` );
66
- return;
67
- }
68
120
  }
69
121
 
70
122
  async function generatesPathObject( name )
@@ -125,7 +177,7 @@ async function generatesState( name, options )
125
177
 
126
178
  console.log( chalk.green.bold( `State ${stateName} successfully generated.`) );
127
179
  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} );`) );
180
+ console.log( chalk.italic.bgWhite( `myApp.states.add( ${stateName}State);`) );
129
181
  }
130
182
 
131
183
  async function generatesWebComponent( name = null )
@@ -303,9 +355,38 @@ program
303
355
  .action( function() { performInit(); } );
304
356
 
305
357
  program
306
- .command( 'create' )
307
- .description( 'Creates starter InfrontJS application.' )
308
- .action( function() { createInfrontJsStarter(); } );
358
+ .command("create")
359
+ .description("Create a new InfrontJS project")
360
+ .argument("[appName]", "Application name", "InfrontJS Starter")
361
+ .argument("[appPath]", "Target directory")
362
+ .action(async ( appName, appPath) => {
363
+ const finalName = appName ?? "InfrontJS Starter";
364
+ if ( !appPath )
365
+ {
366
+ appPath = processY.cwd();
367
+ appPath = path.join( appPath, slugify( finalName, { lower: true , strict: true } ) );
368
+ }
369
+
370
+ const resolvedPath = path.resolve(appPath ?? process.cwd());
371
+
372
+ console.log(chalk.cyan(`\nAbout to create:`));
373
+ console.log(` ${chalk.bold("Name:")} ${finalName}`);
374
+ console.log(` ${chalk.bold("Path:")} ${resolvedPath}\n`);
375
+
376
+ const confirmed = await askYesNo(
377
+ chalk.yellow("Do you really want to create the project in this directory? (y/N) ")
378
+ );
379
+
380
+ if (!confirmed) {
381
+ console.log(chalk.red("Aborted."));
382
+ process.exitCode = 1;
383
+ return;
384
+ }
385
+
386
+ console.log(chalk.green("Starting..."));
387
+ await createInfrontJsStarter( finalName, resolvedPath );
388
+ console.log(chalk.green("Done."));
389
+ });
309
390
 
310
391
  program
311
392
  .command( 'gwc' )
@@ -340,5 +421,10 @@ program
340
421
  .description( 'Building for production.' )
341
422
  .action( function() { frontFire( false, customConfig ); } );
342
423
 
424
+ program
425
+ .command( 'version' )
426
+ .description( 'Prints the version number.' )
427
+ .action( function() { console.log( '0.8.0' ); } );
428
+
343
429
 
344
430
  program.parse();