New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

zexron-cli

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zexron-cli - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

76

initProject/generate.js

@@ -5,3 +5,3 @@ /**

* -----
* Last Modified: 2018-02-27 02:09:38
* Last Modified: 2018-02-28 11:45:34
*/

@@ -11,7 +11,13 @@

const path = require('path')
const http = require('http')
const JSZip = require('jszip')
const chalk = require('chalk')
const ora = require('ora')
const zip = new JSZip()
const AVAILABLE_TYPES = ['gulp', 'gulp2', 'webpack']
/**
* Generate target folder
* @param {String} dir
*/
function makeTarget (dir) {

@@ -29,3 +35,10 @@ const targetPath = dir || './'

/**
* Copy template
* @param {String} type
* @param {String} dir
*/
exports.generate = function (type, dir) {
const targetDir = dir || '.'
if (AVAILABLE_TYPES.indexOf(type) < 0) {

@@ -35,16 +48,13 @@ throw new Error(`No Such Type: ${type}`)

console.log('')
console.log('Start generating', chalk.cyan.underline(type))
console.log('')
makeTarget(dir)
new JSZip.external.Promise((resolve, reject) => {
fs.readFile(path.resolve(__dirname, `templates/${type}.zip`), (err, data) => {
if (err) {
reject(err)
} else {
resolve(data)
}
})
})
.then((data) => zip.loadAsync(data))
downloadFile(type)
.then((data) => {
// Copy files and make folders
Object.keys(data.files).forEach(key => {
const filePath = path.join(dir, key)
const filePath = path.join(targetDir, key)
if (data.files[key].dir) {

@@ -59,5 +69,6 @@ fs.mkdirSync(filePath)

})
console.log('')
console.log(chalk.green('Success create', chalk.cyan.underline(type), 'on'))
console.log(` ${path.resolve(dir || './')}`)
console.log(` ${path.resolve(targetDir)}`)
console.log('')

@@ -70,1 +81,40 @@ })

}
/**
* Download zip file from 404
* @param {String} type
*/
function downloadFile (type) {
return new Promise((resolve, reject) => {
const spinner = ora(`Downloading ${chalk.underline.cyan(`${type}.zip`)}`).start()
const request = http.get(`http://www.status404.cn/BuildTool/${type}.zip`, (res) => {
if (res.statusCode !== 200) {
spinner.fail(`Fail on downloading ${chalk.underline.cyan(`${type}.zip`)}: ${res.statusCode}`)
reject()
return
}
let data = []
let dataLen = 0
res.on('data', (chunk) => {
data.push(chunk)
dataLen += chunk.length
})
res.on('end', () => {
const buf = Buffer.concat(data)
zip
.loadAsync(buf)
.then((zip) => {
spinner.succeed(`Download Success ${chalk.underline.cyan(`${type}.zip`)}`)
resolve(zip)
})
})
})
request.on('error', (err) => {
spinner.fail(`Fail on downloading ${chalk.underline.cyan(`${type}.zip`)}`)
reject(err)
})
})
}

5

package.json
{
"name": "zexron-cli",
"version": "0.0.2",
"version": "0.1.0",
"description": "Easy CLI commands",

@@ -31,4 +31,5 @@ "main": "index.js",

"commander": "^2.14.1",
"jszip": "^3.1.5"
"jszip": "^3.1.5",
"ora": "^2.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc