@discoveryjs/cli
Advanced tools
Comparing version 2.11.2 to 2.12.0
@@ -11,3 +11,3 @@ const archiver = require('archiver'); | ||
const archive = archiver('zip'); | ||
const files = await build({ | ||
const { files, suppressedFailures } = await build({ | ||
...options, | ||
@@ -41,5 +41,6 @@ data: true, | ||
filename: `${basename}.zip`, | ||
stream: archive | ||
stream: archive, | ||
suppressedFailures | ||
}; | ||
}); | ||
}); |
const fs = require('fs'); | ||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
const { pipeline } = require('stream'); | ||
@@ -33,2 +34,3 @@ const bootstrap = require('./shared/bootstrap'); | ||
} | ||
return utils.process(`Write ${relpath(dest)}`, () => { | ||
@@ -170,2 +172,3 @@ fs.writeFileSync(ensureDir(dest), content); | ||
const cacheDispatcher = createCacheDispatcher(config.models, { configFile, ...options }); | ||
const suppressedFailures = []; | ||
const outputDir = options.output; | ||
@@ -175,2 +178,5 @@ const outputFiles = new Map(); | ||
const models = config.models || []; | ||
const skippedModels = []; | ||
const modelAssets = new Map(models.map(modelConfig => [modelConfig.slug, []])); | ||
const addModelAsset = (slug, path, content) => modelAssets.get(slug).push([path, content]); | ||
const esbuildConfig = { | ||
@@ -200,3 +206,3 @@ minify: typeof options.minify === 'boolean' ? options.minify : true, | ||
...config, | ||
models: models | ||
models | ||
}; | ||
@@ -212,7 +218,9 @@ } | ||
entryPoints.set(modelConfig.slug, entryPointPath); | ||
outputFiles.set( | ||
addModelAsset( | ||
modelConfig.slug, | ||
entryPointPath, | ||
gen['/model.html'](modelConfig, options, config) | ||
); | ||
outputFiles.set( | ||
addModelAsset( | ||
modelConfig.slug, | ||
path.join(modelConfig.slug, `favicon${path.extname(favicon)}`), | ||
@@ -238,8 +246,5 @@ fs.readFileSync(favicon) | ||
await utils.process('Build bundles', () => makeBundle(config, options, esbuildConfig, { cacheDispatcher }) | ||
.then(result => { | ||
for (const file of result.outputFiles) { | ||
outputFiles.set(path.relative(outputDir, file.path), Buffer.from(file.contents)); | ||
} | ||
})); | ||
let buildResult = await utils.process('Build bundles', () => | ||
makeBundle(config, options, esbuildConfig, { cacheDispatcher }) | ||
); | ||
@@ -250,3 +255,4 @@ if (options.data) { | ||
if (modelConfig.data) { | ||
await utils.process(modelConfig.slug, async () => outputFiles.set( | ||
await utils.process(modelConfig.slug, async () => addModelAsset( | ||
modelConfig.slug, | ||
path.join(modelConfig.slug, 'data.json'), | ||
@@ -258,3 +264,11 @@ await cacheDispatcher.read(modelConfig.slug) | ||
) | ||
)); | ||
)).catch(...options.excludeModelOnDataFail | ||
? [(error) => { | ||
console.error(chalk.bgRed.white('ERROR') + '\n' + chalk.red(error)); | ||
console.warn(chalk.yellow(`Model "${modelConfig.slug}" failed to build its data. The build will continue, but the model will be excluded from the result because --exclude-model-on-data-fail is enabled.`)); | ||
suppressedFailures.push(`Model "${modelConfig.slug}" failed to build its data`); | ||
skippedModels.push(modelConfig); | ||
}] | ||
: [] | ||
); | ||
} else { | ||
@@ -267,2 +281,30 @@ utils.println(`${modelConfig.slug} <no data>`); | ||
// take action when some models fail to build | ||
if (skippedModels.length > 0) { | ||
for (const modelConfig of skippedModels) { | ||
entryPoints.delete(modelConfig.slug); | ||
modelAssets.delete(modelConfig.slug); | ||
} | ||
buildResult = await utils.process('Rebuild bundles without failed models', () => | ||
makeBundle({ | ||
...config, | ||
models: models.filter(model => !skippedModels.includes(model)) | ||
}, options, esbuildConfig, { cacheDispatcher }) | ||
); | ||
console.log(' Excluded models:', skippedModels.map(model => chalk.red(model.slug)).join(', ')); | ||
} | ||
// fullfil outputFiles | ||
for (const file of buildResult.outputFiles) { | ||
outputFiles.set(path.relative(outputDir, file.path), Buffer.from(file.contents)); | ||
} | ||
for (const assets of modelAssets.values()) { | ||
for (const asset of assets) { | ||
outputFiles.set(...asset); | ||
} | ||
} | ||
// bake html files | ||
if (options.singleFile) { | ||
@@ -320,3 +362,6 @@ await utils.section('Convert to single file', async () => { | ||
return outputFiles; | ||
return { | ||
files: outputFiles, | ||
suppressedFailures: suppressedFailures.length ? suppressedFailures : false | ||
}; | ||
} | ||
@@ -327,4 +372,4 @@ | ||
const outputDir = options.output; | ||
const outputFiles = await build(options, config, configFile); | ||
const outputFilenames = [...outputFiles.keys()].sort(); | ||
const { files, suppressedFailures } = await build(options, config, configFile); | ||
const outputFilenames = [...files.keys()].sort(); | ||
@@ -334,3 +379,3 @@ await utils.section(`Write files to dest (${outputDir})`, async () => { | ||
return utils.silent(() => Promise.all(outputFilenames.map(async filepath => | ||
writeFile(path.resolve(outputDir, filepath), await outputFiles.get(filepath), true) | ||
writeFile(path.resolve(outputDir, filepath), await files.get(filepath), true) | ||
))); | ||
@@ -340,3 +385,3 @@ } | ||
for (const filepath of outputFilenames) { | ||
await writeFile(path.resolve(outputDir, filepath), outputFiles.get(filepath)); | ||
await writeFile(path.resolve(outputDir, filepath), files.get(filepath)); | ||
} | ||
@@ -346,4 +391,6 @@ }); | ||
console.log(`\nDONE 🎉 (in ${utils.prettyDuration(Date.now() - startTime)})`); | ||
return { files, suppressedFailures }; | ||
}); | ||
module.exports.build = build; |
@@ -117,3 +117,3 @@ const path = require('path'); | ||
utils.println(`Download: ${modelConfig.download ? chalk.yellow(modelConfig.download) + (!options.modelDownload ? ' (ignored due to options)' : '') : DISABLED}`); | ||
utils.println(`Darkmode: ${modelConfig.darkmode !== undefined ? chalk.yellow(JSON.stringify(modelConfig.darkmode)) : chalk.gray('<not set>')}`); | ||
utils.println(`Color scheme: ${modelConfig.colorScheme !== undefined ? chalk.yellow(JSON.stringify(modelConfig.colorScheme)) : chalk.gray('<not set>')}`); | ||
@@ -171,3 +171,3 @@ if (modelCache.cache && modelConfig.data) { | ||
utils.println('Embed API:', options.embed === 'enable' ? ENABLED : options.embed === 'disable' ? DISABLED : chalk.yellow(options.embed)); | ||
utils.println('Darkmode:', chalk.yellow(JSON.stringify(config.darkmode))); | ||
utils.println('Color scheme:', chalk.yellow(JSON.stringify(config.colorScheme))); | ||
utils.println('Mode:', chalk.yellow(config.mode)); | ||
@@ -174,0 +174,0 @@ }); |
@@ -26,2 +26,8 @@ const fs = require('fs'); | ||
function warnOnDeprecatedOption(options, optionName, replaceName) { | ||
if (options && optionName in options) { | ||
console.warn(`Option "${optionName}" is deprecated${replaceName ? `, use "${replaceName}" instead` : ''}`); | ||
} | ||
} | ||
function stripKeys(obj, stripKeys) { | ||
@@ -155,2 +161,3 @@ const result = {}; | ||
favicon, | ||
colorScheme, | ||
view, | ||
@@ -235,2 +242,8 @@ cache, | ||
// color scheme | ||
warnOnDeprecatedOption(modelConfig, 'darkmode', 'colorScheme'); | ||
if (modelConfig && modelConfig.colorScheme === undefined && modelConfig.darkmode) { | ||
colorScheme = modelConfig.darkmode; | ||
} | ||
return { | ||
@@ -241,3 +254,3 @@ name: 'Untitled model', | ||
cache: undefined, | ||
...stripKeys(modelConfig || {}, ['slug', 'basedir']), | ||
...stripKeys(modelConfig || {}, ['slug', 'basedir', 'darkmode']), | ||
data, | ||
@@ -249,2 +262,3 @@ encodings, | ||
favicon, | ||
colorScheme, | ||
view, | ||
@@ -296,4 +310,9 @@ routers, | ||
mode: model ? 'single' : 'multi', | ||
...stripKeys(config, ['mode']) | ||
...stripKeys(config, ['mode', 'darkmode']) | ||
}; | ||
warnOnDeprecatedOption(config, 'darkmode', 'colorScheme'); | ||
if ('colorScheme' in config === false && 'darkmode' in config) { | ||
result.colorScheme = config.darkmode; | ||
} | ||
} | ||
@@ -308,3 +327,3 @@ | ||
result.darkmode = result.darkmode !== undefined ? result.darkmode : 'auto'; | ||
result.colorScheme = result.colorScheme !== undefined ? result.colorScheme : 'auto'; | ||
result.download = result.download !== undefined ? Boolean(result.download) : true; | ||
@@ -356,5 +375,5 @@ result.upload = result.upload !== undefined ? result.upload : false; | ||
modelConfig.darkmode = modelConfig.darkmode !== undefined | ||
? modelConfig.darkmode | ||
: result.darkmode; | ||
modelConfig.colorScheme = modelConfig.colorScheme !== undefined | ||
? modelConfig.colorScheme | ||
: result.colorScheme; | ||
@@ -361,0 +380,0 @@ modelConfig.download = getDownloadUrl( |
@@ -86,3 +86,3 @@ const path = require('path'); | ||
download, | ||
darkmode, | ||
colorScheme, | ||
view | ||
@@ -115,4 +115,4 @@ } = modelConfig; | ||
embed: embedOption(options, modelConfig), | ||
darkmode, | ||
darkmodePersistent: true, | ||
colorScheme, | ||
colorSchemePersistent: true, | ||
inspector, | ||
@@ -134,4 +134,4 @@ router, | ||
router: Boolean(config.view?.router), | ||
darkmode: config.darkmode, | ||
darkmodePersistent: true | ||
colorScheme: config.colorScheme, | ||
colorSchemePersistent: true | ||
}; | ||
@@ -138,0 +138,0 @@ |
@@ -6,2 +6,12 @@ /* eslint-env browser */ | ||
export const colorSchemeOptions = ({ | ||
darkmode, | ||
darkmodePersistent, | ||
colorScheme = darkmode, | ||
colorSchemePersistent = darkmodePersistent | ||
}) => | ||
preloader.colorScheme | ||
? { colorScheme, colorSchemePersistent } | ||
: { darkmode: colorScheme, darkmodePersistent: colorSchemePersistent }; | ||
export const loadStyle = SINGLE_FILE | ||
@@ -8,0 +18,0 @@ ? url => document.querySelector(`style[type="discovery/style"][src=${JSON.stringify(url)}]`).firstChild.nodeValue |
/* eslint-env browser */ | ||
import setup from 'discovery-cli:setup'; | ||
import encodings from 'discovery-cli:encodings'; | ||
import { load, loadStyle } from './common.js'; | ||
import { colorSchemeOptions, load, loadStyle } from './common.js'; | ||
@@ -13,6 +13,5 @@ load( | ||
embed: setup.embed, | ||
darkmode: setup.darkmode, | ||
darkmodePersistent: setup.darkmodePersistent, | ||
...colorSchemeOptions(setup), | ||
encodings | ||
} | ||
); |
@@ -5,2 +5,3 @@ /* eslint-env browser */ | ||
import { Widget as ViewModel, navButtons, router, embed } from '@discoveryjs/discovery'; | ||
import { colorSchemeOptions } from './common.js'; | ||
@@ -23,4 +24,3 @@ export default function(setup, progressbar, embedState) { | ||
inspector: setup.inspector, | ||
darkmode: setup.darkmode, | ||
darkmodePersistent: setup.darkmodePersistent, | ||
...colorSchemeOptions(setup), | ||
encodings, | ||
@@ -32,3 +32,3 @@ context, | ||
setup.inspector && navButtons.inspect, | ||
navButtons.darkmodeToggle, | ||
navButtons.colorSchemeToggle || navButtons.darkmodeToggle, | ||
setup.router && router, | ||
@@ -35,0 +35,0 @@ setup.embed && embed.setup(embedState), |
@@ -5,3 +5,3 @@ /* eslint-env browser */ | ||
import encodings from 'discovery-cli:encodings'; | ||
import { load, loadStyle } from './common.js'; | ||
import { colorSchemeOptions, load, loadStyle } from './common.js'; | ||
@@ -15,4 +15,3 @@ load( | ||
embed: setup.model.embed, | ||
darkmode: setup.model.darkmode, | ||
darkmodePersistent: setup.model.darkmodePersistent, | ||
...colorSchemeOptions(setup.model), | ||
encodings, | ||
@@ -19,0 +18,0 @@ ...SINGLE_FILE |
@@ -8,2 +8,3 @@ /* eslint-env browser */ | ||
import { App, embed } from '@discoveryjs/discovery'; | ||
import { colorSchemeOptions } from './common.js'; | ||
@@ -20,4 +21,3 @@ export default function(setup, progressbar, embedState, dataset) { | ||
styles: setup.styles, | ||
darkmode: model.darkmode, | ||
darkmodePersistent: model.darkmodePersistent, | ||
...colorSchemeOptions(model), | ||
upload: model.upload, | ||
@@ -24,0 +24,0 @@ inspector: model.inspector, |
{ | ||
"name": "@discoveryjs/cli", | ||
"version": "2.11.2", | ||
"version": "2.12.0", | ||
"description": "CLI tools to serve & build projects based on Discovery.js", | ||
@@ -5,0 +5,0 @@ "author": "Roman Dvornov <rdvornov@gmail.com> (https://github.com/lahmatiy)", |
@@ -97,36 +97,37 @@ <img align="right" width="128" height="128" | ||
--no-cache Disable data caching | ||
--cachedir [dir] Path to store cache files (using .discoveryjs-cache by default when [dir] | ||
is not set) | ||
--check-cache-ttl Check data cache TTL before using it, option enforces to use actual | ||
(according to TTL) data only | ||
--clean Clean the output directory before emit a build files | ||
-c, --config <filename> Path to config (JavaScript or JSON file), if not specified then looking | ||
for .discoveryrc.js, .discoveryrc.json, .discoveryrc or "discovery" | ||
section in package.json in the listed order | ||
--no-data Don't include data into a model build | ||
--no-data-compression Disable HTML embedded data compression, when --single-file option is used | ||
--no-dev Disable using Discovery.js "src" assets when available (disables | ||
discovery-dev condition) | ||
--embed [mode] Specify an embed API: by-config (default), enable (when [mode] omitted) | ||
or disable | ||
--entry-names [pattern] Specify the file names of the output HTML files corresponding to each | ||
model | ||
--experimental-jsonxl Enable experimental binary data encoding (codename JSONXL) | ||
-h, --help Output usage information | ||
--no-minify Disable JS and CSS minification | ||
-m, --model <name> Specify a model (multi-model mode only) | ||
--no-model-data-upload Ignore model data upload feature setup in config | ||
--model-download Enable model download feature | ||
--model-reset-cache Enable model cache reset feature | ||
-o, --output <path> Path for a build result (`build` by default) | ||
--pretty-data [indent] Pretty print of model data if any | ||
--serve-only-assets Include server only assets into build | ||
-s, --single-file Output a model build as a single HTML file per model | ||
--sourcemap [mode] Enable source map generation, optional "mode" can be: linked (default, | ||
when [mode] is omitted), external or inline (see | ||
https://esbuild.github.io/api/#sourcemap for detail) | ||
--tmpdir <dir> Path to directory of temporary cache files which are generating before | ||
committing to cache directory | ||
-v, --version Output version | ||
--no-cache Disable data caching | ||
--cachedir [dir] Path to store cache files (using .discoveryjs-cache by default when [dir] | ||
is not set) | ||
--check-cache-ttl Check data cache TTL before using it, option enforces to use actual | ||
(according to TTL) data only | ||
--clean Clean the output directory before emit a build files | ||
-c, --config <filename> Path to config (JavaScript or JSON file), if not specified then looking | ||
for .discoveryrc.js, .discoveryrc.json, .discoveryrc or "discovery" | ||
section in package.json in the listed order | ||
--no-data Don't include data into a model build | ||
--no-data-compression Disable HTML embedded data compression, when --single-file option is used | ||
--no-dev Disable using Discovery.js "src" assets when available (disables | ||
discovery-dev condition) | ||
--embed [mode] Specify an embed API: by-config (default), enable (when [mode] omitted) | ||
or disable | ||
--entry-names [pattern] Specify the file names of the output HTML files corresponding to each model | ||
--exclude-model-on-data-fail Exclude models from the result if their data generation fails, ignoring | ||
the failure instead of halting the build (exit code: 1) | ||
--experimental-jsonxl Enable experimental binary data encoding (codename JSONXL) | ||
-h, --help Output usage information | ||
--no-minify Disable JS and CSS minification | ||
-m, --model <name> Specify a model (multi-model mode only) | ||
--no-model-data-upload Ignore model data upload feature setup in config | ||
--model-download Enable model download feature | ||
--model-reset-cache Enable model cache reset feature | ||
-o, --output <path> Path for a build result (`build` by default) | ||
--pretty-data [indent] Pretty print of model data if any | ||
--serve-only-assets Include server only assets into build | ||
-s, --single-file Output a model build as a single HTML file per model | ||
--sourcemap [mode] Enable source map generation, optional "mode" can be: linked (default, | ||
when [mode] is omitted), external or inline | ||
(see https://esbuild.github.io/api/#sourcemap for detail) | ||
--tmpdir <dir> Path to directory of temporary cache files which are generating before | ||
committing to cache directory | ||
-v, --version Output version | ||
``` | ||
@@ -133,0 +134,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
258799
4768
285