@wrhs/extract-config
v1.0.0
Published
Extract warehouse.ai configuration from a given unpacked directory
Downloads
5
Keywords
Readme
@wrhs/extract-config
Extracts warehouse.ai configuration from a given unpacked directory
Installation
npm install --save @wrhs/extract-config
Usage
const extract = require('@wrhs/extract-config');
const path = require('path');
const unpackedRepo = path.join('path', 'to', 'repo');
const config = await extract(unpackedRepo);
What is in config
?
At most, the config
will provide the following information:
{
pkg: {
// the entire contents of the repo's package.json
},
wrhs: {
// Whether or not to perform a webpack build for this package, or if
// we can just use the source of this directory as-is.
//
// Optional (default: none)
build: 'webpack',
// Different locales in which to build the package, this is helpful for
// parallelizing builds for any number of locales.
//
// Optional (default: [])
locales: [
'en-US',
'es-CO',
'de-DE',
'zh-CN'
],
// What recommended files to use in each environment
files: {
dev: [
'dist/output.css',
'dist/output.js'
],
test: [
'dist/output.min.css',
'dist/output.min.js'
],
prod: [
'dist/output.min.css',
'dist/output.min.js'
]
},
// Minification options to apply to the output code
minify: {
compress: {
unsafe: true,
dead_code: true,
collapse_vars: true,
drop_console: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true
}
}
}
}
Allowed files
@wrhs/extract-config
will recognize the following configuration files and
formats.
.wrhsrc
This is a simple json
file that contains information in the above format
{
"build": "webpack",
"locales": [
"C",
"C++",
"ArnoldC"
]
}
package.json
Similar to .wrhsrc
you can place these values into either the base level of
your package.json
, or into a wrhs
object (we will merge the base level into
the wrhs
object if any)
{
"name": "my-cool-package",
"version": "1.2.3",
"wrhs": {
"build": "webpack",
"locales": [
"en-US",
"es-CO",
"de-DE"
],
"files": {
"test": ["dist/output.js", "dist/output.css"],
"prod": ["dist/output.min.js", "dist/output.min.css"]
}
}
}
wrhs.toml
[files]
dev = ['output.js', 'output.css']
test = ['output.min.js', 'output.min.css']
prod = ['output.min.js', 'output.min.css']
build = 'webpack'
locales = [
'English',
'Sindarin',
'Klingon',
'Dothraki'
]
[minify]
[minify.compress]
unsafe = true
dead_code = true
unsafe = true
dead_code = true
collapse_vars = true
drop_console = true
conditionals = true
booleans = true
unused = true
if_return = true
join_vars = true
Order of configuration precedence
They are listed in order above, but we will resolve potentially conflicting information based on this precedence:
.wrhsrc
package.json
wrhs.toml
Any configuration from earlier in the list will override identically named configuration later in the list. For example, I have these 2 files present:
.wrhsrc
{
"build" :"webpack",
"locales": [
"Earth", "Mars"
]
}
wrhs.toml
locales=['Krypton', 'Oa']
[files]
test = ['output.css']
prod = ['output.min.css']
The final configuration object will be:
{
build: 'webpack',
locales: [
'Earth', 'Mars'
],
files: {
test: ['output.css']
prod: ['output.min.css']
}
}
It's important to note that nested lists and objects will not be merged, just overridden.
We highly recommended keeping all of your configuration in one single location, but to support legacy formats, we allow multiple points of entry.
Testing
npm test