From d76a515cbfbf8002debc1237282b7c630f3b0ff4 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Thu, 3 Aug 2023 20:51:11 +0800 Subject: [PATCH 1/3] WIP --- extra/cli.js | 18 ++++++++++++++++++ package-lock.json | 3 +++ package.json | 3 +++ 3 files changed, 24 insertions(+) create mode 100644 extra/cli.js diff --git a/extra/cli.js b/extra/cli.js new file mode 100644 index 0000000000..7f12283736 --- /dev/null +++ b/extra/cli.js @@ -0,0 +1,18 @@ +#!/usr/bin/env node + +if (!process.env.DATA_DIR) { + if (process.platform === "win32") { + process.env.DATA_DIR = process.env.LOCALAPPDATA + "\\uptime-kuma\\"; + } else if (process.platform === "linux") { + process.env.DATA_DIR = process.env.HOME + "/.local/share/uptime-kuma/"; + } else if (process.platform === "darwin") { + // TODO: Not sure if this is the correct path for macOS + process.env.DATA_DIR = process.env.HOME + "/Library/Preferences/uptime-kuma/"; + } else { + console.error("Unable to detect app data directory on platform: " + process.platform); + console.error("Please set the DATA_DIR environment variable or `--data-dir=` to the directory where you want to store your data."); + process.exit(1); + } +} + +require("../server/server"); diff --git a/package-lock.json b/package-lock.json index da1524c790..a4d2050a2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -75,6 +75,9 @@ "thirty-two": "~1.0.2", "ws": "^8.13.0" }, + "bin": { + "uptime-kuma": "extra/cli.js" + }, "devDependencies": { "@actions/github": "~5.0.1", "@babel/eslint-parser": "^7.22.7", diff --git a/package.json b/package.json index 9f57e99b72..d575153c93 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,9 @@ "engines": { "node": "14 || 16 || 18 || >= 20.4.0" }, + "bin": { + "uptime-kuma": "./extra/cli.js" + }, "scripts": { "install-legacy": "npm install", "update-legacy": "npm update", From 642136780fcaefed1a66bedc2309de831cabac16 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 6 Aug 2023 22:23:40 +0800 Subject: [PATCH 2/3] WIP --- extra/cli.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++- package-lock.json | 15 ++++++++++++ package.json | 1 + 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/extra/cli.js b/extra/cli.js index 7f12283736..bdfa6ec993 100644 --- a/extra/cli.js +++ b/extra/cli.js @@ -1,5 +1,8 @@ #!/usr/bin/env node +const path = require("path"); +const args = require("args-parser")(process.argv); +// Set the data directory if (!process.env.DATA_DIR) { if (process.platform === "win32") { process.env.DATA_DIR = process.env.LOCALAPPDATA + "\\uptime-kuma\\"; @@ -15,4 +18,58 @@ if (!process.env.DATA_DIR) { } } -require("../server/server"); +// Change the working directory to the root of the project, so it can read the dist folder +process.chdir(path.join(__dirname, "..")); + +if (args.run) { + require("../server/server"); + +} else if (args.installService) { + + if (process.platform === "win32") { + let Service = require("node-windows").Service; + + // Create a new service object + let svc = new Service({ + name: "Uptime Kuma", + description: "Uptime Kuma is an easy-to-use self-hosted monitoring tool.", + script: "C:\\path\\to\\helloworld.js", + nodeOptions: [ + "--harmony", + "--max_old_space_size=4096" + ] + //, workingDirectory: '...' + //, allowServiceLogon: true + }); + + // Listen for the "install" event, which indicates the + // process is available as a service. + svc.on("install", function () { + svc.start(); + }); + + svc.install(); + } else if (process.platform === "linux") { + + } else { + console.error("Unable to install service on platform: " + process.platform); + process.exit(1); + } + +} else if (args.version || args.v) { + const version = require("../package.json").version; + console.log("Uptime Kuma version: " + version); + +} else { + console.log(`Usage: uptime-kuma [options] + +Options: + --install-service Install Uptime Kuma service (Windows and Linux only) + --uninstall-service Uninstall Uptime Kuma service + --run Run Uptime Kuma directly in the terminal + --data-dir="your path" Set the data directory + --version Print the version + --help Print this help + `); +} + diff --git a/package-lock.json b/package-lock.json index ca8e871921..ddee43b575 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,6 +53,7 @@ "nanoid": "~3.3.4", "node-cloudflared-tunnel": "~1.0.9", "node-radius-client": "~1.0.0", + "node-windows": "^1.0.0-beta.8", "nodemailer": "~6.6.5", "nostr-tools": "^1.13.1", "notp": "~2.0.3", @@ -14645,6 +14646,15 @@ "node": ">= 10" } }, + "node_modules/node-windows": { + "version": "1.0.0-beta.8", + "resolved": "https://registry.npmjs.org/node-windows/-/node-windows-1.0.0-beta.8.tgz", + "integrity": "sha512-uLekXnSeem3nW5escID224Fd0U/1VtvE796JpSpOY+c73Cslz/Qn2WUHRJyPQJEMrNGAy/FMRFjjhh4z1alZTA==", + "dependencies": { + "xml": "1.0.1", + "yargs": "^17.5.1" + } + }, "node_modules/nodemailer": { "version": "6.6.5", "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.5.tgz", @@ -19019,6 +19029,11 @@ } } }, + "node_modules/xml": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", + "integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==" + }, "node_modules/xmlbuilder": { "version": "8.2.2", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-8.2.2.tgz", diff --git a/package.json b/package.json index e5aff73ba6..f95bf1c62c 100644 --- a/package.json +++ b/package.json @@ -118,6 +118,7 @@ "nanoid": "~3.3.4", "node-cloudflared-tunnel": "~1.0.9", "node-radius-client": "~1.0.0", + "node-windows": "^1.0.0-beta.8", "nodemailer": "~6.6.5", "nostr-tools": "^1.13.1", "notp": "~2.0.3", From e4aedeb7af87f1efe32e6965ab7cae2bb11fbbb5 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Fri, 11 Aug 2023 21:26:25 +0800 Subject: [PATCH 3/3] WIP --- .dockerignore | 24 +++++++++--------------- .npmignore | 45 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 11 ++++++++--- 3 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 .npmignore diff --git a/.dockerignore b/.dockerignore index 0bc56885c5..dac3428ec1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,5 @@ +# Should be very similar to .npmignore, but the syntax is a bit different + /.idea /node_modules /data* @@ -12,9 +14,8 @@ **/.gitignore **/docker-compose* **/[Dd]ockerfile* -LICENSE -README.md .editorconfig +.vs .vscode .eslint* .stylelint* @@ -32,22 +33,15 @@ tsconfig.json /tmp /babel.config.js /ecosystem.config.js -/extra/healthcheck.exe -/extra/healthcheck extra/exe-builder +/public - -### .gitignore content (commented rules are duplicated) - -#node_modules .DS_Store -#dist dist-ssr *.local -#.idea - -#/data -#!/data/.gitkeep -#.vscode -### End of .gitignore content +# .dockerignore only, not in .npmignore +/extra/healthcheck.exe +/extra/healthcheck +LICENSE +README.md diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000000..6e578a1967 --- /dev/null +++ b/.npmignore @@ -0,0 +1,45 @@ +# Should be very similar to .dockerignore, but the syntax is a bit different + +/.idea +/node_modules +/data +/cypress +/out +/test +/kubernetes +/.do +/.dockerignore +/private +/.git +/.gitignore +/docker-compose* +/[Dd]ockerfile* +.editorconfig +.vs +.vscode +.eslint* +.stylelint* +/.devcontainer +/.github +yarn.lock +app.json +CODE_OF_CONDUCT.md +CONTRIBUTING.md +CNAME +install.sh +SECURITY.md +tsconfig.json +.env +/tmp +/babel.config.js +/ecosystem.config.js +extra/exe-builder +/public + +.DS_Store +dist-ssr +*.local + +## .npmignore only, not in .dockerignore +/docker +/extra/healthcheck* diff --git a/package.json b/package.json index f95bf1c62c..f728d049fb 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "uptime-kuma", + "description": "Uptime Kuma is an easy-to-use self-hosted monitoring tool", "version": "1.23.0-beta.1", "license": "MIT", "repository": { @@ -13,6 +14,7 @@ "uptime-kuma": "./extra/cli.js" }, "scripts": { + "uptime-kuma": "node ./extra/cli.js", "install-legacy": "npm install", "update-legacy": "npm update", "lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .", @@ -58,8 +60,8 @@ "simple-dns-server": "node extra/simple-dns-server.js", "simple-mqtt-server": "node extra/simple-mqtt-server.js", "update-language-files": "cd extra/update-language-files && node index.js && cross-env-shell eslint ../../src/languages/$npm_config_language.js --fix", - "release-final": "node ./extra/test-docker.js && node extra/update-version.js && npm run build-docker && node ./extra/press-any-key.js && npm run upload-artifacts && node ./extra/update-wiki-version.js", - "release-beta": "node ./extra/test-docker.js && node extra/beta/update-version.js && npm run build && node ./extra/env2arg.js docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:$VERSION -t louislam/uptime-kuma:beta . --target release --push && node ./extra/press-any-key.js && npm run upload-artifacts", + "release-final": "node ./extra/test-docker.js && node extra/update-version.js && npm run build-docker && node ./extra/press-any-key.js && npm run upload-artifacts && node ./extra/update-wiki-version.js && npm run publish-to-npm", + "release-beta": "node ./extra/test-docker.js && node extra/beta/update-version.js && npm run build && node ./extra/env2arg.js docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:$VERSION -t louislam/uptime-kuma:beta . --target release --push && node ./extra/press-any-key.js && npm run upload-artifacts && npm run publish-to-npm-beta", "git-remove-tag": "git tag -d", "build-dist-and-restart": "npm run build && npm run start-server-dev", "start-pr-test": "node extra/checkout-pr.js && npm install && npm run dev", @@ -71,7 +73,10 @@ "deploy-demo-server": "node extra/deploy-demo-server.js", "sort-contributors": "node extra/sort-contributors.js", "quick-run-nightly": "docker run --rm --env NODE_ENV=development -p 3001:3001 louislam/uptime-kuma:nightly2", - "start-dev-container": "cd docker && docker-compose -f docker-compose-dev.yml up --force-recreate" + "start-dev-container": "cd docker && docker-compose -f docker-compose-dev.yml up --force-recreate", + "publish-to-npm-dev": "npm run build && npm publish --tag dev", + "publish-to-npm-beta": "npm publish --tag beta", + "publish-to-npm": "npm publish" }, "dependencies": { "@grpc/grpc-js": "~1.7.3",