nexfep 0.4.4 → 0.5.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/cli/build.mjs CHANGED
@@ -1,111 +1,120 @@
1
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';
2
+ import child_process from "child_process";
3
+ import fs from "fs";
4
+ import path from "path";
5
+ import TimeTyper from "./timeTyper.mjs";
6
6
 
7
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;
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
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
- }
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;
50
37
  }
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
- }
38
+ if (arg === "--reinstall" || arg === "-r") {
39
+ reinstall = true;
57
40
  }
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");
41
+ if (arg === "--skip-clean" || arg === "-s") {
42
+ skipClean = true;
66
43
  }
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");
44
+ if (arg === "--upx" || arg === "-u") {
45
+ NexfpackConfig.upxLevel = Number(args[args.indexOf(arg) + 1]);
81
46
  }
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
- });
47
+ if (arg === "--meta" || arg === "--metadata" || arg === "-m") {
48
+ NexfpackConfig.metadata = JSON.parse(fs.readFileSync(args[args.indexOf(arg) + 1]));
88
49
  }
89
- await new Promise(resolve => {
90
- fs.writeFile(path.join(NexfpackConfig.output, 'nexfpack.config.json'), JSON.stringify(NexfpackConfig, null, 2), resolve);
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(
56
+ " Will skip UPX compression. You can install UPX from https://github.com/upx/upx/releases/latest and add it to the PATH environment variable.",
57
+ );
58
+ }
59
+ }
60
+ if (!skipClean) {
61
+ console.log("Removing Old Build Files...");
62
+ const typerForRemove = new TimeTyper("Removing Old Build Files...");
63
+ await new Promise((resolve) => {
64
+ fs.rm(NexfpackConfig.output, { recursive: true, force: true }, resolve);
91
65
  });
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
- });
66
+ await typerForRemove.kill();
67
+ console.log("\x1b[1A\x1b[2KRemoved Old Build Files");
68
+ }
69
+ if (reinstall) {
70
+ console.log("Reinstalling Dependencies...");
71
+ const typerForReinstall = new TimeTyper("Reinstalling Dependencies...");
72
+ await new Promise((resolve) => {
73
+ fs.rm("node_modules", { recursive: true, force: true }, resolve);
101
74
  });
102
- await new Promise(resolve => {
103
- fs.unlink(path.join(NexfpackConfig.output, 'nexfpack.config.json'), resolve);
75
+ await new Promise((resolve) => {
76
+ const child = child_process.spawn("npm install --omit=dev", { shell: true });
77
+ child.on("close", (code) => {
78
+ resolve({ status: code });
79
+ });
104
80
  });
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
- }
81
+ await typerForReinstall.kill();
82
+ console.log("\x1b[1A\x1b[2KReinstalled Dependencies");
83
+ }
84
+ console.log("Setting Up Build Environment...");
85
+ const typerForSetup = new TimeTyper("Setting Up Build Environment...");
86
+ if (!fs.existsSync(NexfpackConfig.output)) {
87
+ await new Promise((resolve) => {
88
+ fs.mkdir(NexfpackConfig.output, { recursive: true }, resolve);
89
+ });
90
+ }
91
+ await new Promise((resolve) => {
92
+ fs.writeFile(
93
+ path.join(NexfpackConfig.output, "nexfpack.config.json"),
94
+ JSON.stringify(NexfpackConfig, null, 2),
95
+ resolve,
96
+ );
97
+ });
98
+ await typerForSetup.kill();
99
+ console.log("\x1b[1A\x1b[2KSet Up Build Environment");
100
+ console.log("Building...");
101
+ const typerForBuild = new TimeTyper("Building...");
102
+ const result = await new Promise((resolve) => {
103
+ const child = child_process.spawn(
104
+ `npx --yes nexfpack@0.4.2 ${path.join(NexfpackConfig.output, "nexfpack.config.json")}`,
105
+ { shell: true },
106
+ );
107
+ child.on("close", (code) => {
108
+ resolve({ status: code });
109
+ });
110
+ });
111
+ await new Promise((resolve) => {
112
+ fs.unlink(path.join(NexfpackConfig.output, "nexfpack.config.json"), resolve);
113
+ });
114
+ await typerForBuild.kill();
115
+ if (result.status !== 0) {
116
+ console.error("\x1b[1A\x1b[2KBuild Failed: Exit Code: " + result.status);
117
+ process.exit(result.status);
118
+ }
119
+ console.log("\x1b[1A\x1b[2KBuild Success");
120
+ }
package/cli/help.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const helpTexts = {
2
- help: `
2
+ help: `
3
3
  Nexfep - A desktop application framework for Node.js
4
4
 
5
5
  This is a command-line tool for building desktop applications with Node.js.
@@ -16,7 +16,7 @@ Commands:
16
16
  See 'nexfep help <command>'
17
17
  to read about a specific subcommand.
18
18
  `,
19
- build: `
19
+ build: `
20
20
  nexfep build - Build the application into a standalone executable
21
21
 
22
22
  Usage:
@@ -47,11 +47,11 @@ This command uses nexfpack (github.com/nexfteam/Nexfpack) to package
47
47
  your application into a standalone executable. For more details, see:
48
48
  https://github.com/nexfteam/Nexfpack
49
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
+ }
50
57
  }
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
- }
package/cli/index.mjs CHANGED
@@ -1,20 +1,18 @@
1
1
  #!/usr/bin/env node
2
- import fs from 'fs';
3
- import path from 'path';
4
- import build from './build.mjs';
5
- import help from './help.mjs';
2
+ import build from "./build.mjs";
3
+ import help from "./help.mjs";
6
4
  const args = process.argv.slice(2);
7
- if(args.length === 0) {
5
+ if (args.length === 0) {
6
+ help();
7
+ process.exit(1);
8
+ }
9
+ if (args[0] === "help") {
10
+ if (args.length > 1) {
11
+ help(args[1]);
12
+ } else {
8
13
  help();
9
- process.exit(1);
14
+ }
10
15
  }
11
- if(args[0] === 'help') {
12
- if(args.length > 1) {
13
- help(args[1]);
14
- } else {
15
- help();
16
- }
16
+ if (args[0] === "build") {
17
+ build(args.slice(1));
17
18
  }
18
- if(args[0] === 'build') {
19
- build(args.slice(1));
20
- }
package/cli/timeTyper.mjs CHANGED
@@ -1,32 +1,32 @@
1
1
  export default class TimeTyper {
2
- typerKilled;
3
- msg;
4
- constructor(msg) {
5
- this.typerKilled = false;
6
- this.msg = msg;
7
- this.typeTime(0);
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;
8
13
  }
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);
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);
18
26
  }
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
- }
27
+ }
28
+ async kill() {
29
+ this.typerKilled = true;
30
+ await new Promise(this.waitForReset.bind(this));
31
+ }
32
+ }
package/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './src/Application.js';
1
+ export * from "./src/Application.js";
package/index.js CHANGED
@@ -1 +1 @@
1
- export * from './src/Application.js';
1
+ export * from "./src/Application.js";
package/package.json CHANGED
@@ -1,32 +1,24 @@
1
1
  {
2
2
  "name": "nexfep",
3
+ "version": "0.5.0",
3
4
  "description": "A desktop application framework based on @webviewjs/webview",
4
- "repository": "https://github.com/nexfteam/Nexfep",
5
- "homepage": "https://github.com/nexfteam/Nexfep#readme",
6
- "bugs": {
7
- "url": "https://github.com/nexfteam/Nexfep/issues"
8
- },
9
- "bin": {
10
- "nexfep": "cli/index.mjs"
11
- },
12
5
  "keywords": [
13
- "desktop",
6
+ "@webviewjs/webview",
14
7
  "application",
8
+ "desktop",
15
9
  "framework",
16
- "@webviewjs/webview",
17
- "webview",
18
- "typescript"
10
+ "typescript",
11
+ "webview"
19
12
  ],
20
- "version": "0.4.4",
21
- "type": "module",
22
- "main": "./index.js",
23
- "scripts": {
24
- "compile": "tsc"
13
+ "homepage": "https://github.com/nexfteam/Nexfep#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/nexfteam/Nexfep/issues"
25
16
  },
26
- "author": "nexfteam",
27
17
  "license": "MIT",
28
- "engines": {
29
- "node": ">=20.11.0"
18
+ "author": "nexfteam",
19
+ "repository": "https://github.com/nexfteam/Nexfep",
20
+ "bin": {
21
+ "nexfep": "cli/index.mjs"
30
22
  },
31
23
  "files": [
32
24
  "index.js",
@@ -46,14 +38,31 @@
46
38
  "src/Tray.js",
47
39
  "src/Tray.d.ts",
48
40
  "src/Logger.js",
49
- "src/Logger.d.ts"
41
+ "src/Logger.d.ts",
42
+ "src/SingleInstance.js",
43
+ "src/SingleInstance.d.ts"
50
44
  ],
45
+ "type": "module",
46
+ "main": "./index.js",
47
+ "scripts": {
48
+ "compile": "tsc",
49
+ "fmt": "oxfmt --check",
50
+ "lint": "oxlint",
51
+ "fmt:fix": "oxfmt",
52
+ "lint:fix": "oxlint --fix"
53
+ },
51
54
  "dependencies": {
55
+ "@nexfteam/single-instance": "^0.0.7",
52
56
  "@webviewjs/webview": "0.4.0"
53
57
  },
54
58
  "devDependencies": {
55
59
  "@types/node": "^22.0.0",
60
+ "oxfmt": "^0.60.0",
61
+ "oxlint": "^1.75.0",
56
62
  "tsx": "^4.0.0",
57
63
  "typescript": "^5.0.0"
64
+ },
65
+ "engines": {
66
+ "node": ">=20.11.0"
58
67
  }
59
- }
68
+ }
@@ -1,7 +1,8 @@
1
- import { Application as WebviewApplication, TrayIconImage, Notification } from '@webviewjs/webview';
2
- import { WindowPool } from './WindowManager.js';
3
- import { Tray } from './Tray.js';
4
- import { Logger } from './Logger.js';
1
+ import { Application as WebviewApplication, TrayIconImage, Notification } from "@webviewjs/webview";
2
+ import { WindowPool } from "./WindowManager.js";
3
+ import { Tray } from "./Tray.js";
4
+ import { Logger } from "./Logger.js";
5
+ import { Locker } from "./SingleInstance.js";
5
6
  declare class __Utils {
6
7
  app: WebviewApplication;
7
8
  constructor(app: WebviewApplication);
@@ -25,6 +26,7 @@ declare class Application {
25
26
  label: string;
26
27
  }>;
27
28
  }): Tray;
29
+ createLocker(appName: string): Locker;
28
30
  exit(): void;
29
31
  }
30
32
  export { Application };
@@ -1,7 +1,8 @@
1
- import { Application as WebviewApplication, Notification } from '@webviewjs/webview';
2
- import { WindowPool } from './WindowManager.js';
3
- import { Tray } from './Tray.js';
4
- import { Logger } from './Logger.js';
1
+ import { Application as WebviewApplication, Notification } from "@webviewjs/webview";
2
+ import { WindowPool } from "./WindowManager.js";
3
+ import { Tray } from "./Tray.js";
4
+ import { Logger } from "./Logger.js";
5
+ import { Locker } from "./SingleInstance.js";
5
6
  class __Utils {
6
7
  app;
7
8
  constructor(app) {
@@ -21,13 +22,19 @@ class Application {
21
22
  this.app = new WebviewApplication();
22
23
  this.utils = new __Utils(this.app);
23
24
  this.logger = new Logger(options.LogFilePath);
24
- const poolOptions = { WindowsWebview2UserDataFolder: options.WindowsWebview2UserDataFolder, logger: this.logger };
25
+ const poolOptions = {
26
+ WindowsWebview2UserDataFolder: options.WindowsWebview2UserDataFolder,
27
+ logger: this.logger,
28
+ };
25
29
  this.windows = new WindowPool(this.app, poolOptions);
26
30
  this.app.whenReady();
27
31
  }
28
32
  createTray(options) {
29
33
  return new Tray(this.app, options);
30
34
  }
35
+ createLocker(appName) {
36
+ return new Locker(appName);
37
+ }
31
38
  exit() {
32
39
  this.app.exit();
33
40
  }