Browse Source

Added basic command line option

master
Muthu Kumar 7 years ago
parent
commit
61c076b5d9
  1. 2
      README.md
  2. 21
      cli.js
  3. 27
      lib/api.js
  4. 67
      package-lock.json
  5. 7
      package.json
  6. 4
      utils/extract.js

2
README.md

@ -1,6 +1,6 @@
# w # w
w is a cli application to spin up WordBox instances. w is a cli application to spin up WordBox instances. Unstable, but in active development.
[WordBox](https://github.com/codefeathers/WordBox) is a quick development (and deployment) environment for PHP. [WordBox](https://github.com/codefeathers/WordBox) is a quick development (and deployment) environment for PHP.

21
cli.js

@ -1,10 +1,19 @@
#!/usr/bin/env node #!/usr/bin/env node
var program = require('commander'); const program = require('commander');
program const wordbox = require('./lib/api');
.version('0.1.0')
.option('-h, --help', 'Show w-cli help')
.parse(process.argv);
if (program.help) console.log('w -v for version number'); program.version('1.0.2');
program.command('new <appname> [options...]')
.description('Create new WordBox app')
.action((appname, options) => {
wordbox.newapp(appname, options)
});
program.command('-h, --help')
.description('Show w-cli help')
.action(() => console.log('Show w-cli help'));
program.parse(process.argv);

27
lib/api.js

@ -0,0 +1,27 @@
'use strict';
const fs = require('fs');
const normalize = require('path').normalize;
const axios = require('axios');
const extract = require('../utils/extract');
const newapp = async (appname, options) => {
console.log(`Spinning up a new WordBox app at ${appname}...`);
//const stream = fs.createWriteStream;
// const stream = normalize(process.cwd() + '/temp.zip');
// console.log(stream)
// const responseStream = await axios({
// method: 'get',
// url: 'https://github.com/codefeathers/up-serve/archive/master.zip',
// responseType: 'stream'
// })
// await responseStream.data.pipe(fs.createWriteStream(stream))
// const extractResponse = await extract(stream, normalize(process.cwd() + '/' + appname))
// console.log(extractResponse)
// fs.unlink(stream, (err, res) => console.log(err, res))
};
module.exports.newapp = newapp;

67
package-lock.json

@ -0,0 +1,67 @@
{
"name": "w",
"version": "1.0.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"axios": {
"version": "0.17.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.17.1.tgz",
"integrity": "sha1-LY4+XQvb1zJ/kbyBT1xXZg+Bgk0=",
"requires": {
"follow-redirects": "1.4.1",
"is-buffer": "1.1.6"
}
},
"commander": {
"version": "2.13.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz",
"integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA=="
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"follow-redirects": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.4.1.tgz",
"integrity": "sha512-uxYePVPogtya1ktGnAAXOacnbIuRMB4dkvqeNz2qTtTQsuzSfbDolV+wMMKxAmCx0bLgAKLbBOkjItMbbkR1vg==",
"requires": {
"debug": "3.1.0"
}
},
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"node-7z": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/node-7z/-/node-7z-0.4.0.tgz",
"integrity": "sha1-OQEkxYAYPKvTiNE38wsjm0S9Wag=",
"requires": {
"when": "3.7.8",
"win-spawn": "2.0.0"
}
},
"when": {
"version": "3.7.8",
"resolved": "https://registry.npmjs.org/when/-/when-3.7.8.tgz",
"integrity": "sha1-xxMLan6gRpPoQs3J56Hyqjmjn4I="
},
"win-spawn": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/win-spawn/-/win-spawn-2.0.0.tgz",
"integrity": "sha1-OXopEw7JjQqgvIa6pGITk+/9Cwc="
}
}
}

7
package.json

@ -23,5 +23,10 @@
"bugs": { "bugs": {
"url": "https://github.com/codefeathers/w/issues" "url": "https://github.com/codefeathers/w/issues"
}, },
"homepage": "https://github.com/codefeathers/w#readme" "homepage": "https://github.com/codefeathers/w#readme",
"dependencies": {
"axios": "^0.17.1",
"commander": "^2.13.0",
"node-7z": "^0.4.0"
}
} }

4
lib/extract.js → utils/extract.js

@ -2,10 +2,10 @@ var sevenZip = require('node-7z')
var Zip = new sevenZip() var Zip = new sevenZip()
const extract = (filename, destination) => { const extract = (filename, destination) => {
Zip.extractFull(filenames, destination) Zip.extractFull(filename, destination)
.progress((files) => console.log('Some files are extracted: %s', files)) .progress((files) => console.log('Some files are extracted: %s', files))
.then(() => console.log('Extracting done!')) .then(() => console.log('Extracting done!'))
.catch(function (err) => console.error(err)) .catch((err) => console.error(err))
} }
module.exports = extract module.exports = extract
Loading…
Cancel
Save