Initial commit.
This commit is contained in:
commit
551196ceb7
4
.babelrc
Normal file
4
.babelrc
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"presets": ["latest"],
|
||||
"plugins": ["transform-object-rest-spread"]
|
||||
}
|
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@ -0,0 +1,9 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
lib
|
3
bin/themer.js
Executable file
3
bin/themer.js
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('../lib/index.js');
|
27
package.json
Normal file
27
package.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "themer",
|
||||
"version": "1.0.0",
|
||||
"description": "Development theme generator.",
|
||||
"main": "lib/index.js",
|
||||
"author": "mjswensen",
|
||||
"repository": {
|
||||
"url": "git@github.com:mjswensen/themer.git",
|
||||
"type": "git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bin": "./bin/themer.js",
|
||||
"scripts": {
|
||||
"build": "babel --out-dir lib src",
|
||||
"start": "watch 'yarn run build' src"
|
||||
},
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.0",
|
||||
"pn": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.18.0",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.19.0",
|
||||
"babel-preset-latest": "^6.16.0",
|
||||
"watch": "^1.0.1"
|
||||
}
|
||||
}
|
59
src/index.js
Normal file
59
src/index.js
Normal file
@ -0,0 +1,59 @@
|
||||
import path from 'path';
|
||||
import fs from 'pn/fs';
|
||||
import minimist from 'minimist';
|
||||
|
||||
const args = (parsedArgs => {
|
||||
try {
|
||||
if (parsedArgs.colors === undefined) {
|
||||
throw new Error('Please provide a package name or file containing colors');
|
||||
}
|
||||
if (parsedArgs.template === undefined) {
|
||||
throw new Error('Please provide at least one template to render');
|
||||
}
|
||||
if (parsedArgs.out === undefined) {
|
||||
throw new Error('Please provide a directory to write output to');
|
||||
}
|
||||
}
|
||||
catch(e) {
|
||||
console.error(e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
return {
|
||||
...parsedArgs,
|
||||
template: typeof parsedArgs.template === 'string' ? [parsedArgs.template] : parsedArgs.template,
|
||||
out: path.resolve(parsedArgs.out),
|
||||
};
|
||||
})(minimist(process.argv.slice(2), {
|
||||
string: ['colors', 'template', 'out'],
|
||||
alias: {
|
||||
'colors': 'c',
|
||||
'template': 't',
|
||||
'out': 'o',
|
||||
},
|
||||
}));
|
||||
|
||||
const resolvePackage = name => new Promise((resolve, reject) => {
|
||||
try {
|
||||
resolve(require.resolve(name));
|
||||
}
|
||||
catch(e) {
|
||||
try {
|
||||
resolve(require.resolve(path.resolve(name)));
|
||||
}
|
||||
catch(e) {
|
||||
reject(`Unable to resolve ${name}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const flatten = arr => [].concat.apply([], arr);
|
||||
|
||||
Promise.all([args.colors, ...args.template].map(resolvePackage))
|
||||
.then(requireables => {
|
||||
const colors = require(requireables[0]).colors;
|
||||
const templates = requireables.slice(1).map(require);
|
||||
return Promise.all(flatten(templates.map(template => template.render(colors, args))));
|
||||
})
|
||||
.then(files => Promise.all(files.map(file => fs.writeFile(path.resolve(args.out, file.name), file.contents).then(() => console.log(`...${file.name}`)))))
|
||||
.then(() => console.log('Done!'))
|
||||
.catch(e => console.error(e));
|
Loading…
Reference in New Issue
Block a user