From 4d83eb24a8702820f39a59dab566560f62af1c7f Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 28 Dec 2022 09:25:47 +0530 Subject: [PATCH 1/3] Adds typescript support and esbuild --- .gitignore | 3 +- build.js | 15 + package-lock.json | 758 ++++++++++++++++++++++++++++++++++++- package.json | 11 +- src/{index.js => index.ts} | 12 +- tsconfig.json | 104 +++++ 6 files changed, 887 insertions(+), 16 deletions(-) create mode 100644 build.js rename src/{index.js => index.ts} (91%) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 40b878d..04c01ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules/ \ No newline at end of file +node_modules/ +dist/ \ No newline at end of file diff --git a/build.js b/build.js new file mode 100644 index 0000000..e0430a4 --- /dev/null +++ b/build.js @@ -0,0 +1,15 @@ +const esbuild = require('esbuild') + +// Automatically exclude all node_modules from the bundled version +const { nodeExternalsPlugin } = require('esbuild-node-externals') + +esbuild.build({ + entryPoints: ['./src/index.ts'], + outdir: 'dist', + bundle: true, + minify: false, // TODO: Make this change based on environment variable + platform: 'node', + sourcemap: true, + target: 'node14', + plugins: [nodeExternalsPlugin()] +}).catch(() => process.exit(1)) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 95ac4a1..13fc8ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,16 +7,358 @@ "": { "name": "neutralinojs-builder", "version": "1.0.0", - "license": "ISC", + "license": "MIT", "dependencies": { "chalk": "^4.1.0", "cli-spinner": "^0.2.10", "decompress": "^4.2.1", + "esbuild": "^0.16.11", + "esbuild-node-externals": "^1.6.0", + "fs-extra": "^11.1.0", "inquirer": "^8.2.4", "node-downloader-helper": "^2.1.1", "ora": "^5.4.1" + }, + "devDependencies": { + "@types/node": "^18.11.18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.16.11.tgz", + "integrity": "sha512-j2xsG1OETgCe+OBA54DG5vLuGjmMZtQvyxt+rTw2aYK/RqjcG/F+UDdj43uoUOv8lSRC3lM4XpKLOVZfY/82yA==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.16.11.tgz", + "integrity": "sha512-CPwhZd15PasQSlkFuZv1st37xvuBeklztfb9y2GZWLQu59zcMIDkZVSEz/TTIxzt811+eJfblg5HhP49iVVDWQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.16.11.tgz", + "integrity": "sha512-vbFn+0JXX6FkKq+0sNeA6aF2QhuOt9ZkBl+DSyqKIF+Ms58lUOhbqSwberKWQDm0udgOp3d/LhOFTYmpvmlZmA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.16.11.tgz", + "integrity": "sha512-1tqsIG6AySZ9njT8V2ddH1F/J01zX+0obPCpP0uD9TMIUlAA5WUF/+abFlnIsNY4jACcbN/13NUbLRWE9bayjw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.16.11.tgz", + "integrity": "sha512-Gqx2/nYqnK46dwEDPGv3SwLqgLIZQJ7m2xNoNRzO50VZPvoCWSUqDaoirrZZf7uVfl+fxHoZBcdQJx2gOdxffQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.16.11.tgz", + "integrity": "sha512-58FTdlgIQ3ZxFtGphjbIBmo7kfDhQih/PlfAnKraAcCDZOYXWcRFmHJtW+EVg32IIxuEAqhLAzCgrqpm5o8Wlw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.16.11.tgz", + "integrity": "sha512-L7hr6VnpqZzYEDVQeaViz1QnmfFRCRm3zVtljbYi/CU6InKs6tda1J3pAvqVsbNpbGMA9AvyiyBrgjJAFCawVg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.16.11.tgz", + "integrity": "sha512-Mk6TZij71alyS0FGuKEKYjTZGjUw2uXi07V/AiGZW1b5grTfGx6lpsbQdystgDJqju99Osq2Ix+C7WteSnwrHg==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.16.11.tgz", + "integrity": "sha512-OKU0ajh9Xu7Pd1MlSq8Xqj5SJEV+4yVnALydPTDrrmTyvU72P8mTRJgZMilHw7H+Jqc0utryjNOwlJ/+fOkwGw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.16.11.tgz", + "integrity": "sha512-pr1/tdDfgQQ9hp2IskSKMuwkx2X4jR7iHLbqEmmj/lPLKeoa6AUulnglGY4y0OPo+0eAYd6DzWp7ve3KI4lOCA==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.16.11.tgz", + "integrity": "sha512-2MCYdDBh9R+R1xuBFiApgkbp/tW1uV+aVeefKYqWSEk3o6MHzWo1FxEGA4dSnC+kThSBOMVpCV9z4/DPouA3bQ==", + "cpu": [ + "loong64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.16.11.tgz", + "integrity": "sha512-IyotdnRg0J8F9FKttYe3cy/M9ZJ5W/Gm6whH08sbXMxRVKs/TyyoqFIA8oT1MzR+si6GLlRpcF7JbUnOXssjPA==", + "cpu": [ + "mips64el" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.16.11.tgz", + "integrity": "sha512-NUMtxvb0j41UL8yf8VnTMNbCQxKqIPmF0Wf/N44UrxpKE8iCNmWT95Wt98Ivr2ebHdz+V3kptlgBuZNYcJLI6g==", + "cpu": [ + "ppc64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.16.11.tgz", + "integrity": "sha512-03/B26az/JezvVkgck+lhauP13t6RqzCQgnrkBCBrXXpX+2r02DfSU43BEhpErJrsrDA8GXSE/rvsfbGCX6OvA==", + "cpu": [ + "riscv64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.16.11.tgz", + "integrity": "sha512-Xs2tRB0fgly4XfC4FMv1Fd699AMEH8BClp36mzqRuVzm/285XIJaK5cPEZ9cLLn9ukNHdvvSX/83u5uS1BCd8g==", + "cpu": [ + "s390x" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.16.11.tgz", + "integrity": "sha512-CiNialxsjJllrG3ggzOKzSaqQK/De/Mv4g/3r7jxLt01GLerPh0Q3TVTndFG9VfOrR1PdN7Fz5AOV3bE6Isd1Q==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" } }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.16.11.tgz", + "integrity": "sha512-PiljZi6QZ3Pz0pL8rfJqPln8F/a3mEJwh2vhBb1kDYLniLufo9/7AInb/ZyhvgR7FxUQluUYyz64owPomgaLJA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.16.11.tgz", + "integrity": "sha512-Nyk8aJM+w6NoS4RGQJ0ybb516jEIbEVlLvhRIdpCssUuqKU0lr9lJPHnFY2QqyoVaJkd6VxaHOBU/v/ieuiENQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.16.11.tgz", + "integrity": "sha512-shxBLdNJecr7KxuyZQ19idBU8x7Mq7m+N5Fj8ROWMWQbDdjSjlBPxz7EZJIxSh7FUgSMKl7qSCCVaczXrta4MQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.16.11.tgz", + "integrity": "sha512-vyTbfoEBn7cGXK8writbsB+G2wyRoOA+EbTNQ9cu5lyLU65sfWetCaL8T7mX338AN8tTbCYl6ce5YRKTonpA3w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.16.11.tgz", + "integrity": "sha512-ATGCGc52LNqakUE9i54RzFC4lm70UTcTW721AFGjQotc6uCg7sf7QeRd05wD5tLBFafHdMSZv4rsU/Nh7LT/rQ==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.16.11.tgz", + "integrity": "sha512-7NcClJIctrO3iRu5CCqwdSBePm8bL2Iu1DYsuOnxuYJ+a1Kv3Wn3MzNdJIrUPLi1yADVwRliRUU/jtMC/tJnJA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@types/node": { + "version": "18.11.18", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", + "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==", + "dev": true + }, "node_modules/ansi-escapes": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", @@ -334,6 +676,57 @@ "once": "^1.4.0" } }, + "node_modules/esbuild": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.16.11.tgz", + "integrity": "sha512-Al0hhRUz/cCDvDp9VZp1L500HZZQ/HLjgTnQTmnW97+PoLmw+PuvB3e19JHYZtWnrxoh3qYrN/0tiRIbrE2oVQ==", + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/android-arm": "0.16.11", + "@esbuild/android-arm64": "0.16.11", + "@esbuild/android-x64": "0.16.11", + "@esbuild/darwin-arm64": "0.16.11", + "@esbuild/darwin-x64": "0.16.11", + "@esbuild/freebsd-arm64": "0.16.11", + "@esbuild/freebsd-x64": "0.16.11", + "@esbuild/linux-arm": "0.16.11", + "@esbuild/linux-arm64": "0.16.11", + "@esbuild/linux-ia32": "0.16.11", + "@esbuild/linux-loong64": "0.16.11", + "@esbuild/linux-mips64el": "0.16.11", + "@esbuild/linux-ppc64": "0.16.11", + "@esbuild/linux-riscv64": "0.16.11", + "@esbuild/linux-s390x": "0.16.11", + "@esbuild/linux-x64": "0.16.11", + "@esbuild/netbsd-x64": "0.16.11", + "@esbuild/openbsd-x64": "0.16.11", + "@esbuild/sunos-x64": "0.16.11", + "@esbuild/win32-arm64": "0.16.11", + "@esbuild/win32-ia32": "0.16.11", + "@esbuild/win32-x64": "0.16.11" + } + }, + "node_modules/esbuild-node-externals": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/esbuild-node-externals/-/esbuild-node-externals-1.6.0.tgz", + "integrity": "sha512-LmQnnDVMVTvMmPBpBDrCtub7CVW9aavBvF4ZjOLRNy/+ODoHz3kLjvDdMS/UKn1eJ5WrlAImiYsD3hF4YKyGkw==", + "dependencies": { + "find-up": "^5.0.0", + "tslib": "^2.4.1" + }, + "engines": { + "node": ">=12" + }, + "peerDependencies": { + "esbuild": "0.12 - 0.16" + } + }, "node_modules/escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -385,11 +778,39 @@ "node": ">=4" } }, + "node_modules/find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dependencies": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/fs-constants": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" }, + "node_modules/fs-extra": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.0.tgz", + "integrity": "sha512-0rcTq621PD5jM/e0a3EJoGC/1TC5ZBCERW82LQuwfGnCa1V8w7dpYH1yNu+SLb6E5dkeCBzKEyLGlFrnr+dUyw==", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=14.14" + } + }, "node_modules/get-stream": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-2.3.1.tgz", @@ -535,6 +956,31 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" }, + "node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dependencies": { + "p-locate": "^5.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", @@ -658,6 +1104,42 @@ "node": ">=0.10.0" } }, + "node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dependencies": { + "p-limit": "^3.0.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "engines": { + "node": ">=8" + } + }, "node_modules/pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -903,9 +1385,9 @@ "integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg==" }, "node_modules/tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", + "integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==" }, "node_modules/type-fest": { "version": "0.21.3", @@ -927,6 +1409,14 @@ "through": "^2.3.8" } }, + "node_modules/universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -977,9 +1467,158 @@ "buffer-crc32": "~0.2.3", "fd-slicer": "~1.1.0" } + }, + "node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } } }, "dependencies": { + "@esbuild/android-arm": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.16.11.tgz", + "integrity": "sha512-j2xsG1OETgCe+OBA54DG5vLuGjmMZtQvyxt+rTw2aYK/RqjcG/F+UDdj43uoUOv8lSRC3lM4XpKLOVZfY/82yA==", + "optional": true + }, + "@esbuild/android-arm64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.16.11.tgz", + "integrity": "sha512-CPwhZd15PasQSlkFuZv1st37xvuBeklztfb9y2GZWLQu59zcMIDkZVSEz/TTIxzt811+eJfblg5HhP49iVVDWQ==", + "optional": true + }, + "@esbuild/android-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.16.11.tgz", + "integrity": "sha512-vbFn+0JXX6FkKq+0sNeA6aF2QhuOt9ZkBl+DSyqKIF+Ms58lUOhbqSwberKWQDm0udgOp3d/LhOFTYmpvmlZmA==", + "optional": true + }, + "@esbuild/darwin-arm64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.16.11.tgz", + "integrity": "sha512-1tqsIG6AySZ9njT8V2ddH1F/J01zX+0obPCpP0uD9TMIUlAA5WUF/+abFlnIsNY4jACcbN/13NUbLRWE9bayjw==", + "optional": true + }, + "@esbuild/darwin-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.16.11.tgz", + "integrity": "sha512-Gqx2/nYqnK46dwEDPGv3SwLqgLIZQJ7m2xNoNRzO50VZPvoCWSUqDaoirrZZf7uVfl+fxHoZBcdQJx2gOdxffQ==", + "optional": true + }, + "@esbuild/freebsd-arm64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.16.11.tgz", + "integrity": "sha512-58FTdlgIQ3ZxFtGphjbIBmo7kfDhQih/PlfAnKraAcCDZOYXWcRFmHJtW+EVg32IIxuEAqhLAzCgrqpm5o8Wlw==", + "optional": true + }, + "@esbuild/freebsd-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.16.11.tgz", + "integrity": "sha512-L7hr6VnpqZzYEDVQeaViz1QnmfFRCRm3zVtljbYi/CU6InKs6tda1J3pAvqVsbNpbGMA9AvyiyBrgjJAFCawVg==", + "optional": true + }, + "@esbuild/linux-arm": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.16.11.tgz", + "integrity": "sha512-Mk6TZij71alyS0FGuKEKYjTZGjUw2uXi07V/AiGZW1b5grTfGx6lpsbQdystgDJqju99Osq2Ix+C7WteSnwrHg==", + "optional": true + }, + "@esbuild/linux-arm64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.16.11.tgz", + "integrity": "sha512-OKU0ajh9Xu7Pd1MlSq8Xqj5SJEV+4yVnALydPTDrrmTyvU72P8mTRJgZMilHw7H+Jqc0utryjNOwlJ/+fOkwGw==", + "optional": true + }, + "@esbuild/linux-ia32": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.16.11.tgz", + "integrity": "sha512-pr1/tdDfgQQ9hp2IskSKMuwkx2X4jR7iHLbqEmmj/lPLKeoa6AUulnglGY4y0OPo+0eAYd6DzWp7ve3KI4lOCA==", + "optional": true + }, + "@esbuild/linux-loong64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.16.11.tgz", + "integrity": "sha512-2MCYdDBh9R+R1xuBFiApgkbp/tW1uV+aVeefKYqWSEk3o6MHzWo1FxEGA4dSnC+kThSBOMVpCV9z4/DPouA3bQ==", + "optional": true + }, + "@esbuild/linux-mips64el": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.16.11.tgz", + "integrity": "sha512-IyotdnRg0J8F9FKttYe3cy/M9ZJ5W/Gm6whH08sbXMxRVKs/TyyoqFIA8oT1MzR+si6GLlRpcF7JbUnOXssjPA==", + "optional": true + }, + "@esbuild/linux-ppc64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.16.11.tgz", + "integrity": "sha512-NUMtxvb0j41UL8yf8VnTMNbCQxKqIPmF0Wf/N44UrxpKE8iCNmWT95Wt98Ivr2ebHdz+V3kptlgBuZNYcJLI6g==", + "optional": true + }, + "@esbuild/linux-riscv64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.16.11.tgz", + "integrity": "sha512-03/B26az/JezvVkgck+lhauP13t6RqzCQgnrkBCBrXXpX+2r02DfSU43BEhpErJrsrDA8GXSE/rvsfbGCX6OvA==", + "optional": true + }, + "@esbuild/linux-s390x": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.16.11.tgz", + "integrity": "sha512-Xs2tRB0fgly4XfC4FMv1Fd699AMEH8BClp36mzqRuVzm/285XIJaK5cPEZ9cLLn9ukNHdvvSX/83u5uS1BCd8g==", + "optional": true + }, + "@esbuild/linux-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.16.11.tgz", + "integrity": "sha512-CiNialxsjJllrG3ggzOKzSaqQK/De/Mv4g/3r7jxLt01GLerPh0Q3TVTndFG9VfOrR1PdN7Fz5AOV3bE6Isd1Q==", + "optional": true + }, + "@esbuild/netbsd-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.16.11.tgz", + "integrity": "sha512-PiljZi6QZ3Pz0pL8rfJqPln8F/a3mEJwh2vhBb1kDYLniLufo9/7AInb/ZyhvgR7FxUQluUYyz64owPomgaLJA==", + "optional": true + }, + "@esbuild/openbsd-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.16.11.tgz", + "integrity": "sha512-Nyk8aJM+w6NoS4RGQJ0ybb516jEIbEVlLvhRIdpCssUuqKU0lr9lJPHnFY2QqyoVaJkd6VxaHOBU/v/ieuiENQ==", + "optional": true + }, + "@esbuild/sunos-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.16.11.tgz", + "integrity": "sha512-shxBLdNJecr7KxuyZQ19idBU8x7Mq7m+N5Fj8ROWMWQbDdjSjlBPxz7EZJIxSh7FUgSMKl7qSCCVaczXrta4MQ==", + "optional": true + }, + "@esbuild/win32-arm64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.16.11.tgz", + "integrity": "sha512-vyTbfoEBn7cGXK8writbsB+G2wyRoOA+EbTNQ9cu5lyLU65sfWetCaL8T7mX338AN8tTbCYl6ce5YRKTonpA3w==", + "optional": true + }, + "@esbuild/win32-ia32": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.16.11.tgz", + "integrity": "sha512-ATGCGc52LNqakUE9i54RzFC4lm70UTcTW721AFGjQotc6uCg7sf7QeRd05wD5tLBFafHdMSZv4rsU/Nh7LT/rQ==", + "optional": true + }, + "@esbuild/win32-x64": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.16.11.tgz", + "integrity": "sha512-7NcClJIctrO3iRu5CCqwdSBePm8bL2Iu1DYsuOnxuYJ+a1Kv3Wn3MzNdJIrUPLi1yADVwRliRUU/jtMC/tJnJA==", + "optional": true + }, + "@types/node": { + "version": "18.11.18", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", + "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==", + "dev": true + }, "ansi-escapes": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", @@ -1207,6 +1846,44 @@ "once": "^1.4.0" } }, + "esbuild": { + "version": "0.16.11", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.16.11.tgz", + "integrity": "sha512-Al0hhRUz/cCDvDp9VZp1L500HZZQ/HLjgTnQTmnW97+PoLmw+PuvB3e19JHYZtWnrxoh3qYrN/0tiRIbrE2oVQ==", + "requires": { + "@esbuild/android-arm": "0.16.11", + "@esbuild/android-arm64": "0.16.11", + "@esbuild/android-x64": "0.16.11", + "@esbuild/darwin-arm64": "0.16.11", + "@esbuild/darwin-x64": "0.16.11", + "@esbuild/freebsd-arm64": "0.16.11", + "@esbuild/freebsd-x64": "0.16.11", + "@esbuild/linux-arm": "0.16.11", + "@esbuild/linux-arm64": "0.16.11", + "@esbuild/linux-ia32": "0.16.11", + "@esbuild/linux-loong64": "0.16.11", + "@esbuild/linux-mips64el": "0.16.11", + "@esbuild/linux-ppc64": "0.16.11", + "@esbuild/linux-riscv64": "0.16.11", + "@esbuild/linux-s390x": "0.16.11", + "@esbuild/linux-x64": "0.16.11", + "@esbuild/netbsd-x64": "0.16.11", + "@esbuild/openbsd-x64": "0.16.11", + "@esbuild/sunos-x64": "0.16.11", + "@esbuild/win32-arm64": "0.16.11", + "@esbuild/win32-ia32": "0.16.11", + "@esbuild/win32-x64": "0.16.11" + } + }, + "esbuild-node-externals": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/esbuild-node-externals/-/esbuild-node-externals-1.6.0.tgz", + "integrity": "sha512-LmQnnDVMVTvMmPBpBDrCtub7CVW9aavBvF4ZjOLRNy/+ODoHz3kLjvDdMS/UKn1eJ5WrlAImiYsD3hF4YKyGkw==", + "requires": { + "find-up": "^5.0.0", + "tslib": "^2.4.1" + } + }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -1243,11 +1920,30 @@ "resolved": "https://registry.npmjs.org/file-type/-/file-type-5.2.0.tgz", "integrity": "sha512-Iq1nJ6D2+yIO4c8HHg4fyVb8mAJieo1Oloy1mLLaB2PvezNedhBVm+QU7g0qM42aiMbRXTxKKwGD17rjKNJYVQ==" }, + "find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "requires": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + } + }, "fs-constants": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" }, + "fs-extra": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.0.tgz", + "integrity": "sha512-0rcTq621PD5jM/e0a3EJoGC/1TC5ZBCERW82LQuwfGnCa1V8w7dpYH1yNu+SLb6E5dkeCBzKEyLGlFrnr+dUyw==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, "get-stream": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-2.3.1.tgz", @@ -1348,6 +2044,23 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" }, + "jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, + "locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "requires": { + "p-locate": "^5.0.0" + } + }, "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", @@ -1434,6 +2147,27 @@ "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==" }, + "p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "requires": { + "yocto-queue": "^0.1.0" + } + }, + "p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "requires": { + "p-limit": "^3.0.2" + } + }, + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" + }, "pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -1630,9 +2364,9 @@ "integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg==" }, "tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", + "integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==" }, "type-fest": { "version": "0.21.3", @@ -1648,6 +2382,11 @@ "through": "^2.3.8" } }, + "universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -1689,6 +2428,11 @@ "buffer-crc32": "~0.2.3", "fd-slicer": "~1.1.0" } + }, + "yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==" } } } diff --git a/package.json b/package.json index 83b8d75..988fb54 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,10 @@ "name": "neutralinojs-builder", "version": "1.0.0", "description": "A complete solution to make Neutralinojs app distribution packages", - "main": "./src/index.js", + "main": "./dist/index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "build": "tsc && node build.js" }, "repository": { "type": "git", @@ -25,8 +26,14 @@ "chalk": "^4.1.0", "cli-spinner": "^0.2.10", "decompress": "^4.2.1", + "fs-extra": "^11.1.0", "inquirer": "^8.2.4", "node-downloader-helper": "^2.1.1", "ora": "^5.4.1" + }, + "devDependencies": { + "esbuild": "^0.16.11", + "esbuild-node-externals": "^1.6.0", + "@types/node": "^18.11.18" } } diff --git a/src/index.js b/src/index.ts similarity index 91% rename from src/index.js rename to src/index.ts index 98af057..5010904 100644 --- a/src/index.js +++ b/src/index.ts @@ -1,9 +1,9 @@ -const process = require("process"); -const path = require("path"); -const fs = require("fs"); -const utils = require("./utils"); +import process from "process"; +import path from "path"; +import fs from "fs"; +import utils from "./utils"; -const buildAppimage = require("./targets/appimage.js"); +import buildAppimage from "./targets/appimage.js"; let neuModules; @@ -78,7 +78,7 @@ module.exports = { }, }; -const buildForLinux = async (targets = []) => { +const buildForLinux = async (targets: any = []) => { for (const t in targets) { switch (targets[t].target) { case "appimage": diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..0909e53 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,104 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + // "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + // "module": "commonjs", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./dist", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "include": ["src"] +} From baa228442974df41df7d4e61cbb40b9126e0fb7b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 28 Dec 2022 11:40:46 +0530 Subject: [PATCH 2/3] Adds NeuModules type and migrates utils to ts --- package.json | 5 +++-- src/@types/global.d.ts | 25 +++++++++++++++++++++++++ src/index.ts | 17 +++++++++++++---- src/{utils.js => utils.ts} | 27 ++++++++++++++------------- 4 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 src/@types/global.d.ts rename src/{utils.js => utils.ts} (62%) diff --git a/package.json b/package.json index 988fb54..33ee24f 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,9 @@ "ora": "^5.4.1" }, "devDependencies": { + "@types/node": "^18.11.18", + "commander": "^9.4.1", "esbuild": "^0.16.11", - "esbuild-node-externals": "^1.6.0", - "@types/node": "^18.11.18" + "esbuild-node-externals": "^1.6.0" } } diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts new file mode 100644 index 0000000..e5217b6 --- /dev/null +++ b/src/@types/global.d.ts @@ -0,0 +1,25 @@ +type NeuModules = { + bundler: { + bundleApp: (isRelease?: boolean, copyStorage?: boolean) => Promise; + }; + creator: { + bundleApp: (binaryName: string, template?: string) => Promise; + }; + config: { + get: () => any; + update: (key: string, value: any) => void; + }; + downloader: { + downloadTemplate: (template: string) => Promise; + downloadAndUpdateBinaries: () => Promise; + downloadAndUpdateClient: () => Promise; + }; + runner: { + runApp: (options: { argsOpt: string; arch: string }) => Promise; + }; + websocket: { + start: (options: Record) => void; + stop: () => void; + dispatch: (event: string, data: any) => void; + }; +}; diff --git a/src/index.ts b/src/index.ts index 5010904..8e6eb35 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,16 @@ import process from "process"; import path from "path"; import fs from "fs"; -import utils from "./utils"; +import utils from "./utils.js"; +import type { Command } from "commander"; import buildAppimage from "./targets/appimage.js"; -let neuModules; +let neuModules: NeuModules; -module.exports = { +export default { command: "builder [target]", - register: (command, modules) => { + register: (command: Command, modules: NeuModules) => { command .description("builds installers for your Neutalinojs app") .option("--x64", "x64 or x86 amd/intel architecture") @@ -33,6 +34,14 @@ module.exports = { if (!target) { // if the no target, get from neutralino.config.json const builderOptions = neuModules.config.get()?.cli?.builder; + + // if no builderOptions are provided in config throw error + if (!builderOptions) { + utils.handleFatalError( + "No builder options provided in neutralino.config.json" + ); + } + const operatingSys = Object.keys(builderOptions); if (!operatingSys) utils.handleFatalError("Please Specify a target"); diff --git a/src/utils.js b/src/utils.ts similarity index 62% rename from src/utils.js rename to src/utils.ts index a43bc74..3d3fa24 100644 --- a/src/utils.js +++ b/src/utils.ts @@ -1,23 +1,24 @@ -const fs = require("fs"); -const chalk = require("chalk"); +import { PathLike } from "fs"; +import fs from "fs"; +import chalk from "chalk"; -const error = (message) => { +const error = (message: string) => { console.error(`neu builder: ${chalk.bgRed.black("ERROR")} ${message}`); }; -const log = (message) => { +const log = (message: string) => { console.log(`neu builder: ${chalk.bgGreen.black("INFO")} ${message}`); }; -const warn = (message) => { +const warn = (message: string) => { console.warn(`neu builder: ${chalk.bgYellow.black("WARNING")} ${message}`); }; -const isNeutralinojsProject = (CONFIG_FILE) => { +const isNeutralinojsProject = (CONFIG_FILE: PathLike) => { return fs.existsSync(CONFIG_FILE); }; -const checkCurrentProject = (CONFIG_FILE) => { +const checkCurrentProject = (CONFIG_FILE: PathLike) => { if (!isNeutralinojsProject(CONFIG_FILE)) { error( `Unable to find ${CONFIG_FILE}. ` + @@ -27,18 +28,18 @@ const checkCurrentProject = (CONFIG_FILE) => { } }; -const findExt = (path, extension) => { +const findExt = (path: PathLike, extension: string) => { let files = fs.readdirSync(path); - return !!files.filter((file) => + return !!files.filter((file: string) => file.match(new RegExp(`.*\.(${extension})`, "ig")) ); }; -const deleteResources = (resource) => { +const deleteResources = (resource: PathLike) => { return fs.rmSync(resource, { recursive: true, force: true }); }; -const handleFatalError = (message, resource = undefined) => { +const handleFatalError = (message: string, resource = undefined) => { if (!message) return; error(`${message}`); @@ -47,14 +48,14 @@ const handleFatalError = (message, resource = undefined) => { process.exit(1); }; -const handleNoneFatalError = (message, resource = undefined) => { +const handleNoneFatalError = (message: string, resource = undefined) => { if (!message) return; error(`${message}`); if (resource) deleteResources(resource); }; -module.exports = { +export default { error, log, warn, From 9e46b62e3314fa1bba0de00d2ef88a11d47fc206 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 28 Dec 2022 12:59:36 +0530 Subject: [PATCH 3/3] initial migration to ts --- build.js | 1 + package-lock.json | 176 ++++++++++++++++++++++++-- package.json | 3 + src/@types/global.d.ts | 2 + src/index.ts | 10 +- src/modules/downloader.js | 100 --------------- src/modules/downloader.ts | 108 ++++++++++++++++ src/scripts/AppRun.js | 41 ------ src/scripts/AppRun.ts | 49 ++++++++ src/scripts/DesktopFile.js | 51 -------- src/scripts/DesktopFile.ts | 57 +++++++++ src/targets/appimage.js | 251 ------------------------------------- src/targets/appimage.ts | 249 ++++++++++++++++++++++++++++++++++++ src/targets/test.js | 9 -- src/utils.ts | 30 ++--- tsconfig.json | 2 +- 16 files changed, 651 insertions(+), 488 deletions(-) delete mode 100644 src/modules/downloader.js create mode 100644 src/modules/downloader.ts delete mode 100644 src/scripts/AppRun.js create mode 100644 src/scripts/AppRun.ts delete mode 100644 src/scripts/DesktopFile.js create mode 100644 src/scripts/DesktopFile.ts delete mode 100644 src/targets/appimage.js create mode 100644 src/targets/appimage.ts delete mode 100644 src/targets/test.js diff --git a/build.js b/build.js index e0430a4..eac1b64 100644 --- a/build.js +++ b/build.js @@ -3,6 +3,7 @@ const esbuild = require('esbuild') // Automatically exclude all node_modules from the bundled version const { nodeExternalsPlugin } = require('esbuild-node-externals') + esbuild.build({ entryPoints: ['./src/index.ts'], outdir: 'dist', diff --git a/package-lock.json b/package-lock.json index 13fc8ee..dd6c1d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,15 +12,19 @@ "chalk": "^4.1.0", "cli-spinner": "^0.2.10", "decompress": "^4.2.1", - "esbuild": "^0.16.11", - "esbuild-node-externals": "^1.6.0", "fs-extra": "^11.1.0", "inquirer": "^8.2.4", "node-downloader-helper": "^2.1.1", "ora": "^5.4.1" }, "devDependencies": { - "@types/node": "^18.11.18" + "@types/chalk": "^2.2.0", + "@types/fs-extra": "^9.0.13", + "@types/inquirer": "^8.2.4", + "@types/node": "^18.11.18", + "commander": "^9.4.1", + "esbuild": "^0.16.11", + "esbuild-node-externals": "^1.6.0" } }, "node_modules/@esbuild/android-arm": { @@ -30,6 +34,7 @@ "cpu": [ "arm" ], + "dev": true, "optional": true, "os": [ "android" @@ -45,6 +50,7 @@ "cpu": [ "arm64" ], + "dev": true, "optional": true, "os": [ "android" @@ -60,6 +66,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "android" @@ -75,6 +82,7 @@ "cpu": [ "arm64" ], + "dev": true, "optional": true, "os": [ "darwin" @@ -90,6 +98,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "darwin" @@ -105,6 +114,7 @@ "cpu": [ "arm64" ], + "dev": true, "optional": true, "os": [ "freebsd" @@ -120,6 +130,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "freebsd" @@ -135,6 +146,7 @@ "cpu": [ "arm" ], + "dev": true, "optional": true, "os": [ "linux" @@ -150,6 +162,7 @@ "cpu": [ "arm64" ], + "dev": true, "optional": true, "os": [ "linux" @@ -165,6 +178,7 @@ "cpu": [ "ia32" ], + "dev": true, "optional": true, "os": [ "linux" @@ -180,6 +194,7 @@ "cpu": [ "loong64" ], + "dev": true, "optional": true, "os": [ "linux" @@ -195,6 +210,7 @@ "cpu": [ "mips64el" ], + "dev": true, "optional": true, "os": [ "linux" @@ -210,6 +226,7 @@ "cpu": [ "ppc64" ], + "dev": true, "optional": true, "os": [ "linux" @@ -225,6 +242,7 @@ "cpu": [ "riscv64" ], + "dev": true, "optional": true, "os": [ "linux" @@ -240,6 +258,7 @@ "cpu": [ "s390x" ], + "dev": true, "optional": true, "os": [ "linux" @@ -255,6 +274,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "linux" @@ -270,6 +290,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "netbsd" @@ -285,6 +306,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "openbsd" @@ -300,6 +322,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "sunos" @@ -315,6 +338,7 @@ "cpu": [ "arm64" ], + "dev": true, "optional": true, "os": [ "win32" @@ -330,6 +354,7 @@ "cpu": [ "ia32" ], + "dev": true, "optional": true, "os": [ "win32" @@ -345,6 +370,7 @@ "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "win32" @@ -353,12 +379,49 @@ "node": ">=12" } }, + "node_modules/@types/chalk": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@types/chalk/-/chalk-2.2.0.tgz", + "integrity": "sha512-1zzPV9FDe1I/WHhRkf9SNgqtRJWZqrBWgu7JGveuHmmyR9CnAPCie2N/x+iHrgnpYBIcCJWHBoMRv2TRWktsvw==", + "deprecated": "This is a stub types definition for chalk (https://github.com/chalk/chalk). chalk provides its own type definitions, so you don't need @types/chalk installed!", + "dev": true, + "dependencies": { + "chalk": "*" + } + }, + "node_modules/@types/fs-extra": { + "version": "9.0.13", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.13.tgz", + "integrity": "sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/inquirer": { + "version": "8.2.5", + "resolved": "https://registry.npmjs.org/@types/inquirer/-/inquirer-8.2.5.tgz", + "integrity": "sha512-QXlzybid60YtAwfgG3cpykptRYUx2KomzNutMlWsQC64J/WG/gQSl+P4w7A21sGN0VIxRVava4rgnT7FQmFCdg==", + "dev": true, + "dependencies": { + "@types/through": "*" + } + }, "node_modules/@types/node": { "version": "18.11.18", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==", "dev": true }, + "node_modules/@types/through": { + "version": "0.0.30", + "resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.30.tgz", + "integrity": "sha512-FvnCJljyxhPM3gkRgWmxmDZyAQSiBQQWLI0A0VFL0K7W1oRUrPJSqNO0NvTnLkBcotdlp3lKvaT0JrnyRDkzOg==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/ansi-escapes": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", @@ -557,9 +620,13 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, "node_modules/commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.4.1.tgz", + "integrity": "sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw==", + "dev": true, + "engines": { + "node": "^12.20.0 || >=14" + } }, "node_modules/core-util-is": { "version": "1.0.3", @@ -680,6 +747,7 @@ "version": "0.16.11", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.16.11.tgz", "integrity": "sha512-Al0hhRUz/cCDvDp9VZp1L500HZZQ/HLjgTnQTmnW97+PoLmw+PuvB3e19JHYZtWnrxoh3qYrN/0tiRIbrE2oVQ==", + "dev": true, "hasInstallScript": true, "bin": { "esbuild": "bin/esbuild" @@ -716,6 +784,7 @@ "version": "1.6.0", "resolved": "https://registry.npmjs.org/esbuild-node-externals/-/esbuild-node-externals-1.6.0.tgz", "integrity": "sha512-LmQnnDVMVTvMmPBpBDrCtub7CVW9aavBvF4ZjOLRNy/+ODoHz3kLjvDdMS/UKn1eJ5WrlAImiYsD3hF4YKyGkw==", + "dev": true, "dependencies": { "find-up": "^5.0.0", "tslib": "^2.4.1" @@ -782,6 +851,7 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, "dependencies": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" @@ -971,6 +1041,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, "dependencies": { "p-locate": "^5.0.0" }, @@ -1108,6 +1179,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, "dependencies": { "yocto-queue": "^0.1.0" }, @@ -1122,6 +1194,7 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, "dependencies": { "p-limit": "^3.0.2" }, @@ -1136,6 +1209,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, "engines": { "node": ">=8" } @@ -1254,6 +1328,11 @@ "seek-table": "bin/seek-bzip-table" } }, + "node_modules/seek-bzip/node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + }, "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", @@ -1472,6 +1551,7 @@ "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, "engines": { "node": ">=10" }, @@ -1485,140 +1565,198 @@ "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.16.11.tgz", "integrity": "sha512-j2xsG1OETgCe+OBA54DG5vLuGjmMZtQvyxt+rTw2aYK/RqjcG/F+UDdj43uoUOv8lSRC3lM4XpKLOVZfY/82yA==", + "dev": true, "optional": true }, "@esbuild/android-arm64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.16.11.tgz", "integrity": "sha512-CPwhZd15PasQSlkFuZv1st37xvuBeklztfb9y2GZWLQu59zcMIDkZVSEz/TTIxzt811+eJfblg5HhP49iVVDWQ==", + "dev": true, "optional": true }, "@esbuild/android-x64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.16.11.tgz", "integrity": "sha512-vbFn+0JXX6FkKq+0sNeA6aF2QhuOt9ZkBl+DSyqKIF+Ms58lUOhbqSwberKWQDm0udgOp3d/LhOFTYmpvmlZmA==", + "dev": true, "optional": true }, "@esbuild/darwin-arm64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.16.11.tgz", "integrity": "sha512-1tqsIG6AySZ9njT8V2ddH1F/J01zX+0obPCpP0uD9TMIUlAA5WUF/+abFlnIsNY4jACcbN/13NUbLRWE9bayjw==", + "dev": true, "optional": true }, "@esbuild/darwin-x64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.16.11.tgz", "integrity": "sha512-Gqx2/nYqnK46dwEDPGv3SwLqgLIZQJ7m2xNoNRzO50VZPvoCWSUqDaoirrZZf7uVfl+fxHoZBcdQJx2gOdxffQ==", + "dev": true, "optional": true }, "@esbuild/freebsd-arm64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.16.11.tgz", "integrity": "sha512-58FTdlgIQ3ZxFtGphjbIBmo7kfDhQih/PlfAnKraAcCDZOYXWcRFmHJtW+EVg32IIxuEAqhLAzCgrqpm5o8Wlw==", + "dev": true, "optional": true }, "@esbuild/freebsd-x64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.16.11.tgz", "integrity": "sha512-L7hr6VnpqZzYEDVQeaViz1QnmfFRCRm3zVtljbYi/CU6InKs6tda1J3pAvqVsbNpbGMA9AvyiyBrgjJAFCawVg==", + "dev": true, "optional": true }, "@esbuild/linux-arm": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.16.11.tgz", "integrity": "sha512-Mk6TZij71alyS0FGuKEKYjTZGjUw2uXi07V/AiGZW1b5grTfGx6lpsbQdystgDJqju99Osq2Ix+C7WteSnwrHg==", + "dev": true, "optional": true }, "@esbuild/linux-arm64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.16.11.tgz", "integrity": "sha512-OKU0ajh9Xu7Pd1MlSq8Xqj5SJEV+4yVnALydPTDrrmTyvU72P8mTRJgZMilHw7H+Jqc0utryjNOwlJ/+fOkwGw==", + "dev": true, "optional": true }, "@esbuild/linux-ia32": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.16.11.tgz", "integrity": "sha512-pr1/tdDfgQQ9hp2IskSKMuwkx2X4jR7iHLbqEmmj/lPLKeoa6AUulnglGY4y0OPo+0eAYd6DzWp7ve3KI4lOCA==", + "dev": true, "optional": true }, "@esbuild/linux-loong64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.16.11.tgz", "integrity": "sha512-2MCYdDBh9R+R1xuBFiApgkbp/tW1uV+aVeefKYqWSEk3o6MHzWo1FxEGA4dSnC+kThSBOMVpCV9z4/DPouA3bQ==", + "dev": true, "optional": true }, "@esbuild/linux-mips64el": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.16.11.tgz", "integrity": "sha512-IyotdnRg0J8F9FKttYe3cy/M9ZJ5W/Gm6whH08sbXMxRVKs/TyyoqFIA8oT1MzR+si6GLlRpcF7JbUnOXssjPA==", + "dev": true, "optional": true }, "@esbuild/linux-ppc64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.16.11.tgz", "integrity": "sha512-NUMtxvb0j41UL8yf8VnTMNbCQxKqIPmF0Wf/N44UrxpKE8iCNmWT95Wt98Ivr2ebHdz+V3kptlgBuZNYcJLI6g==", + "dev": true, "optional": true }, "@esbuild/linux-riscv64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.16.11.tgz", "integrity": "sha512-03/B26az/JezvVkgck+lhauP13t6RqzCQgnrkBCBrXXpX+2r02DfSU43BEhpErJrsrDA8GXSE/rvsfbGCX6OvA==", + "dev": true, "optional": true }, "@esbuild/linux-s390x": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.16.11.tgz", "integrity": "sha512-Xs2tRB0fgly4XfC4FMv1Fd699AMEH8BClp36mzqRuVzm/285XIJaK5cPEZ9cLLn9ukNHdvvSX/83u5uS1BCd8g==", + "dev": true, "optional": true }, "@esbuild/linux-x64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.16.11.tgz", "integrity": "sha512-CiNialxsjJllrG3ggzOKzSaqQK/De/Mv4g/3r7jxLt01GLerPh0Q3TVTndFG9VfOrR1PdN7Fz5AOV3bE6Isd1Q==", + "dev": true, "optional": true }, "@esbuild/netbsd-x64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.16.11.tgz", "integrity": "sha512-PiljZi6QZ3Pz0pL8rfJqPln8F/a3mEJwh2vhBb1kDYLniLufo9/7AInb/ZyhvgR7FxUQluUYyz64owPomgaLJA==", + "dev": true, "optional": true }, "@esbuild/openbsd-x64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.16.11.tgz", "integrity": "sha512-Nyk8aJM+w6NoS4RGQJ0ybb516jEIbEVlLvhRIdpCssUuqKU0lr9lJPHnFY2QqyoVaJkd6VxaHOBU/v/ieuiENQ==", + "dev": true, "optional": true }, "@esbuild/sunos-x64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.16.11.tgz", "integrity": "sha512-shxBLdNJecr7KxuyZQ19idBU8x7Mq7m+N5Fj8ROWMWQbDdjSjlBPxz7EZJIxSh7FUgSMKl7qSCCVaczXrta4MQ==", + "dev": true, "optional": true }, "@esbuild/win32-arm64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.16.11.tgz", "integrity": "sha512-vyTbfoEBn7cGXK8writbsB+G2wyRoOA+EbTNQ9cu5lyLU65sfWetCaL8T7mX338AN8tTbCYl6ce5YRKTonpA3w==", + "dev": true, "optional": true }, "@esbuild/win32-ia32": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.16.11.tgz", "integrity": "sha512-ATGCGc52LNqakUE9i54RzFC4lm70UTcTW721AFGjQotc6uCg7sf7QeRd05wD5tLBFafHdMSZv4rsU/Nh7LT/rQ==", + "dev": true, "optional": true }, "@esbuild/win32-x64": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.16.11.tgz", "integrity": "sha512-7NcClJIctrO3iRu5CCqwdSBePm8bL2Iu1DYsuOnxuYJ+a1Kv3Wn3MzNdJIrUPLi1yADVwRliRUU/jtMC/tJnJA==", + "dev": true, "optional": true }, + "@types/chalk": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@types/chalk/-/chalk-2.2.0.tgz", + "integrity": "sha512-1zzPV9FDe1I/WHhRkf9SNgqtRJWZqrBWgu7JGveuHmmyR9CnAPCie2N/x+iHrgnpYBIcCJWHBoMRv2TRWktsvw==", + "dev": true, + "requires": { + "chalk": "*" + } + }, + "@types/fs-extra": { + "version": "9.0.13", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.13.tgz", + "integrity": "sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/inquirer": { + "version": "8.2.5", + "resolved": "https://registry.npmjs.org/@types/inquirer/-/inquirer-8.2.5.tgz", + "integrity": "sha512-QXlzybid60YtAwfgG3cpykptRYUx2KomzNutMlWsQC64J/WG/gQSl+P4w7A21sGN0VIxRVava4rgnT7FQmFCdg==", + "dev": true, + "requires": { + "@types/through": "*" + } + }, "@types/node": { "version": "18.11.18", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==", "dev": true }, + "@types/through": { + "version": "0.0.30", + "resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.30.tgz", + "integrity": "sha512-FvnCJljyxhPM3gkRgWmxmDZyAQSiBQQWLI0A0VFL0K7W1oRUrPJSqNO0NvTnLkBcotdlp3lKvaT0JrnyRDkzOg==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "ansi-escapes": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", @@ -1744,9 +1882,10 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, "commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.4.1.tgz", + "integrity": "sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw==", + "dev": true }, "core-util-is": { "version": "1.0.3", @@ -1850,6 +1989,7 @@ "version": "0.16.11", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.16.11.tgz", "integrity": "sha512-Al0hhRUz/cCDvDp9VZp1L500HZZQ/HLjgTnQTmnW97+PoLmw+PuvB3e19JHYZtWnrxoh3qYrN/0tiRIbrE2oVQ==", + "dev": true, "requires": { "@esbuild/android-arm": "0.16.11", "@esbuild/android-arm64": "0.16.11", @@ -1879,6 +2019,7 @@ "version": "1.6.0", "resolved": "https://registry.npmjs.org/esbuild-node-externals/-/esbuild-node-externals-1.6.0.tgz", "integrity": "sha512-LmQnnDVMVTvMmPBpBDrCtub7CVW9aavBvF4ZjOLRNy/+ODoHz3kLjvDdMS/UKn1eJ5WrlAImiYsD3hF4YKyGkw==", + "dev": true, "requires": { "find-up": "^5.0.0", "tslib": "^2.4.1" @@ -1924,6 +2065,7 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, "requires": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" @@ -2057,6 +2199,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, "requires": { "p-locate": "^5.0.0" } @@ -2151,6 +2294,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, "requires": { "yocto-queue": "^0.1.0" } @@ -2159,6 +2303,7 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, "requires": { "p-limit": "^3.0.2" } @@ -2166,7 +2311,8 @@ "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true }, "pend": { "version": "1.2.0", @@ -2244,6 +2390,13 @@ "integrity": "sha512-e1QtP3YL5tWww8uKaOCQ18UxIT2laNBXHjV/S2WYCiK4udiv8lkG89KRIoCjUagnAmCBurjF4zEVX2ByBbnCjQ==", "requires": { "commander": "^2.8.1" + }, + "dependencies": { + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + } } }, "signal-exit": { @@ -2432,7 +2585,8 @@ "yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", - "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==" + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true } } } diff --git a/package.json b/package.json index 33ee24f..54683d6 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,9 @@ "ora": "^5.4.1" }, "devDependencies": { + "@types/chalk": "^2.2.0", + "@types/fs-extra": "^9.0.13", + "@types/inquirer": "^8.2.4", "@types/node": "^18.11.18", "commander": "^9.4.1", "esbuild": "^0.16.11", diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index e5217b6..d18282f 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -23,3 +23,5 @@ type NeuModules = { dispatch: (event: string, data: any) => void; }; }; + +type BuildConfig = Record; diff --git a/src/index.ts b/src/index.ts index 8e6eb35..98bf4b2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,14 @@ import process from "process"; import path from "path"; import fs from "fs"; -import utils from "./utils.js"; +import * as utils from "./utils"; import type { Command } from "commander"; -import buildAppimage from "./targets/appimage.js"; +import buildAppimage from "./targets/appimage"; let neuModules: NeuModules; -export default { +const builderPlugin = { command: "builder [target]", register: (command: Command, modules: NeuModules) => { command @@ -106,3 +106,7 @@ const buildForLinux = async (targets: any = []) => { } } }; + +// neu cli requires the command and register to be present as named export +export const command = builderPlugin.command; +export const register = builderPlugin.register; diff --git a/src/modules/downloader.js b/src/modules/downloader.js deleted file mode 100644 index 915331c..0000000 --- a/src/modules/downloader.js +++ /dev/null @@ -1,100 +0,0 @@ -const { DownloaderHelper } = require("node-downloader-helper"); -const ora = require("ora"); -const path = require("path"); -const inquirer = require("inquirer"); -const utils = require("../utils"); - -const download = async (url, writePath, appName = undefined) => { - let downloadUrl; - try { - downloadUrl = new URL(url); - } catch (err) { - utils.handleFatalError(err.message); - } - - const spinner = ora(""); - const dl = new DownloaderHelper(url, writePath); - - const app = await dl.getTotalSize(); - await getUserConsent(app, downloadUrl.protocol); - - const name = appName || app.name; - - const timeout = checkTimeOut( - "The download process timed out, please check your internet connection", - path.join(writePath, name) - ); - - dl.on("stateChanged", (state) => { - if (state === "STARTED") - utils.log(`connecting to ${downloadUrl.hostname}...`); - - if (state === "DOWNLOADING") { - timeout.ref(); - } - }); - - dl.on("progress", ({ progress, speed }) => { - timeout.refresh(); - - if (!spinner.isSpinning) spinner.start(); - spinner.text = `Downloading ${name} from ${ - downloadUrl.hostname - } ${progress.toFixed(0)}% | ${speed}b/s`; - }); - - dl.once("error", (err) => { - spinner.stop(); - utils.handleFatalError(err.message); - }); - - dl.on("warning", (err) => { - spinner.stop(); - utils.warn(err.message); - }); - - dl.once("end", (stats) => { - timeout.unref(); - - spinner.stop(); - dl.removeAllListeners(); - return stats; - }); - - await dl.start(); -}; - -const checkTimeOut = (message, resource) => { - const timeout = setTimeout(() => { - utils.handleFatalError(message, resource); - }, 8000); - - timeout.unref(); - - return timeout; -}; - -const getUserConsent = async (app, protocol) => { - const alertNotHTTPSProtocol = - protocol !== "https:" && protocol !== "https" - ? `The protocol being used is ${protocol}. Make sure you trust this connection` - : ""; - - const answers = await inquirer.prompt([ - { - type: "confirm", - name: "download", - message: `You need to dowload ${app.name}, It will use up ${( - app.total / 1000000 - ).toFixed(3)}mb. ${alertNotHTTPSProtocol}`, - }, - ]); - - if (answers.download) { - return true; - } else { - utils.handleFatalError("user terminated the process"); - } -}; - -module.exports = download; diff --git a/src/modules/downloader.ts b/src/modules/downloader.ts new file mode 100644 index 0000000..747b2f2 --- /dev/null +++ b/src/modules/downloader.ts @@ -0,0 +1,108 @@ +import { DownloaderHelper } from "node-downloader-helper"; +import ora from "ora"; +import { join } from "path"; +import { prompt } from "inquirer"; +import { error, handleFatalError, log, warn } from "../utils"; +import { PathLike } from "fs"; +import { URL } from "url"; + +const download = async (url: string, writePath: PathLike, appName?: string) => { + try { + let downloadUrl = new URL(url); + + if (!download) { + error("Resourse download path not present"); + process.exit(1); + } + + const spinner = ora(""); + const dl = new DownloaderHelper(url, writePath.toString()); + + const app = await dl.getTotalSize(); + await getUserConsent(app, downloadUrl.protocol); + + const name = appName || app.name; + + const timeout = checkTimeOut( + "The download process timed out, please check your internet connection", + join(writePath as string, name) + ); + + dl.on("stateChanged", (state) => { + if (state === "STARTED") log(`connecting to ${downloadUrl.hostname}...`); + + if (state === "DOWNLOADING") { + timeout.ref(); + } + }); + + dl.on("progress", ({ progress, speed }) => { + timeout.refresh(); + + if (!spinner.isSpinning) spinner.start(); + spinner.text = `Downloading ${name} from ${ + downloadUrl.hostname + } ${progress.toFixed(0)}% | ${speed}b/s`; + }); + + dl.once("error", (err) => { + spinner.stop(); + handleFatalError(err.message); + }); + + dl.on("warning", (err) => { + spinner.stop(); + warn(err.message); + }); + + dl.once("end", (stats) => { + timeout.unref(); + + spinner.stop(); + dl.removeAllListeners(); + return stats; + }); + + await dl.start(); + } catch (error: any) { + handleFatalError(error.message); + } +}; + +const checkTimeOut = (message: string, resource: string) => { + const timeout = setTimeout(() => { + handleFatalError(message, resource); + }, 8000); + + timeout.unref(); + + return timeout; +}; + +const getUserConsent = async ( + app: { name: string; total: number | null }, + protocol: string +) => { + const alertNotHTTPSProtocol = + protocol !== "https:" && protocol !== "https" + ? `The protocol being used is ${protocol}. Make sure you trust this connection` + : ""; + + const answers = await prompt([ + { + type: "confirm", + name: "download", + message: `You need to dowload ${app.name}, It will use up ${( + (app.total ?? 0) / 1000000 + ).toFixed(3)}mb. ${alertNotHTTPSProtocol}`, + }, + ]); + + if (answers.download) { + return true; + } else { + handleFatalError("user terminated the process"); + } +}; + +export default download; diff --git a/src/scripts/AppRun.js b/src/scripts/AppRun.js deleted file mode 100644 index 9d4f855..0000000 --- a/src/scripts/AppRun.js +++ /dev/null @@ -1,41 +0,0 @@ -const path = require("path"); -const { execSync } = require("child_process"); -const fs = require("fs"); - -class AppRun { - #self = ""; - #here = ""; - #exec = ""; - #execPath = ""; - - set(execPath) { - this.#self = `$(readlink -f "$0")`; - this.#here = "${SELF%/*}"; - this.#exec = "${HERE}" + execPath; - this.#execPath = "${EXEC}"; - } - - get() { - return { - self: this.#self, - here: this.#here, - exec: this.#exec, - execPath: this.#execPath, - }; - } - - writeScript(writePath) { - const src = this.get(); - - fs.writeFileSync( - path.join(writePath, "AppRun"), - `#!/bin/sh ${Object.keys(src) - .map((key) => "\n" + key.toUpperCase() + "=" + src[key]) - .join("")} \nexec ${this.#exec}` - ); - - execSync("chmod 777 " + path.join(writePath, "AppRun")); - } -} - -module.exports = AppRun; diff --git a/src/scripts/AppRun.ts b/src/scripts/AppRun.ts new file mode 100644 index 0000000..3aa52ae --- /dev/null +++ b/src/scripts/AppRun.ts @@ -0,0 +1,49 @@ +const path = require("path"); +const { execSync } = require("child_process"); +const fs = require("fs"); + +export type AppRunConfig = { + self: string; + here: string; + exec: string; + execPath: string; +}; + +export default class AppRun { + self = ""; + here = ""; + exec = ""; + execPath = ""; + + set(execPath: string) { + this.self = `$(readlink -f "$0")`; + this.here = "${SELF%/*}"; + this.exec = "${HERE}" + execPath; + this.execPath = "${EXEC}"; + } + + get() { + return { + self: this.self, + here: this.here, + exec: this.exec, + execPath: this.execPath, + }; + } + + writeScript(writePath: string) { + const src = this.get(); + + fs.writeFileSync( + path.join(writePath, "AppRun"), + `#!/bin/sh ${Object.keys(src) + .map( + (key) => + "\n" + key.toUpperCase() + "=" + src[key as keyof AppRunConfig] + ) + .join("")} \nexec ${this.exec}` + ); + + execSync("chmod 777 " + path.join(writePath, "AppRun")); + } +} diff --git a/src/scripts/DesktopFile.js b/src/scripts/DesktopFile.js deleted file mode 100644 index 0110695..0000000 --- a/src/scripts/DesktopFile.js +++ /dev/null @@ -1,51 +0,0 @@ -const fs = require("fs"); -const path = require("path"); -const { execSync } = require("child_process"); -const os = require("os"); - -class DesktopFile { - #name = ""; - #exec = ""; - #icon = ""; - #type = ""; - #categories = ""; - - set({ name, exec, icon, type, categories }) { - this.#name = name; - this.#exec = exec; - this.#icon = icon; - this.#type = type || "Application"; - this.#categories = categories || "Utility"; - } - - get() { - return { - name: this.#name, - exec: this.#exec, - icon: this.#icon, - type: this.#type, - categories: this.#categories, - }; - } - - writeScript(writePath, appName) { - const src = this.get(); - const desktopFile = path.join(writePath, `${appName}.desktop`); - - fs.writeFileSync( - desktopFile, - "[Desktop Entry]" + - `${Object.keys(src) - .map((k) => { - const key = k.charAt(0).toUpperCase() + k.slice(1); - - return "\n" + key + "=" + src[k]; - }) - .join("")}` - ); - - execSync("chmod 777 " + desktopFile); - } -} - -module.exports = DesktopFile; diff --git a/src/scripts/DesktopFile.ts b/src/scripts/DesktopFile.ts new file mode 100644 index 0000000..0773305 --- /dev/null +++ b/src/scripts/DesktopFile.ts @@ -0,0 +1,57 @@ +const fs = require("fs"); +const path = require("path"); +const { execSync } = require("child_process"); +const os = require("os"); + +export type AppImageConfig = { + name: string; + exec: string; + icon: string; + type: string; + categories: string; +}; + +export default class DesktopFile { + private name = ""; + private exec = ""; + private icon = ""; + private type = ""; + private categories = ""; + + set({ name, exec, icon, type, categories }: AppImageConfig) { + this.name = name; + this.exec = exec; + this.icon = icon; + this.type = type || "Application"; + this.categories = categories || "Utility"; + } + + get() { + return { + name: this.name, + exec: this.exec, + icon: this.icon, + type: this.type, + categories: this.categories, + }; + } + + writeScript(writePath: string, appName: string) { + const src = this.get(); + const desktopFile = path.join(writePath, `${appName}.desktop`); + + fs.writeFileSync( + desktopFile, + "[Desktop Entry]" + + `${Object.keys(src) + .map((k) => { + const key = k.charAt(0).toUpperCase() + k.slice(1); + + return "\n" + key + "=" + src[k as keyof AppImageConfig]; + }) + .join("")}` + ); + + execSync("chmod 777 " + desktopFile); + } +} diff --git a/src/targets/appimage.js b/src/targets/appimage.js deleted file mode 100644 index 553f0c5..0000000 --- a/src/targets/appimage.js +++ /dev/null @@ -1,251 +0,0 @@ -const inquirer = require("inquirer"); -const path = require("path"); -const os = require("os"); -const fs = require("fs-extra"); -const process = require("process"); -const { execSync, spawn } = require("child_process"); - -const download = require("../modules/downloader"); -const DesktopFile = require("../scripts/DesktopFile.js"); -const desktopFile = new DesktopFile(); - -const utils = require("../utils.js"); -const AppRun = require("../scripts/AppRun"); -const appRun = new AppRun(); - -const osTempDir = path.join(os.tmpdir(), "appImage"); -const tmpdir = path.join(process.cwd(), ".tmp"); -const AppDir = path.join(tmpdir, "AppDir"); -let appimageConfig; -let appimageTool; - -const configObj = { - build_ARCH: "", - sys_ARCH: "", - icon: "", - appName: "", - arch: "", -}; - -const buildAppimage = async (archList = ["x64", "arm64"], config) => { - const findAppimage = (t) => t.target === "appimage"; - - for (const key in archList) { - const findArch = (t) => t.arch?.find((a) => a === archList[key]); - - appimageConfig = config.cli?.builder?.linux?.targets?.find( - (findAppimage && findArch) || findAppimage - ); - - configObj.build_ARCH = archList[key]; - configObj.icon = config.modes.window.icon; - configObj.appName = config.cli.binaryName; - - if (configObj.build_ARCH === "x64") configObj.arch = "x86_64"; - else if (configObj.build_ARCH === "arm64") configObj.arch = "aarch64"; - - if (os.arch() === "x64") configObj.sys_ARCH = "x86_64"; - else if (os.arch() === "arm64") configObj.sys_ARCH = "aarch64"; - - const appImage = `${configObj.appName}-${configObj.arch}.AppImage`; - - utils.log(`building ${appImage}...`); - - await buildAppDir(); - await getAppImageTool(); - await configureAppImage(); - - try { - execSync(`mv ${appImage} ${path.join(process.cwd(), "dist")}`); - } catch (err) { - utils.handleNoneFatalError(err.message); - } - } - - console.log("Built your appimage(s) successfully!! 🚀"); - console.log("check your dist folder"); - console.log(""); -}; - -const buildAppDir = async () => { - await createAppDir(); - configureAppDir(); -}; - -const createAppDir = async () => { - if (!fs.existsSync(tmpdir)) { - try { - fs.mkdirSync(tmpdir); - } catch (error) { - utils.handleFatalError(error.message); - } - } - - if (fs.existsSync(AppDir)) { - const answers = await inquirer.prompt([ - { - type: "confirm", - name: "overwrite", - message: `An AppDir folder already exists in your .tmp dir would you like to overwrite it`, - default: true, - }, - ]); - - if (answers.overwrite) { - utils.deleteResources(AppDir); - } else { - console.log("closing..."); - process.exit(1); - } - } - - try { - fs.mkdirSync(path.join(AppDir, "usr", "bin"), { recursive: true }); - } catch (err) { - utils.handleFatalError(err.message, AppDir); - } -}; - -const configureAppDir = async () => { - const { appName, build_ARCH } = configObj; - - const binary = path.join( - process.cwd(), - "dist", - `${appName}`, - `${appName}-linux_${build_ARCH}` - ); - - const resources = path.join( - process.cwd(), - "dist", - `${appName}`, - "resources.neu" - ); - - if (!appimageConfig?.icon) - utils.warn("no icon inculded, a default neutralino icon will be used"); - - try { - execSync( - `chmod 755 ${binary} && cp ${binary} ${path.join(AppDir, "usr", "bin")}` - ); - execSync(`cp ${resources} ${path.join(AppDir, "usr", "bin")}`); - execSync( - `cp ${path.join( - process.cwd(), - appimageConfig?.icon || configObj.icon - )} ${AppDir}` - ); - } catch (err) { - utils.handleFatalError(err.message, AppDir); - } - - buildDesktopFile(); - buildAppRun(); -}; - -const buildDesktopFile = () => { - const { appName, build_ARCH, icon } = configObj; - - const exec = `${appName}-linux_${build_ARCH}`; - const appIcon = appimageConfig?.icon || icon; - - desktopFile.set({ - name: appName, - exec: exec, - icon: path.basename(appIcon, path.extname(appIcon)), - type: appimageConfig?.type, - categories: appimageConfig?.categories, - }); - - try { - desktopFile.writeScript(path.join(AppDir), appName); - } catch (err) { - utils.handleFatalError(err.message, AppDir); - } -}; - -const buildAppRun = () => { - const { appName, build_ARCH } = configObj; - appRun.set(`/usr/bin/${appName}-linux_${build_ARCH}`); - - try { - appRun.writeScript(AppDir); - } catch (err) { - utils.handleFatalError(err.message, AppDir); - } -}; - -const getAppImageTool = async () => { - const { sys_ARCH } = configObj; - const appimageSpec = `appimagetool-${sys_ARCH}.AppImage`; - appimageTool = path.join(osTempDir, appimageSpec); - fs; - - if ( - !fs.existsSync(path.join(process.cwd(), appimageSpec)) && - !fs.existsSync(appimageTool) - ) { - const appImageToolUrl = `https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-${sys_ARCH}.AppImage`; - - try { - if (!fs.existsSync(osTempDir)) fs.mkdirSync(osTempDir); - await download(appImageToolUrl, osTempDir); - } catch (err) { - utils.handleFatalError(err.message, AppDir); - } - } else if (fs.existsSync(path.join(process.cwd(), appimageSpec))) { - appimageTool = path.join(process.cwd(), appimageSpec); - } - - try { - execSync("chmod 777 " + appimageTool); - } catch (err) { - utils.handleFatalError(err.message, AppDir); - } -}; - -const configureAppImage = () => { - const { arch } = configObj; - - return new Promise((resolve, reject) => { - console.log(appimageTool); - - let child; - try { - child = spawn(`${appimageTool}`, [AppDir], { - env: { ARCH: arch }, - }); - } catch (err) { - utils.error(err); - } - - child.stderr.on("data", (data) => utils.log(`${data}`)); - child.stdout.on("data", (data) => utils.log(`${data}`)); - - child.on("error", (err) => { - reject( - utils.handleFatalError( - `${err}, this error orignated from the appimagetool` - ) - ); - }); - - child.on("exit", (code) => { - utils.deleteResources(AppDir); - - if (code !== 0) { - reject( - utils.handleFatalError( - `process exited with code ${code}, this error orignated from the appimagetool` - ) - ); - } - - resolve(); - }); - }); -}; - -module.exports = buildAppimage; diff --git a/src/targets/appimage.ts b/src/targets/appimage.ts new file mode 100644 index 0000000..5f818f1 --- /dev/null +++ b/src/targets/appimage.ts @@ -0,0 +1,249 @@ +import { join, basename, extname } from "path"; +import { tmpdir as _tmpdir, arch as _arch } from "os"; +import fs, { existsSync, mkdirSync } from "fs-extra"; +import { cwd, exit } from "process"; +import { execSync, spawn } from "child_process"; +import * as inquirer from "inquirer"; + +import download from "../modules/downloader"; +import DesktopFile, { AppImageConfig } from "../scripts/DesktopFile.js"; +const desktopFile = new DesktopFile(); + +import { + log, + handleNoneFatalError, + handleFatalError, + deleteResources, + warn, + error as _error, +} from "../utils"; +// @ts-ignore +import AppRun from "../scripts/AppRun"; +const appRun = new AppRun(); + +const osTempDir = join(_tmpdir(), "appImage"); +const tmpdir = join(cwd(), ".tmp"); +const AppDir = join(tmpdir, "AppDir"); + +let appimageConfig: AppImageConfig; +let appimageTool: fs.PathLike; + +const configObj = { + build_ARCH: "", + sys_ARCH: "", + icon: "", + appName: "", + arch: "", +}; + +const buildAppimage = async ( + archList = ["x64", "arm64"], + config: BuildConfig +) => { + const findAppimage = (t: Partial) => t.target === "appimage"; + + for (const key in archList) { + const findArch = (t: Partial) => + t.arch?.find((a: string) => a === archList[key]); + + appimageConfig = config.cli?.builder?.linux?.targets?.find( + (t: Array>) => + (findAppimage(t) && findArch(t)) || findAppimage(t) + ); + + configObj.build_ARCH = archList[key]; + configObj.icon = config.modes.window.icon; + configObj.appName = config.cli.binaryName; + + if (configObj.build_ARCH === "x64") configObj.arch = "x86_64"; + else if (configObj.build_ARCH === "arm64") configObj.arch = "aarch64"; + + if (_arch() === "x64") configObj.sys_ARCH = "x86_64"; + else if (_arch() === "arm64") configObj.sys_ARCH = "aarch64"; + + const appImage = `${configObj.appName}-${configObj.arch}.AppImage`; + + log(`building ${appImage}...`); + + await buildAppDir(); + await getAppImageTool(); + await configureAppImage(); + + try { + execSync(`mv ${appImage} ${join(cwd(), "dist")}`); + } catch (err: any) { + handleNoneFatalError(err.message); + } + } + + console.log("Built your appimage(s) successfully!! 🚀"); + console.log("check your dist folder"); + console.log(""); +}; + +const buildAppDir = async () => { + await createAppDir(); + configureAppDir(); +}; + +const createAppDir = async () => { + if (!existsSync(tmpdir)) { + try { + mkdirSync(tmpdir); + } catch (error: any) { + handleFatalError(error.message); + } + } + + if (existsSync(AppDir)) { + const answers = await inquirer.prompt([ + { + type: "confirm", + name: "overwrite", + message: `An AppDir folder already exists in your .tmp dir would you like to overwrite it`, + default: true, + }, + ]); + + if (answers.overwrite) { + deleteResources(AppDir); + } else { + console.log("closing..."); + exit(1); + } + } + + try { + mkdirSync(join(AppDir, "usr", "bin"), { recursive: true }); + } catch (err: any) { + handleFatalError(err.message, AppDir); + } +}; + +const configureAppDir = async () => { + const { appName, build_ARCH } = configObj; + + const binary = join( + cwd(), + "dist", + `${appName}`, + `${appName}-linux_${build_ARCH}` + ); + + const resources = join(cwd(), "dist", `${appName}`, "resources.neu"); + + if (!appimageConfig?.icon) + warn("no icon inculded, a default neutralino icon will be used"); + + try { + execSync( + `chmod 755 ${binary} && cp ${binary} ${join(AppDir, "usr", "bin")}` + ); + execSync(`cp ${resources} ${join(AppDir, "usr", "bin")}`); + execSync( + `cp ${join(cwd(), appimageConfig?.icon || configObj.icon)} ${AppDir}` + ); + } catch (err: any) { + handleFatalError(err.message, AppDir); + } + + buildDesktopFile(); + buildAppRun(); +}; + +const buildDesktopFile = () => { + const { appName, build_ARCH, icon } = configObj; + + const exec = `${appName}-linux_${build_ARCH}`; + const appIcon = appimageConfig?.icon || icon; + + desktopFile.set({ + name: appName, + exec: exec, + icon: basename(appIcon, extname(appIcon)), + type: appimageConfig?.type, + categories: appimageConfig?.categories, + }); + + try { + desktopFile.writeScript(join(AppDir), appName); + } catch (err: any) { + handleFatalError(err.message, AppDir); + } +}; + +const buildAppRun = () => { + const { appName, build_ARCH } = configObj; + appRun.set(`/usr/bin/${appName}-linux_${build_ARCH}`); + + try { + appRun.writeScript(AppDir); + } catch (err: any) { + handleFatalError(err.message, AppDir); + } +}; + +const getAppImageTool = async () => { + const { sys_ARCH } = configObj; + const appimageSpec = `appimagetool-${sys_ARCH}.AppImage`; + appimageTool = join(osTempDir, appimageSpec); + fs; + + if (!existsSync(join(cwd(), appimageSpec)) && !existsSync(appimageTool)) { + const appImageToolUrl = `https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-${sys_ARCH}.AppImage`; + + try { + if (!existsSync(osTempDir)) mkdirSync(osTempDir); + await download(appImageToolUrl, osTempDir); + } catch (err: any) { + handleFatalError(err.message, AppDir); + } + } else if (existsSync(join(cwd(), appimageSpec))) { + appimageTool = join(cwd(), appimageSpec); + } + + try { + execSync("chmod 777 " + appimageTool); + } catch (err: any) { + handleFatalError(err.message, AppDir); + } +}; + +const configureAppImage = async () => { + const { arch } = configObj; + + console.log(appimageTool); + + let child; + try { + child = spawn(`${appimageTool}`, [AppDir], { + env: { ARCH: arch }, + }); + } catch (err: any) { + _error(err); + } + + if (!child) { + _error(`Could not spawn ${appimageTool} process`); + process.exit(1); + } + + child.stderr.on("data", (data) => log(`${data}`)); + child.stdout.on("data", (data) => log(`${data}`)); + + child.on("error", (err) => { + handleFatalError(`${err}, this error orignated from the appimagetool`); + }); + + child.on("exit", (code) => { + deleteResources(AppDir); + + if (code !== 0) { + handleFatalError( + `process exited with code ${code}, this error orignated from the appimagetool` + ); + } + }); +}; + +export default buildAppimage; diff --git a/src/targets/test.js b/src/targets/test.js deleted file mode 100644 index 688c83a..0000000 --- a/src/targets/test.js +++ /dev/null @@ -1,9 +0,0 @@ -const array = [1, 2, 3, 4, 5]; - -// checks whether an element is even -const even = (element) => element % 2 === 0; - -const arr = array.filter(even); - -console.log(arr); -// expected output: true diff --git a/src/utils.ts b/src/utils.ts index 3d3fa24..df42449 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,23 +2,23 @@ import { PathLike } from "fs"; import fs from "fs"; import chalk from "chalk"; -const error = (message: string) => { +export const error = (message: string) => { console.error(`neu builder: ${chalk.bgRed.black("ERROR")} ${message}`); }; -const log = (message: string) => { +export const log = (message: string) => { console.log(`neu builder: ${chalk.bgGreen.black("INFO")} ${message}`); }; -const warn = (message: string) => { +export const warn = (message: string) => { console.warn(`neu builder: ${chalk.bgYellow.black("WARNING")} ${message}`); }; -const isNeutralinojsProject = (CONFIG_FILE: PathLike) => { +export const isNeutralinojsProject = (CONFIG_FILE: PathLike) => { return fs.existsSync(CONFIG_FILE); }; -const checkCurrentProject = (CONFIG_FILE: PathLike) => { +export const checkCurrentProject = (CONFIG_FILE: PathLike) => { if (!isNeutralinojsProject(CONFIG_FILE)) { error( `Unable to find ${CONFIG_FILE}. ` + @@ -28,18 +28,18 @@ const checkCurrentProject = (CONFIG_FILE: PathLike) => { } }; -const findExt = (path: PathLike, extension: string) => { +export const findExt = (path: PathLike, extension: string) => { let files = fs.readdirSync(path); return !!files.filter((file: string) => file.match(new RegExp(`.*\.(${extension})`, "ig")) ); }; -const deleteResources = (resource: PathLike) => { +export const deleteResources = (resource: PathLike) => { return fs.rmSync(resource, { recursive: true, force: true }); }; -const handleFatalError = (message: string, resource = undefined) => { +export const handleFatalError = (message: string, resource?: string) => { if (!message) return; error(`${message}`); @@ -48,21 +48,9 @@ const handleFatalError = (message: string, resource = undefined) => { process.exit(1); }; -const handleNoneFatalError = (message: string, resource = undefined) => { +export const handleNoneFatalError = (message: string, resource?: string) => { if (!message) return; error(`${message}`); if (resource) deleteResources(resource); }; - -export default { - error, - log, - warn, - isNeutralinojsProject, - checkCurrentProject, - findExt, - deleteResources, - handleFatalError, - handleNoneFatalError, -}; diff --git a/tsconfig.json b/tsconfig.json index 0909e53..769bb11 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -77,7 +77,7 @@ /* Type Checking */ "strict": true, /* Enable all strict type-checking options. */ - "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */