Skip to content

Commit

Permalink
add naive purge command
Browse files Browse the repository at this point in the history
  • Loading branch information
aruniverse committed Feb 13, 2022
1 parent f4f4f8b commit bb7fc1b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
22 changes: 21 additions & 1 deletion create-cospace/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const help = `
Commands:
init <dir> Initialize a new CoSpace
If <dir> is not provided, will default to current dir.
If <dir> is not provided, will default to current dir
override Override the CoSpace's pnpm config
purge Purge all node_modules from the CoSpace
Flags:
--help, -h Show this help message
Expand Down Expand Up @@ -53,6 +54,11 @@ const init = async (cospaceDir = ".") => {
await fs.copy(path.join(__dirname, "./template"), cospaceDir);

process.chdir(cospaceDir);
try {
execSync("pnpm i");
} catch (e) {
console.error("Failed to install, please run install prior to CoSpace use");
}

console.log(
"Your CoSpace has been initialized! Look at the Readme, setup your CoSpace, install, build and you're good to go!"
Expand Down Expand Up @@ -90,6 +96,18 @@ const overridePnpm = async () => {
);
};

const purge = async () => {
const paths = JSON.parse(
execSync("pnpm ls -r --depth -1 --json", {
encoding: "utf8",
})
).map((pkg) => pkg.path);

await Promise.all(paths.map((path) => fs.remove(`${path}/node_modules`)));

console.log("All node_modules have been purged from the CoSpace.");
};

const run = async () => {
const { input, flags, showHelp, showVersion } = meow(help, {
importMeta: import.meta,
Expand All @@ -108,6 +126,8 @@ const run = async () => {
await init(input[1]);
} else if (input[0] === "override") {
await overridePnpm();
} else if (input[0] === "purge") {
await purge();
} else {
console.log(
`Unrecognized command, ${input[0]}, please try again with --help for more info.`
Expand Down
2 changes: 1 addition & 1 deletion create-cospace/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-cospace",
"version": "0.2.1",
"version": "0.3.0",
"description": "Setup a `CoSpace` to link multiple (mono)repos together!",
"author": "https://github.com/aruniverse",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions create-cospace/template/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "my-cospace",
"version": "0.1.0",
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",
"build": "lage build",
"build:clean": "lage build --no-cache",
"clean": "lage clean && rimraf node_modules",
"clean": "lage clean --no-cache && cospace purge",
"setOverrides": "cospace override"
},
"devDependencies": {
"create-cospace": "latest",
"lage": "latest",
"rimraf": "^3.0.2"
"lage": "latest"
},
"pnpm": {
"overrides": {},
Expand Down

0 comments on commit bb7fc1b

Please sign in to comment.