From b34ec8c53dea145df0494d84d090f8aa1bef621e Mon Sep 17 00:00:00 2001 From: Fsalker Date: Tue, 21 Jul 2020 02:58:39 +0300 Subject: [PATCH] feat(scaffolding): enforce location within projectRoot & run yarn --- packages/cli-plugin-scaffold-node-package/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/cli-plugin-scaffold-node-package/index.js b/packages/cli-plugin-scaffold-node-package/index.js index 2b1df61130f..a6b3dc69d44 100644 --- a/packages/cli-plugin-scaffold-node-package/index.js +++ b/packages/cli-plugin-scaffold-node-package/index.js @@ -11,7 +11,7 @@ module.exports = [ type: "cli-plugin-scaffold-template", scaffold: { name: "Node Package", - questions: () => { + questions: ({ context }) => { return [ { name: "location", @@ -21,6 +21,13 @@ module.exports = [ return "Please enter a package location"; } + const fullLocation = path.resolve(location); + const projectLocation = context.paths.projectRoot; + if (path.relative(fullLocation, projectLocation).match(/[^.\\]/)) { + return "The target location must be within the Webiny project's root"; + } + return "fuck"; + if (fs.existsSync(path.resolve(location))) { return "The target location already exists"; } @@ -99,6 +106,9 @@ module.exports = [ const tsconfigBuild = require(tsconfigBuildPath); tsconfigBuild.extends = baseTsConfigBuildPath; fs.writeFileSync(tsconfigBuildPath, JSON.stringify(tsconfigBuild, null, 2)); + + // Run Yarn to link the new package to the monorepo + await execa("yarn"); } } }