From f62b70c9a96c15b41dda49919cc96f4ba905320a Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sat, 17 Jul 2021 02:30:16 +0800 Subject: [PATCH] add nightly to version number --- dockerfile | 4 +++- extra/mark-as-nightly.js | 39 +++++++++++++++++++++++++++++++++++++++ package.json | 7 ++++--- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 extra/mark-as-nightly.js diff --git a/dockerfile b/dockerfile index d21c22bee..0388d4bcb 100644 --- a/dockerfile +++ b/dockerfile @@ -1,5 +1,5 @@ # DON'T UPDATE TO alpine3.13, 1.14, see #41. -FROM node:14-alpine3.12 +FROM node:14-alpine3.12 AS release WORKDIR /app # split the sqlite install here, so that it can caches the arm prebuilt @@ -33,3 +33,5 @@ EXPOSE 3001 VOLUME ["/app/data"] CMD ["npm", "run", "start-server"] +FROM release AS nightly +RUN npm run mark-as-nightly diff --git a/extra/mark-as-nightly.js b/extra/mark-as-nightly.js new file mode 100644 index 000000000..c35455e87 --- /dev/null +++ b/extra/mark-as-nightly.js @@ -0,0 +1,39 @@ +/** + * String.prototype.replaceAll() polyfill + * https://gomakethings.com/how-to-replace-a-section-of-a-string-with-another-one-with-vanilla-js/ + * @author Chris Ferdinandi + * @license MIT + */ +if (!String.prototype.replaceAll) { + String.prototype.replaceAll = function(str, newStr){ + + // If a regex pattern + if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') { + return this.replace(str, newStr); + } + + // If a string + return this.replace(new RegExp(str, 'g'), newStr); + + }; +} + +const pkg = require('../package.json'); +const fs = require("fs"); +const oldVersion = pkg.version +const newVersion = oldVersion + "-nightly" + +console.log("Old Version: " + oldVersion) +console.log("New Version: " + newVersion) + +if (newVersion) { + // Process package.json + pkg.version = newVersion + pkg.scripts.setup = pkg.scripts.setup.replaceAll(oldVersion, newVersion) + pkg.scripts["build-docker"] = pkg.scripts["build-docker"].replaceAll(oldVersion, newVersion) + fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n") + + // Process README.md + fs.writeFileSync("README.md", fs.readFileSync("README.md", 'utf8').replaceAll(oldVersion, newVersion)) +} + diff --git a/package.json b/package.json index af0840183..44d94c3fe 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,11 @@ "update": "", "build": "vite build", "vite-preview-dist": "vite preview --host", - "build-docker": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma -t louislam/uptime-kuma:1 -t louislam/uptime-kuma:1.0.4 . --push", - "build-docker-nightly": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly . --push", + "build-docker": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma -t louislam/uptime-kuma:1 -t louislam/uptime-kuma:1.0.4 --target release . --push", + "build-docker-nightly": "docker buildx build --platform linux/amd64 -t louislam/uptime-kuma:nightly --target nightly . --push", "setup": "git checkout 1.0.4 && npm install && npm run build", - "version-global-replace": "node extra/version-global-replace.js" + "version-global-replace": "node extra/version-global-replace.js", + "mark-as-nightly": "node extra/mark-as-nightly.js" }, "dependencies": { "@popperjs/core": "^2.9.2",