fabric-cli
Advanced tools
Comparing version 0.0.5 to 0.1.0
127
index.js
@@ -5,37 +5,118 @@ #!/usr/bin/env node | ||
const program = require('commander'); | ||
const inquirer = require('inquirer'); | ||
const appRoot = require('app-root-path'); | ||
const fs = require('fs'); | ||
const figlet = require('figlet'); | ||
const chalk = require('chalk'); | ||
const exec = require('child_process').exec; | ||
const chalk = require('chalk'); | ||
const pkg = require('./package.json'); | ||
const cmd = 'grunt'; | ||
const prompt = inquirer.createPromptModule(); | ||
const buildConfig = require(appRoot + '/config.json'); | ||
function trailingSlash(path) { | ||
return path.endsWith('/') ? path : path + '/'; | ||
} | ||
function log(data) { | ||
data.stdout.on('data', function (data) { | ||
process.stdout.write(data); | ||
data.stdout.on('data', data => process.stdout.write(data)); | ||
data.stderr.on('data', data => process.stdout.write(data)); | ||
data.on('close', function (code) { | ||
if (code) console.log('[END] code', code); | ||
if (stdout) console.log('[END] stdout "%s"', stdout); | ||
if (stderr) console.log('[END] stderr "%s"', stderr); | ||
}); | ||
} | ||
data.stderr.on('data', function (data) { | ||
process.stdout.write(data); | ||
}); | ||
function defaultTask(path) { | ||
return 'rm src/build; ln -s ' + path + ' src/build; grunt'; | ||
} | ||
function run(task) { | ||
function argument(task, name, path, basePath) { | ||
const config = readConfig(); | ||
let project; | ||
let command; | ||
let buildInfo; | ||
task === 'start' ? command = cmd : command = cmd + ' ' + task; | ||
let fabric = exec(command + ' --colors'); | ||
log(fabric); | ||
if (task === 'Connect build') { | ||
command = 'rm src/build; ln -s ' + config.basePath + path + ' src/build; grunt'; | ||
buildInfo = require(config.basePath + trailingSlash(path) + 'package.json'); | ||
buildConfig.projects.push({ name: buildInfo.name, path: config.basePath + path }); | ||
fs.writeFile(appRoot + '/config.json', JSON.stringify(buildConfig, null, 2), err => { | ||
if (err) return console.log(err); | ||
console.log('Build stored!'); | ||
}); | ||
} | ||
if (task === 'Start build') { | ||
project = config.projects.find(obj => obj.name === name); | ||
command = defaultTask(project.path); | ||
} | ||
if (task === 'Connect base') { | ||
buildConfig.basePath = trailingSlash(basePath); | ||
fs.writeFile(appRoot + '/config.json', JSON.stringify(buildConfig, null, 2), err => { | ||
if (err) return console.log(err); | ||
console.log('Base path stored!'); | ||
}); | ||
} | ||
return command; | ||
} | ||
program | ||
.version(pkg.version) | ||
.arguments('[task]') | ||
.version(pkg.version) | ||
.description('CLI for Fabric') | ||
.action(function (task) { | ||
run(task); | ||
}); | ||
function readConfig() { | ||
return JSON.parse(fs.readFileSync(appRoot + '/config.json', 'utf8')); | ||
} | ||
program.parse(process.argv); | ||
function getBuilds() { | ||
const builds = readConfig(); | ||
let projects = new Array(); | ||
if (program.args.length === 0) program.help(); | ||
projects = Array.from(new Set(builds.projects.map(JSON.stringify))).map(JSON.parse); | ||
return projects; | ||
} | ||
function run(task, name, path, rootPath) { | ||
const command = argument(task, name, path, rootPath); | ||
const fabric = command ? exec(command) : null; | ||
fabric !== null ? log(fabric) : null; | ||
} | ||
const questions = [ | ||
{ | ||
type: 'list', | ||
name: 'command', | ||
message: 'What would you like to do?', | ||
choices: ['Start build', 'Connect build', 'Connect base'], | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'build', | ||
message: 'Which build would you like to start?', | ||
choices: getBuilds(), | ||
when: answers => answers.command === 'Start build', | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'path', | ||
message: 'Enter the build path', | ||
when: answers => answers.command === 'Connect build', | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'basePath', | ||
message: 'Enter your base path', | ||
when: answers => answers.command === 'Connect base' | ||
}, | ||
]; | ||
console.log(chalk.yellow(figlet.textSync('Fabric', { horizontalLayout: 'full' }))); | ||
prompt(questions).then(answers => { | ||
const { command, build, path, basePath } = answers; | ||
run(command, build, path, basePath); | ||
}); |
{ | ||
"name": "fabric-cli", | ||
"version": "0.0.5", | ||
"description": "A command line tool for fabric", | ||
"version": "0.1.0", | ||
"description": "A command line tool for our internal fabric tooling", | ||
"main": "index.js", | ||
@@ -15,10 +15,14 @@ "author": "Jamie Robertson", | ||
"dependencies": { | ||
"app-root-path": "^2.0.1", | ||
"chalk": "^1.1.3", | ||
"commander": "^2.9.0" | ||
"commander": "^2.9.0", | ||
"figlet": "^1.2.0", | ||
"inquirer": "^6.0.0" | ||
}, | ||
"keywords": [ | ||
"fabric", | ||
"fabric cli" | ||
"fabric cli", | ||
"cello signal fabric" | ||
], | ||
"license": "MIT" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25681
6
679
5
3
2
+ Addedapp-root-path@^2.0.1
+ Addedfiglet@^1.2.0
+ Addedinquirer@^6.0.0
+ Addedansi-escapes@3.2.0(transitive)
+ Addedansi-regex@3.0.14.1.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedapp-root-path@2.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedchardet@0.7.0(transitive)
+ Addedcli-cursor@2.1.0(transitive)
+ Addedcli-width@2.2.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedexternal-editor@3.1.0(transitive)
+ Addedfiglet@1.8.0(transitive)
+ Addedfigures@2.0.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinquirer@6.5.2(transitive)
+ Addedis-fullwidth-code-point@2.0.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmimic-fn@1.2.0(transitive)
+ Addedmute-stream@0.0.7(transitive)
+ Addedonetime@2.0.1(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedrestore-cursor@2.0.0(transitive)
+ Addedrun-async@2.4.1(transitive)
+ Addedrxjs@6.6.7(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstring-width@2.1.1(transitive)
+ Addedstrip-ansi@4.0.05.2.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedtmp@0.0.33(transitive)
+ Addedtslib@1.14.1(transitive)