From d14d297d2594d4102b54d94ffb7a0349a8898169 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Thu, 7 Nov 2019 21:46:47 +0000 Subject: [PATCH] cli - new handler respects latestPackagesFolder --- packages/cli/src/commands/new/newHandler.js | 14 +++++++++----- packages/cli/src/common.js | 2 +- packages/server/package.json | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/commands/new/newHandler.js b/packages/cli/src/commands/new/newHandler.js index 3434000cb5..19b4dfb2a7 100644 --- a/packages/cli/src/commands/new/newHandler.js +++ b/packages/cli/src/commands/new/newHandler.js @@ -2,17 +2,18 @@ const { getAppContext } = require("../../common"); const { getMasterApisWithFullAccess } = require("@budibase/server/utilities/budibaseApi"); -const { copy, readJSON, writeJSON, remove } = require("fs-extra"); +const { copy, readJSON, writeJSON, remove, exists } = require("fs-extra"); const { resolve, join } = require("path"); const thisPackageJson = require("../../../package.json"); const {exec} = require('child_process'); -module.exports = ({name}) => { - run({name}); +module.exports = (opts) => { + run(opts); } const run = async (opts) => { const context = await getAppContext({configName:opts.config, masterIsCreated:true}); + opts.config = context.config; const bb = await getMasterApisWithFullAccess(context); const app = bb.recordApi.getNew("/applications", "application"); @@ -28,11 +29,14 @@ const createEmtpyAppPackage = async (opts) => { const templateFolder = resolve( __dirname, "appPackageTemplate"); - const destinationFolder = resolve(".", opts.name); + const appsFolder = opts.config.latestPackagesFolder || "."; + const destinationFolder = resolve(appsFolder, opts.name); + + if(await exists(destinationFolder)) return; await copy(templateFolder, destinationFolder); - const packageJsonPath = join(opts.name, "package.json"); + const packageJsonPath = join(appsFolder, opts.name, "package.json"); const packageJson = await readJSON(packageJsonPath); packageJson.name = opts.name; diff --git a/packages/cli/src/common.js b/packages/cli/src/common.js index 1bd4e852c9..6b3b24bc09 100644 --- a/packages/cli/src/common.js +++ b/packages/cli/src/common.js @@ -20,6 +20,6 @@ module.exports.getAppContext = async ({configName, masterIsCreated}) => { configName = "config.js"; } - const config = require(join(cwd(), configName))(); + const config = require(resolve(cwd(), configName))(); return await buildAppContext(config, masterIsCreated); } \ No newline at end of file diff --git a/packages/server/package.json b/packages/server/package.json index 3986ab3fb5..4ea1f3c060 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "jest", "build": "cd appPackages/_master && yarn && cd ../testApp && yarn && cd ../testApp2 && yarn", - "initialise": "node initialise/initialiseBudibase --datastore local --username admin --password admin --rootPath .data --cleanDev", + "initialise": "node initialise/initialiseBudibase --datastore local --username admin --password admin --rootPath .data --cleanDev && node ../cli/bin/budi new testApp2", "dev:builder": "node index" }, "keywords": [