From 4be1efa46e94b620e0de2c2a0ae471765b51fbb1 Mon Sep 17 00:00:00 2001 From: Mark Hughes Date: Tue, 15 Mar 2022 10:29:40 +1100 Subject: [PATCH] fix(#56): build cache for published packages --- package.json | 3 ++- packages/cli/bin/droppy | 8 ++++++++ packages/cli/lib/cli.js | 16 ++++++++-------- packages/cli/package.json | 3 ++- packages/server/lib/services/resources.js | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 3b2be4c9..bbfba663 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,14 @@ "node": ">= 12.10.0" }, "scripts": { + "build": "DROPPY_CACHE_PATH=$PWD/packages/cli/dist/cache.json lerna run --stream build --", "start": "lerna run --stream start --", "bootstrap": "lerna bootstrap", "lint": "eslint packages", "test": "jest", "postinstall": "husky install && yarn bootstrap", "pub:canary": "lerna publish --c", - "pub": "lerna publish && git push" + "pub": "yarn build && lerna publish && git push" }, "resolutions": { "hosted-git-info": "^4.0.2", diff --git a/packages/cli/bin/droppy b/packages/cli/bin/droppy index b465f9fa..eb915d44 100644 --- a/packages/cli/bin/droppy +++ b/packages/cli/bin/droppy @@ -1,3 +1,11 @@ #!/usr/bin/env node +const {realpathSync, existsSync} = require("fs"); +const path = require("path"); + +const cachePath = realpathSync(path.join(__dirname, "..", "dist", "cache.json")); +if (existsSync(cachePath)) { + process.env.DROPPY_CACHE_PATH = cachePath; +} + require("../lib/cli"); diff --git a/packages/cli/lib/cli.js b/packages/cli/lib/cli.js index 5a3e6a26..f4b8c75e 100644 --- a/packages/cli/lib/cli.js +++ b/packages/cli/lib/cli.js @@ -54,14 +54,6 @@ if (argv.daemon || argv.d) { require("daemonize-process")(); } -if (argv._[0] === "build") { - console.info("Building resources ..."); - resources.build(err => { - console.info(err || "Resources built successfully"); - process.exit(err ? 1 : 0); - }); -} - if (argv.configdir || argv.filesdir || argv.c || argv.f) { paths.seed(argv.configdir || argv.c, argv.filesdir || argv.f); } @@ -131,6 +123,14 @@ switch (cmd) { break; } + case "build": + console.info("Building resources ..."); + resources.build(err => { + console.info(err || "Resources built successfully"); + process.exit(err ? 1 : 0); + }); + break; + case "version": console.info(pkg.version); break; diff --git a/packages/cli/package.json b/packages/cli/package.json index 4b306378..11d2fe38 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -42,7 +42,8 @@ "url": "git+https://github.com/droppyjs/droppy.git" }, "scripts": { - "start": "node ./lib/cli.js start" + "start": "node ./lib/cli.js start", + "build": "node ./lib/cli.js build" }, "bugs": { "url": "https://github.com/droppyjs/droppy/issues" diff --git a/packages/server/lib/services/resources.js b/packages/server/lib/services/resources.js index 0fb9f3f2..27fe7504 100644 --- a/packages/server/lib/services/resources.js +++ b/packages/server/lib/services/resources.js @@ -16,7 +16,7 @@ const utils = require("./utils.js"); const themesPath = path.join(paths.client, "/node_modules/codemirror/theme"); const modesPath = path.join(paths.client, "/node_modules/codemirror/mode"); -const cachePath = path.join(paths.homedir, "/.droppy/cache/cache.json"); +const cachePath = process.env.DROPPY_CACHE_PATH ?? path.join(paths.homedir, "/.droppy/cache/cache.json"); const pkg = require("../../package.json");