From fcb1a908cac8c3009d04dadf708e58cd9025df6f Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Wed, 31 Jan 2018 19:51:53 +0530 Subject: [PATCH] Bump to v 1.1.0 MVP --- LICENSE | 2 +- README.md | 24 +++++++++++++++++++++++- lib/api.js | 33 ++++++++++++++++++++------------- package.json | 8 ++++---- utils/extract.js | 19 ++++++++++--------- utils/npminstall.js | 9 +++++++++ 6 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 utils/npminstall.js diff --git a/LICENSE b/LICENSE index da26da0..a090146 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 CodeFeathers +Copyright (c) 2017 Muthu Kumar / Anu Rahul Nandhan @ CodeFeathers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index b541105..d4da586 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,31 @@ # w -w is a cli application to spin up WordBox instances. Unstable, but in active development. +w-cli is a cli application to spin up WordBox instances. [WordBox](https://github.com/codefeathers/WordBox) is a quick development (and deployment) environment for PHP. +## Install + +> Before you install! `p7zip` must be in your PATH. `7z --help` to verify. On Debian or Ubuntu, use `sudo apt-get install p7zip`. Currently `w-cli` only works in Linux. + +Install `w` from npm! + +`npm install w --global` + +## Usage + +`w new ` + +Creates a new project at current folder with name `appname`. Downloads WordBox and extracts it to the folder and does `npm install` to resolve dependencies. You should download or compile `php` and `php-cgi` binaries and place them at `appname/php`. Place your public `.php` files at `appname/public`. Check `config.js` to see if all's perfect, then do `node .` to start a new Express server that runs PHP. + +You should probably use `nginx` to reverse-proxy the server in production. Check out my other project `up-serve` [[npm]](https://npmjs.com/package/up-serve) [[Github]](https://github.com/codefeathers/up-serve) to setup nginx servers with a single command. + +## Version + +Current version is `v 1.1.0`. This is an MVP. + +> Note: Because npm versions are immutable, our public version number starts directly from v.1.0.1. The project should be considered unstable until v.2.0.0 which will be `w-cli`'s first stable release version. + ### Credits I humbly thank [@wbhob](https://github.com/wbhob) for donating the package name `w` on npm. diff --git a/lib/api.js b/lib/api.js index 5ba481d..768df93 100644 --- a/lib/api.js +++ b/lib/api.js @@ -6,22 +6,29 @@ const normalize = require('path').normalize; const axios = require('axios'); const extract = require('../utils/extract'); +const npminstall = require('../utils/npminstall'); -const newapp = async (appname, options) => { +const newapp = (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)) + const tmp = normalize(process.cwd() + '/wordbox.zip'); + console.log(`Downloading wordbox.zip`); + axios({ + method: 'get', + url: 'https://github.com/codefeathers/WordBox/archive/master.zip', + responseType: 'stream' + }) + .then(responseStream => new Promise((resolve, reject) => { + responseStream.data.once('error', reject); + let fileStream = fs.createWriteStream(tmp); + fileStream.once('error', reject); + fileStream.once('finish', resolve); + return responseStream.data.pipe(fileStream); + })) + .then(() => extract(tmp, normalize(process.cwd() + '/' + appname))) + .then(() => fs.unlink(tmp, (err) => { if(err) throw new Error(err) })) + .then(() => npminstall(appname)) + .catch((err) => { if(err) throw new Error(err) }); }; module.exports.newapp = newapp; \ No newline at end of file diff --git a/package.json b/package.json index 87747be..f601395 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "w", - "version": "1.0.2", + "version": "1.1.0", "description": "WordBox cli to quickly spin up PHP dev environments.", - "main": "app.js", + "main": "lib/api.js", + "bin": "cli.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, @@ -26,7 +27,6 @@ "homepage": "https://github.com/codefeathers/w#readme", "dependencies": { "axios": "^0.17.1", - "commander": "^2.13.0", - "node-7z": "^0.4.0" + "commander": "^2.13.0" } } diff --git a/utils/extract.js b/utils/extract.js index f86c4ad..ee549c8 100644 --- a/utils/extract.js +++ b/utils/extract.js @@ -1,11 +1,12 @@ -var sevenZip = require('node-7z') -var Zip = new sevenZip() +'use strict'; -const extract = (filename, destination) => { -Zip.extractFull(filename, destination) - .progress((files) => console.log('Some files are extracted: %s', files)) - .then(() => console.log('Extracting done!')) - .catch((err) => console.error(err)) -} +const child = require('child_process'); +const { normalize } = require('path'); -module.exports = extract +function extract(source, destination) { + child.execSync(`7z x ${source} -o${destination}`); + child.execSync(`mv ${normalize(destination + '/WordBox-master/*')} ${destination}`); + child.execSync(`rm -rf ${normalize(destination + '/WordBox-master/')}`); +}; + +module.exports = extract; \ No newline at end of file diff --git a/utils/npminstall.js b/utils/npminstall.js new file mode 100644 index 0000000..35cdc8c --- /dev/null +++ b/utils/npminstall.js @@ -0,0 +1,9 @@ +'use strict'; + +const child = require('child_process'); + +function npminstall(projectFolder) { + return std = child.execSync(`cd ${projectFolder} && npm install`); +}; + +module.exports = npminstall; \ No newline at end of file