-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67a18b9
commit d598ad4
Showing
8 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var Charts = require('../lib/index') | ||
|
||
window.Charts = Charts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const { emptyDir } = require('@jiaminghi/fs') | ||
const print = require('./plugin/print') | ||
const exec = require('./plugin/exec') | ||
|
||
const libName = 'charts' | ||
|
||
async function start () { | ||
const isEmpty = await emptyDir('./dist') | ||
|
||
if (!isEmpty) { | ||
print.error('Exception in emptyDir!') | ||
|
||
return | ||
} | ||
|
||
print.tip('After emptyDir!') | ||
|
||
const doBabel = await exec('babel -d lib/ src/') | ||
|
||
if (!doBabel) { | ||
print.error('Exception in babel') | ||
|
||
return | ||
} | ||
|
||
print.tip('After babel!') | ||
|
||
const browserifyMap = await exec(`browserify build/entry.js > dist/${libName}.map.js --debug`) | ||
|
||
if (!browserifyMap) { | ||
print.error('Exception in browserifyMap') | ||
|
||
return | ||
} | ||
|
||
print.tip(`After browserify! (${libName}.map.js)`) | ||
|
||
const browserifyMin = await exec(`browserify build/entry.js > dist/${libName}.min.js`) | ||
|
||
if (!browserifyMin) { | ||
print.error('Exception in browserifyMin') | ||
|
||
return | ||
} | ||
|
||
print.tip(`After browserify! (${libName}.min.js)`) | ||
|
||
const uglifyjs = await exec(`uglifyjs dist/${libName}.min.js -o dist/${libName}.min.js`) | ||
|
||
if (!uglifyjs) { | ||
print.error('Exception in uglifyjs') | ||
|
||
return | ||
} | ||
|
||
print.success('DONE!') | ||
} | ||
|
||
start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { exec } = require('child_process') | ||
|
||
function doExec (execString, maxBuffer = 1024 ** 5) { | ||
return new Promise(resolve => { | ||
exec(execString, { | ||
maxBuffer | ||
}, err => { | ||
if (err) { | ||
console.error(err) | ||
|
||
resolve(false) | ||
} else { | ||
resolve(true) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = doExec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const print = { | ||
log (info) { | ||
console.log(info) | ||
}, | ||
warn (info) { | ||
console.log('\033[31;33m' + info + '\033[0m') | ||
}, | ||
error (info) { | ||
console.log('\033[31;40m' + info + '\033[0m') | ||
}, | ||
tip (info) { | ||
console.log('\033[40;32m' + info + '\033[0m') | ||
}, | ||
success (info) { | ||
console.log('\033[42;30m' + info + '\033[0m') | ||
}, | ||
yellow (info) { | ||
console.log('\033[31;33m' + info + '\033[0m') | ||
} | ||
} | ||
|
||
module.exports = print |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const { fileForEach } = require('@jiaminghi/fs') | ||
const Client = require('ftp') | ||
const print = require('./plugin/print') | ||
const { emptyDir, put } = require('./plugin/ftp') | ||
const getNodeParams = require('./plugin/nodeParams') | ||
|
||
let config = null | ||
|
||
try { | ||
config = require('./config') | ||
} catch (err) { | ||
void 0 | ||
} | ||
|
||
const DIST_PATH = './dist/' | ||
const FTP_PATH = './charts/' | ||
|
||
const ftp = new Client() | ||
|
||
ftp.on('ready', async foo => { | ||
print.tip('FTP connected!') | ||
|
||
const isEmpty = await emptyDir(ftp, FTP_PATH) | ||
|
||
if (!isEmpty) { | ||
print.error('Exception in emptyDir!') | ||
|
||
return false | ||
} | ||
|
||
let status = true | ||
|
||
await fileForEach(DIST_PATH, async src => { | ||
const destPath = FTP_PATH + src.split('/').slice(-1)[0] | ||
|
||
print.tip('Upload: ' + destPath) | ||
|
||
if (!await put(ftp, src, destPath)) { | ||
status = false | ||
|
||
print.error('Exception in upload ' + destPath) | ||
} | ||
}) | ||
|
||
if (status) { | ||
print.yellow('-------------------------------------') | ||
print.success(' Automatic Deployment Success! ') | ||
print.yellow('-------------------------------------') | ||
} | ||
|
||
ftp.destroy() | ||
}) | ||
|
||
ftp.on('greeting', foo => { | ||
print.tip('FTP greeting') | ||
}) | ||
ftp.on('close', foo => { | ||
print.tip('FTP close') | ||
}) | ||
ftp.on('end', foo => { | ||
print.tip('FTP end') | ||
}) | ||
ftp.on('error', foo => { | ||
print.tip('FTP error') | ||
}) | ||
|
||
const { host, user, pass } = config || getNodeParams() | ||
|
||
if (!host || !user || !pass) { | ||
print.error('Upload Dist to FTP Missing Parameters!') | ||
|
||
return false | ||
} | ||
|
||
print.tip('Start Upload!') | ||
|
||
ftp.connect({ | ||
host, | ||
user, | ||
password: pass | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
async function getList (ftp, src) { | ||
return new Promise(resolve => { | ||
ftp.list(src, (err, list) => { | ||
if (err) { | ||
console.error(err) | ||
|
||
resolve(false) | ||
} else { | ||
resolve(list) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
async function rmDir (ftp, src, recusive = true) { | ||
return new Promise(resolve => { | ||
ftp.rmdir(src, recusive, err => { | ||
if (err) { | ||
console.error(err) | ||
|
||
resolve(false) | ||
} else { | ||
resolve(true) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
async function deleteFile (ftp, src) { | ||
return new Promise(resolve => { | ||
ftp.delete(src, err => { | ||
if (err) { | ||
console.error(err) | ||
|
||
resolve(false) | ||
} else { | ||
resolve(true) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
async function emptyDir (ftp, src, except = []) { | ||
const list = await getList(ftp, src) | ||
|
||
for (let i = 0, listNum = list.length; i < listNum; i++) { | ||
const { type, name } = list[i] | ||
|
||
if (type === 'd' && (name === '.' || name === '..')) continue | ||
if (except.find(n => n === name)) continue | ||
|
||
const fullSrc = `${src}${name}` | ||
|
||
if (type === 'd') { | ||
if (!await rmDir(ftp, fullSrc, true)) return false | ||
} else { | ||
if (!await deleteFile(ftp, fullSrc)) return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
async function put (ftp, src, dest) { | ||
return new Promise(resolve => { | ||
ftp.put(src, dest, err => { | ||
if (err) { | ||
console.error(err) | ||
|
||
resolve(false) | ||
} else { | ||
resolve(true) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
async function mkDir (ftp, src, recusive = true) { | ||
return new Promise(resolve => { | ||
ftp.mkdir(src, recusive, err => { | ||
if (err) { | ||
console.error(err) | ||
|
||
resolve(false) | ||
} else { | ||
resolve(true) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = { | ||
put, | ||
rmDir, | ||
mkDir, | ||
getList, | ||
emptyDir, | ||
deleteFile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function getNodeParams () { | ||
const params = {} | ||
|
||
process.argv.slice(2).forEach(param => { | ||
param = param.split('=') | ||
|
||
params[param[0]] = param[1] | ||
}) | ||
|
||
return params | ||
} | ||
|
||
module.exports = getNodeParams |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const print = { | ||
log (info) { | ||
console.log(info) | ||
}, | ||
warn (info) { | ||
console.log('\033[31;33m' + info + '\033[0m') | ||
}, | ||
error (info) { | ||
console.log('\033[31;40m' + info + '\033[0m') | ||
}, | ||
tip (info) { | ||
console.log('\033[40;32m' + info + '\033[0m') | ||
}, | ||
success (info) { | ||
console.log('\033[42;30m' + info + '\033[0m') | ||
}, | ||
yellow (info) { | ||
console.log('\033[31;33m' + info + '\033[0m') | ||
} | ||
} | ||
|
||
module.exports = print |