Skip to content

Commit 8660328

Browse files
committed
feat(generate): add flags to skip default steps
Using --skip-live or --skip-components you may now opt-out of bookshop/generate building those files for you.
1 parent 66e9dfe commit 8660328

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

javascript-modules/generate/main.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const addComponentTo = (obj, component) => {
3232

3333
async function run() {
3434
program.option("-d, --dot", "Look for Bookshops inside . directories");
35+
program.option("--skip-live", "Don't build live editing JS or add live editing scripts to HTML");
36+
program.option("--skip-components", "Don't build the component browser JS or add component browser scripts to HTML");
3537
program.parse(process.argv);
3638
const options = program.opts();
3739

@@ -94,14 +96,22 @@ async function run() {
9496
fs.writeFileSync(infoJsonFile, JSON.stringify(info_json, null, 2));
9597
console.log(`📚 ———— Added components as CloudCannon Structures`);
9698

97-
const liveEditingNeeded = await hydrateLiveForSite(siteRoot, options);
98-
if (liveEditingNeeded) {
99-
await buildLiveScript(siteRoot, bookshopRoots);
99+
if (!options.skipLive) {
100+
const liveEditingNeeded = await hydrateLiveForSite(siteRoot, options);
101+
if (liveEditingNeeded) {
102+
await buildLiveScript(siteRoot, bookshopRoots);
103+
}
104+
} else {
105+
console.log(`📚 ———— Skipping live editing generation`);
100106
}
101107

102-
const componentBrowserNeeded = await hydrateComponentBrowserForSite(siteRoot, options);
103-
if (componentBrowserNeeded) {
104-
await buildBrowserScript(siteRoot, bookshopRoots);
108+
if (!options.skipComponents) {
109+
const componentBrowserNeeded = await hydrateComponentBrowserForSite(siteRoot, options);
110+
if (componentBrowserNeeded) {
111+
await buildBrowserScript(siteRoot, bookshopRoots);
112+
}
113+
} else {
114+
console.log(`📚 ———— Skipping component browser generation`);
105115
}
106116
}
107117

javascript-modules/integration-tests/features/generate/structure_generation.feature

+7
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ Feature: Bookshop Structure Generation
7878
And site/public/_cloudcannon/bookshop-live.js should leniently contain each row:
7979
| text |
8080
| {{ .card_text }} |
81+
82+
Scenario: Can skip live editing
83+
When I run "npm run generate-no-live" in the . directory
84+
Then stderr should be empty
85+
And stdout should contain "Skipping live editing generation"
86+
And site/public/index.html should not contain the text "_cloudcannon"
87+
And site/public/_cloudcannon/bookshop-live.js should not exist

javascript-modules/integration-tests/support/starters/generate/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"private": true,
44
"scripts": {
55
"start": "bookshop-generate",
6+
"generate-no-live": "bookshop-generate --skip-live",
67
"cc-hugo": "cloudcannon-hugo --baseURL /"
78
},
89
"devDependencies": {
910
"@bookshop/generate": "file:../../../javascript-modules/generate"
1011
}
11-
}
12+
}

0 commit comments

Comments
 (0)