Skip to content

Instantly share code, notes, and snippets.

@justinobney
Last active December 31, 2015 00:39
Show Gist options
  • Save justinobney/55a80d81a591a0c5ed81 to your computer and use it in GitHub Desktop.
Save justinobney/55a80d81a591a0c5ed81 to your computer and use it in GitHub Desktop.
// npm i mkdirp node-fetch minimist
var path = require('path');
var fs = require('fs');
var fetch = require('node-fetch');
var mkdirp = require('mkdirp');
var argDefaults = {
dir:'test',
template: 'module'
}
var gistMap = {
module: '6834249eb249c32a86af',
react: '26593cff2b0c8e991198'
}
var argv = require('minimist')(process.argv.slice(2), {default: argDefaults});
var gistId = gistMap[argv.template];
console.log(argv);
fetch(`https://api.github.com/gists/${gistId}`)
.then(res => res.json())
.then(data => {
mkdirp(argv.dir, () => {
Object.keys(data.files)
.map(fileName => {
var pathInfo = path.resolve(argv.dir, fileName);
var fileInfo = data.files[fileName];
fs.writeFile(pathInfo, fileInfo.content, 'utf8', err => {
console.log(fileName, fileInfo.content.length)
});
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment