From d2827aa40b692960adc82842951283ca1dd07de6 Mon Sep 17 00:00:00 2001 From: Lipis Date: Fri, 28 Feb 2020 22:51:36 +0100 Subject: [PATCH] Add version to build and the archived asar app (#854) --- package-lock.json | 49 ++++++++++++++++++++++++++++++++++++++++ package.json | 8 ++++--- scripts/build-version.js | 37 ++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100755 scripts/build-version.js diff --git a/package-lock.json b/package-lock.json index ece83231..1eb57962 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2408,6 +2408,22 @@ "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", "integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=" }, + "asar": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/asar/-/asar-2.1.0.tgz", + "integrity": "sha512-d2Ovma+bfqNpvBzY/KU8oPY67ZworixTpkjSx0PCXnQi67c2cXmssaTxpFDUM0ttopXoGx/KRxNg/GDThYbXQA==", + "dev": true, + "requires": { + "@types/glob": "^7.1.1", + "chromium-pickle-js": "^0.2.0", + "commander": "^2.20.0", + "cuint": "^0.2.2", + "glob": "^7.1.3", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.1", + "tmp-promise": "^1.0.5" + } + }, "asn1": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", @@ -3383,6 +3399,12 @@ "tslib": "^1.9.0" } }, + "chromium-pickle-js": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/chromium-pickle-js/-/chromium-pickle-js-0.2.0.tgz", + "integrity": "sha1-BKEGZywYsIWrd02YPfo+oTjyIgU=", + "dev": true + }, "ci-info": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", @@ -4183,6 +4205,12 @@ "integrity": "sha512-xz39Sb4+OaTsULgUERcCk+TJj8ylkL4aSVDQiX/ksxbELSqwkgt4d4RD7fovIdgJGSuNYqwZEiVjYY5l0ask+Q==", "dev": true }, + "cuint": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/cuint/-/cuint-0.2.2.tgz", + "integrity": "sha1-QICG1AlVDCYxFVYZ6fp7ytw7mRs=", + "dev": true + }, "currently-unhandled": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", @@ -14810,6 +14838,27 @@ "os-tmpdir": "~1.0.2" } }, + "tmp-promise": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-1.1.0.tgz", + "integrity": "sha512-8+Ah9aB1IRXCnIOxXZ0uFozV1nMU5xiu7hhFVUSxZ3bYu+psD4TzagCzVbexUCgNNGJnsmNDQlS4nG3mTyoNkw==", + "dev": true, + "requires": { + "bluebird": "^3.5.0", + "tmp": "0.1.0" + }, + "dependencies": { + "tmp": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz", + "integrity": "sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==", + "dev": true, + "requires": { + "rimraf": "^2.6.3" + } + } + } + }, "tmpl": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", diff --git a/package.json b/package.json index b85e7b4f..58fa6a1b 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,8 @@ "roughjs": "4.0.4", "stacktrace-js": "2.0.2" }, - "description": "", "devDependencies": { + "asar": "2.1.0", "@testing-library/jest-dom": "5.1.1", "@testing-library/react": "9.4.1", "@types/jest": "25.1.3", @@ -80,8 +80,10 @@ "main": "src/index.js", "name": "excalidraw", "scripts": { - "build": "react-scripts build", - "build-node": "./scripts/build-node.js", + "build:app": "react-scripts build", + "build:zip": "node ./scripts/build-version.js", + "build": "npm run build:app && npm run build:zip", + "build-node": "node ./scripts/build-node.js", "eject": "react-scripts eject", "fix": "npm run fix:other && npm run fix:code", "fix:code": "npm run test:code -- --fix", diff --git a/scripts/build-version.js b/scripts/build-version.js new file mode 100755 index 00000000..ce3404d7 --- /dev/null +++ b/scripts/build-version.js @@ -0,0 +1,37 @@ +#!/usr/bin/env node + +const fs = require("fs"); +const path = require("path"); +const asar = require("asar"); + +const zero = digit => `0${digit}`.slice(-2); + +const versionDate = date => { + const date_ = `${date.getFullYear()}-${zero(date.getMonth() + 1)}-${zero( + date.getDate(), + )}`; + const time = `${zero(date.getHours())}-${zero(date.getMinutes())}-${zero( + date.getSeconds(), + )}`; + return `${date_}-${time}`; +}; + +const now = new Date(); + +const data = JSON.stringify( + { + app: `excalidraw-${versionDate(now)}.asar`, + version: versionDate(now), + }, + undefined, + 2, +); + +fs.writeFileSync(path.join("build", "version.json"), data); + +(async () => { + const src = "build/"; + const dest = path.join("build", `excalidraw-${versionDate(now)}.asar`); + + await asar.createPackage(src, dest); +})();