-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbuild.js
59 lines (51 loc) · 2.59 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const argv = yargs(hideBin(process.argv)).argv
const {generateGithubData} = require('./build/github');
const {generateMarkdownData} = require('./build/markdown');
const {testDemoUrls} = require('./build/demo');
const {writeThemesFile, writeErrorFile, writeStackbitFile} = require('./build/write')
const {generateStackbitData} = require('./build/stackbit')
const {generateScreenshots, generateThumbnails} = require('./build/screenshot')
const config = require('./build/config');
const {errorLog} = require('./build/errors');
const build = async (options) => {
const themesMarkdown = await generateMarkdownData(config.themesMarkdownFiles, options)
if (options.github) {
// Updates themes.json
const themesGithub = await generateGithubData(themesMarkdown)
writeThemesFile(themesGithub)
}
if (options.stackbit) {
// Updates stackbit.json
const stackbit = generateStackbitData(themesMarkdown)
writeStackbitFile(stackbit);
}
if (options.demos) {
// Visits each demo URL with a headless browser and if the site cannot be reached sets the markdown file to disabled=true
await testDemoUrls(themesMarkdown)
}
if (options.images) {
await generateScreenshots(themesMarkdown, options.recaptureImage)
await generateThumbnails(themesMarkdown, options.regenerateImage)
}
writeErrorFile(errorLog)
console.log("Build Successful")
console.log("Error Log")
process.exit(0)
}
const options = {
github: argv.github !== "false", // generates `data/themes.json` which is used for github stars, commits meta data etc
stackbit: argv.stackbit !== "false", // generates `data/stackbit.json` which is used for the "create site" button
demos: argv.demos !== "false", // tests the themes demo url using headless browser and disables the theme if the url does not resolve
images: argv.images !== "false", // captures screenshots and generates thumbnails
disabled: argv.disabled !== "false", // Skip processing themes that have front-matter `disabled: true`
draft: argv.draft !== "false", // Skip processing themes that have front-matter `draft: true`
latest: argv.latest || false, // Only process themes which don't already exist in `data/themes.json`
file: argv.file || false, // Only process a single file ie --file=gatsby-starter-advanced.md
all: argv.all || false, // process all themes
recaptureImage: argv.recaptureImage || false,
regenerateImage: argv.regenerateImage || false
}
build(options);