Skip to content

Commit

Permalink
Add a webstone web delete page CLI command (#82)
Browse files Browse the repository at this point in the history
* chore(cli): ensure CLI templates are copied when starting the dev env

* feat(cli): add a `webstone web delete page` CLI command

Add a `webstone web delete page` CLI command.

close #76

* docs(cli): add a changelog entry for the `webstone web delete page` CLI command

* chore(create-webstone-app): sneaking in a small cosmetic change in the terminal output
  • Loading branch information
mikenikles authored Oct 6, 2021
1 parent 58bc87d commit db93524
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-toys-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@webstone/cli": minor
---

Add a `webstone web delete page` CLI command.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"clean": "rm -rf ./dist",
"compile": "tsc -p .",
"copy-templates": "if [ -e ./src/templates ]; then cp -a ./src/templates ./dist/; fi",
"dev": "pnpm dev:watch-src & pnpm dev:watch-templates",
"dev": "pnpm copy-templates && pnpm dev:watch-src & pnpm dev:watch-templates",
"dev:watch-src": "tsc -w",
"dev:watch-templates": "npm-watch copy-templates",
"format": "prettier --write **/*.{js,ts,tsx,json}",
Expand Down
30 changes: 30 additions & 0 deletions packages/cli/src/commands/web/delete/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { GluegunCommand } from "gluegun";

const command: GluegunCommand = {
run: async (toolbox) => {
const { filesystem, parameters, print, prompt, strings } = toolbox;

let name = parameters.first;
if (!name) {
const result = await prompt.ask({
type: "input",
name: "name",
message: `What's the page to delete?`,
});
if (result && result.name) name = result.name;
}

if (!name) {
print.error("Please provide a page, e.g. 'about-us'.");
return;
}

const filename = strings.kebabCase(name);
const target = `services/web/src/routes/${filename}`;
const spinner = print.spin(`Removing page "${target}"...`);
filesystem.remove(target);
spinner.succeed(`Page deleted at: ${target}`);
},
};

module.exports = command;
2 changes: 1 addition & 1 deletion packages/create-webstone-app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Thank you for your interest in Webstone, I'd love to hear your feedback 🙏.
Next steps:
- cd ${appDir.split("/").pop()}
- pnpm dev
- pnpm ws dev
`);
resolve();
});
Expand Down

0 comments on commit db93524

Please sign in to comment.