Skip to content

Instantly share code, notes, and snippets.

@blenderous
Created November 29, 2016 14:07
Show Gist options
  • Save blenderous/559f641f70bd910bffa7316f8b4868a1 to your computer and use it in GitHub Desktop.
Save blenderous/559f641f70bd910bffa7316f8b4868a1 to your computer and use it in GitHub Desktop.
A CLI that takes you step by step asking what kind bower packages need to be included for your page
'use strict'
var fs = require('fs-extra');
/*
* function
* takes bower dependencies in the form of array
* and creates a bower.json
*/
module.exports = function (pageName, dependencies) {
fs.ensureFile('./bower.json', function (err) {
if (err != null) {
fs.writeJson('./bower.json', {dependencies: {'angular' : '1.2.29'}}, function (err) {
console.log(err);
})
}
else if (err == null) {
fs.writeJson('./bower.json', {name: pageName}, function (err) {
console.log(err);
});
}
});
}
'use strict'
var makeBower = require('./make-bower');
var fs = require('fs-extra');
var yargs = require('yargs').argv;
var inquirer = require('inquirer');
if (yargs._[0] == 'init') {
inquirer.prompt(
[
{
type: 'input',
name: 'name',
message: 'What is the name of your page?',
validate: function(input) {
if (input.length > 0) {return true;}
else {
return "Please enter a name to proceed";
}
}
},
{
type: 'checkbox',
name: 'additionalBower',
message: 'Select additional bower packages:',
choices: [' "angular-animate" : "~1.2.28"', ' "angular-touch" : "~1.2.28"'],
when: function(answers) {
// Great !
console.log(" ___ ____ ____ __ ____ _ ");
console.log(" / __)( _ \\( __) / _\\(_ _) / \\ ");
console.log(" ( (_ \\ ) / ) _) / \\ )( \\_/ ");
console.log(" \\___/(__\\_)(____)\\_/\\_/(__) (_) ");
console.log(" ");
return true;
}
},
{
type: 'confirm',
name: 'thirdPartyBower',
message: 'Add third party bower packages?',
when: function(answers) {
// cool !
console.log(" ___ __ __ __ _ ");
console.log(" / __)/ \\ / \\ ( ) / \\ ");
console.log(" ( (__( O )( O )/ (_/\\ \\_/ ");
console.log(" \\___)\\__/ \\__/ \\____/ (_) ");
console.log(" ");
return true;
}
},
{
type: 'input',
name: 'thirdPartyBowerList',
message: 'Add name and version of third party bower (eg: moment#2.15.2, jquery^3.1.1, angular-cookies~1.2.28 etc.)',
when: function(answers) {
if (answers['thirdPartyBower']) {
return true;
}
}
}
]
).then(function (answers) {
// Sounds good !
console.log(" ____ __ _ _ __ _ ____ ____ ___ __ __ ____ _ ");
console.log(" / ___) / \\ / )( \\( ( \\( \\/ ___) / __) / \\ / \\( \\ / \\ ");
console.log(" \\___ \\( O )) \\/ (/ / ) D (\\___ \\ ( (_ \\( O )( O )) D ( \\_/ ");
console.log(" (____/ \\__/ \\____/\\_)__)(____/(____/ \\___/ \\__/ \\__/(____/ (_) ");
console.log(" ");
var thirdPartyBowerList = answers['thirdPartyBowerList'];
var re = /([a-z\-]+)(\~|\^|\#)\d+.\d+.\d+/gi;
// get dependencies to be installed by bower
var dependencies = thirdPartyBowerList.match(re);
if (dependencies.length == 0) {
throw error;
}
// make bower file if it doesn't exist
// or inject dependencies to existing bower
makeBower(dependencies);
});
}
else if (yargs._[0] == 'check') {
inquirer.prompt({
type: 'input',
name: 'thirdPartyBowerList',
message: 'Add name and version of third party bower (eg: moment#2.15.2, jquery^3.1.1, angular-cookies~1.2.28 etc.)'
})
.then(function (answers) {
var thirdPartyBowerList = answers['thirdPartyBowerList'];
var regEx = /([a-z\-]+)(\~|\^|\#)\d+.\d+.\d+/gi;
// get dependencies to be installed by bower
var dependencies = thirdPartyBowerList.match(regEx);
if (dependencies.length == 0) {
throw error;
}
dependencies.forEach(function(dependency) {
var regEx = /(\~|\^|\#)\d+.\d+.\d+/gi
dependency.split(regEx);
console.log(dependency);
})
makeBower('pagify', dependencies);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment