nexfep 0.4.2 → 0.4.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/cli/build.mjs ADDED
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env node
2
+ import child_process from 'child_process';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import TimeTyper from './timeTyper.mjs';
6
+
7
+ export default async function build(args) {
8
+ const packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf8'));
9
+ const NexfpackConfig = {
10
+ name: packageJson.name,
11
+ metadata: undefined,
12
+ entry: packageJson.main,
13
+ output: 'dist',
14
+ noConsole: true,
15
+ log: false,
16
+ upxLevel: 0,
17
+ ignore: [],
18
+ }
19
+ let reinstall = false;
20
+ let skipClean = false;
21
+
22
+ for (const arg of args) {
23
+ if (arg === ('--name') || arg === '-n') {
24
+ NexfpackConfig.name = args[args.indexOf(arg) + 1];
25
+ }
26
+ if (arg === ('--entry') || arg === '-e') {
27
+ NexfpackConfig.entry = args[args.indexOf(arg) + 1];
28
+ }
29
+ if (arg === ('--output') || arg === '-o') {
30
+ NexfpackConfig.output = args[args.indexOf(arg) + 1];
31
+ }
32
+ if (arg === ('--ignore') || arg === '-i') {
33
+ NexfpackConfig.ignore.push(args[args.indexOf(arg) + 1]);
34
+ }
35
+ if (arg === ('--console') || arg === '-c') {
36
+ NexfpackConfig.noConsole = false;
37
+ }
38
+ if (arg === ('--reinstall') || arg === '-r') {
39
+ reinstall = true;
40
+ }
41
+ if (arg === ('--skip-clean') || arg === '-s') {
42
+ skipClean = true;
43
+ }
44
+ if (arg === ('--upx') || arg === '-u') {
45
+ NexfpackConfig.upxLevel = Number(args[args.indexOf(arg) + 1]);
46
+ }
47
+ if (arg === ('--meta') || arg === ('--metadata') || arg === '-m') {
48
+ NexfpackConfig.metadata = JSON.parse(fs.readFileSync(args[args.indexOf(arg) + 1]));
49
+ }
50
+ }
51
+ if (NexfpackConfig.upxLevel > 0) {
52
+ const upxCheckResult = child_process.spawnSync("upx --version", { shell: true });
53
+ if (upxCheckResult.status !== 0) {
54
+ console.log("⚠️ UPX is not installed or is not in the PATH.");
55
+ console.log(" Will skip UPX compression. You can install UPX from https://github.com/upx/upx/releases/latest and add it to the PATH environment variable.");
56
+ }
57
+ }
58
+ if (!skipClean) {
59
+ console.log("Removing Old Build Files...");
60
+ const typerForRemove = new TimeTyper("Removing Old Build Files...");
61
+ await new Promise(resolve => {
62
+ fs.rm(NexfpackConfig.output, { recursive: true, force: true }, resolve);
63
+ });
64
+ await typerForRemove.kill();
65
+ console.log("\x1b[1A\x1b[2KRemoved Old Build Files");
66
+ }
67
+ if (reinstall) {
68
+ console.log("Reinstalling Dependencies...");
69
+ const typerForReinstall = new TimeTyper("Reinstalling Dependencies...");
70
+ await new Promise(resolve => {
71
+ fs.rm("node_modules", { recursive: true, force: true }, resolve);
72
+ });
73
+ await new Promise(resolve => {
74
+ const child = child_process.spawn("npm install --omit=dev", { shell: true });
75
+ child.on('close', (code) => {
76
+ resolve({ status: code });
77
+ });
78
+ });
79
+ await typerForReinstall.kill();
80
+ console.log("\x1b[1A\x1b[2KReinstalled Dependencies");
81
+ }
82
+ console.log("Setting Up Build Environment...");
83
+ const typerForSetup = new TimeTyper("Setting Up Build Environment...");
84
+ if (!fs.existsSync(NexfpackConfig.output)) {
85
+ await new Promise(resolve => {
86
+ fs.mkdir(NexfpackConfig.output, { recursive: true }, resolve);
87
+ });
88
+ }
89
+ await new Promise(resolve => {
90
+ fs.writeFile(path.join(NexfpackConfig.output, 'nexfpack.config.json'), JSON.stringify(NexfpackConfig, null, 2), resolve);
91
+ });
92
+ await typerForSetup.kill();
93
+ console.log("\x1b[1A\x1b[2KSet Up Build Environment");
94
+ console.log("Building...");
95
+ const typerForBuild = new TimeTyper("Building...");
96
+ const result = await new Promise(resolve => {
97
+ const child = child_process.spawn(`npx --yes nexfpack@0.4.2 ${path.join(NexfpackConfig.output, 'nexfpack.config.json')}`, { shell: true });
98
+ child.on('close', (code) => {
99
+ resolve({ status: code });
100
+ });
101
+ });
102
+ await new Promise(resolve => {
103
+ fs.unlink(path.join(NexfpackConfig.output, 'nexfpack.config.json'), resolve);
104
+ });
105
+ await typerForBuild.kill();
106
+ if (result.status !== 0) {
107
+ console.error("\x1b[1A\x1b[2KBuild Failed: Exit Code: " + result.status);
108
+ process.exit(result.status);
109
+ }
110
+ console.log("\x1b[1A\x1b[2KBuild Success");
111
+ }
package/cli/help.mjs ADDED
@@ -0,0 +1,57 @@
1
+ const helpTexts = {
2
+ help: `
3
+ Nexfep - A desktop application framework for Node.js
4
+
5
+ This is a command-line tool for building desktop applications with Node.js.
6
+
7
+ For application development, please refer to the README.md:
8
+ https://github.com/nexfteam/Nexfep#readme
9
+
10
+ Usage: nexfep <command> [options]
11
+
12
+ Commands:
13
+ help Show this help message
14
+ build Build the application into a standalone executable
15
+
16
+ See 'nexfep help <command>'
17
+ to read about a specific subcommand.
18
+ `,
19
+ build: `
20
+ nexfep build - Build the application into a standalone executable
21
+
22
+ Usage:
23
+ nexfep build [options]
24
+
25
+ Options:
26
+ -n, --name <name> Application name (default: from package.json)
27
+ -e, --entry <file> Entry file path (default: from package.json main)
28
+ -o, --output <dir> Output directory (default: dist)
29
+ -i, --ignore <pattern> Files or directories to ignore (can be used multiple times)
30
+ -c, --console Show console window on Windows (default: false)
31
+ -r, --reinstall Reinstall production dependencies only before building (default: false)
32
+ -s, --skip-clean Skip cleaning old build files before building (default: false)
33
+ -u, --upx <level> Use UPX to compress the executable, level in range 0-9, 0 means no UPX compression.
34
+ Ensure UPX is installed before using (default: 0)
35
+ -m, --meta, --metadata <file> Metadata JSON file path.
36
+ For more details, see README.md and https://github.com/nexfteam/Nexfpack#Metadata.
37
+
38
+ Examples:
39
+ nexfep build # Build using defaults from package.json
40
+ nexfep build -n my-app # Set custom application name
41
+ nexfep build -e ./src/index.js # Set custom entry file
42
+ nexfep build -o ./build # Set custom output directory
43
+ nexfep build -i node_modules # Ignore node_modules
44
+ nexfep build -i test -i temp # Ignore multiple patterns
45
+
46
+ This command uses nexfpack (github.com/nexfteam/Nexfpack) to package
47
+ your application into a standalone executable. For more details, see:
48
+ https://github.com/nexfteam/Nexfpack
49
+ `,
50
+ }
51
+ export default function help(command = 'help') {
52
+ if(command in helpTexts) {
53
+ console.log(helpTexts[command]);
54
+ } else {
55
+ console.log("Invalid command.");
56
+ }
57
+ }
@@ -0,0 +1,32 @@
1
+ export default class TimeTyper {
2
+ typerKilled;
3
+ msg;
4
+ constructor(msg) {
5
+ this.typerKilled = false;
6
+ this.msg = msg;
7
+ this.typeTime(0);
8
+ }
9
+ typeTime(seconds) {
10
+ if (this.typerKilled) {
11
+ this.typerKilled = false;
12
+ return;
13
+ }
14
+ console.log(`\x1b[1A\x1b[2K(${seconds}s) ${this.msg}`);
15
+ setTimeout(() => {
16
+ this.typeTime(seconds + 1);
17
+ }, 1000);
18
+ }
19
+ async waitForReset(resolve) {
20
+ if (!this.typerKilled) {
21
+ resolve();
22
+ } else {
23
+ setTimeout(() => {
24
+ this.waitForReset(resolve);
25
+ }, 10);
26
+ }
27
+ }
28
+ async kill() {
29
+ this.typerKilled = true;
30
+ await new Promise(this.waitForReset.bind(this));
31
+ }
32
+ }
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "webview",
18
18
  "typescript"
19
19
  ],
20
- "version": "0.4.2",
20
+ "version": "0.4.4",
21
21
  "type": "module",
22
22
  "main": "./index.js",
23
23
  "scripts": {
@@ -35,6 +35,10 @@
35
35
  "README-CN.md",
36
36
  "LICENSE",
37
37
  "package.json",
38
+ "cli/index.mjs",
39
+ "cli/help.mjs",
40
+ "cli/build.mjs",
41
+ "cli/timeTyper.mjs",
38
42
  "src/WindowManager.js",
39
43
  "src/WindowManager.d.ts",
40
44
  "src/Application.js",
@@ -12,7 +12,7 @@ declare class Application {
12
12
  windows: WindowPool;
13
13
  logger: Logger;
14
14
  utils: __Utils;
15
- constructor(options: {
15
+ constructor(options?: {
16
16
  WindowsWebview2UserDataFolder?: string;
17
17
  LogFilePath?: string;
18
18
  });
@@ -17,7 +17,7 @@ class Application {
17
17
  windows;
18
18
  logger;
19
19
  utils;
20
- constructor(options) {
20
+ constructor(options = {}) {
21
21
  this.app = new WebviewApplication();
22
22
  this.utils = new __Utils(this.app);
23
23
  this.logger = new Logger(options.LogFilePath);