Skip to content

Commit

Permalink
fix(cli-plugin-scaffold-react-package): improve messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Aug 18, 2020
1 parent 6c23ab6 commit dff0597
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/cli-plugin-scaffold-react-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { replaceInPath } = require("replace-in-path");
const Case = require("case");
const readJson = require("load-json-file");
const writeJson = require("write-json-file");
const { green } = require("chalk");

module.exports = [
{
Expand Down Expand Up @@ -49,7 +50,7 @@ module.exports = [
}
];
},
generate: async ({ input }) => {
generate: async ({ input, oraSpinner, wait }) => {
let { location, packageName } = input;
location = location.split("/");
location[location.length - 1] = Case.kebab(location[location.length - 1]);
Expand All @@ -70,6 +71,9 @@ module.exports = [
throw new Error(`Destination folder ${location} already exists!`);
}

oraSpinner.start(`Creating React package files in ${green(fullLocation)}...`);
await wait();

await fs.mkdirSync(location, { recursive: true });

// Get base TS config & tsconfig.build path
Expand Down Expand Up @@ -132,17 +136,36 @@ module.exports = [
replaceWith: Case.kebab(packageName)
});

oraSpinner.stopAndPersist({
symbol: green("✔"),
text: `React package files created in ${green(fullLocation)}.`
});


// Update root package.json - update "workspaces.packages" section.
oraSpinner.start(`Adding ${green(input.location)} workspace in root ${green(`package.json`)}..`);
await wait();

const rootPackageJsonPath = path.join(projectRootPath, "package.json");
const rootPackageJson = await readJson(rootPackageJsonPath);
if (!rootPackageJson.workspaces.packages.includes(location)) {
rootPackageJson.workspaces.packages.push(location);
await writeJson(rootPackageJsonPath, rootPackageJson);
}

oraSpinner.stopAndPersist({
symbol: green("✔"),
text: `Workspace ${green(input.location)} added in root ${green(`package.json`)}.`
});

// Once everything is done, run `yarn` so the new packages are automatically installed.
try {
oraSpinner.start(`Installing dependencies...`);
await execa("yarn");
oraSpinner.stopAndPersist({
symbol: green("✔"),
text: "Dependencies installed."
});
} catch (err) {
throw new Error(
`Unable to install dependencies. Try running "yarn" in project root manually.`
Expand Down

0 comments on commit dff0597

Please sign in to comment.