Comparing version 0.0.6 to 0.0.7
@@ -0,42 +1,19 @@ | ||
const path = require('path'); | ||
const commander = require('commander'); | ||
const { checkGitStatus } = require('../src/utils/git'); | ||
const { getAuthResult } = require('../src/login'); | ||
const upload = require('../src/upload'); | ||
const saveInfo = require('../src/saveInfo'); | ||
const { logger, createInteractive } = require('../src/utils/logger'); | ||
const constants = require('../src/constants'); | ||
const { MESSAGE } = constants; | ||
const save = require('../src/saveInfo/index') | ||
module.exports = async function() { | ||
const checkLogger = createInteractive({ | ||
scope: MESSAGE.CHECK.SCOPE, | ||
}); | ||
checkLogger.start(MESSAGE.CHECK.GIT); | ||
// 检查提交 | ||
const isClear = await checkGitStatus(); | ||
if (!isClear) { | ||
// throw new Error('请先提交本地代码'); | ||
checkLogger.error(MESSAGE.CHECK.FAIL); | ||
logger.error('请先提交本地代码'); | ||
process.exit(-1); | ||
} | ||
commander | ||
.option('-m --mp', '小程序保存信息') | ||
.option('-p --projectPath [value]', '小程序保存信息') | ||
.parse(process.argv); | ||
checkLogger.await(MESSAGE.CHECK.USER); | ||
const authResult = await getAuthResult(); | ||
if (!authResult) { | ||
// throw new Error('用户名密码错误'); | ||
checkLogger.error(MESSAGE.CHECK.FAIL); | ||
logger.error('用户名密码错误'); | ||
process.exit(-1); | ||
} | ||
checkLogger.success(MESSAGE.CHECK.SUCCESS); | ||
if (commander.mp) { // 小程序 | ||
saveInfo('mp'); | ||
} else { | ||
const urls = await upload(); | ||
saveInfo('h5', urls); | ||
} | ||
let projectDir = commander.projectPath || process.cwd(); | ||
// projectDir = '/Users/tsxuehu/youzan-workspace/isv/weipaopaoshangcheng-youzanyun/weipaopaoshangcheng-youzanyun-mp-extension' | ||
let gitRepoDir = path.resolve(projectDir, '..'); | ||
if (commander.mp) { | ||
save(gitRepoDir, projectDir, 'mp'); | ||
} else { | ||
save(gitRepoDir, projectDir, 'h5'); | ||
} |
@@ -1,18 +0,10 @@ | ||
const { getAuthResult } = require('../src/login'); | ||
const { checkGitStatus } = require('../src/utils/git'); | ||
const upload = require('../src/upload'); | ||
const commander = require('commander'); | ||
module.exports = async function() { | ||
// 检查提交 | ||
const isClear = await checkGitStatus(); | ||
if (!isClear) { | ||
throw new Error('请先提交本地代码'); | ||
} | ||
const upload = require('../src/upload/index') | ||
const authResult = await getAuthResult(); | ||
if (!authResult) { | ||
throw new Error('用户名密码错误'); | ||
} | ||
upload(); | ||
} | ||
commander | ||
.parse(process.argv); | ||
let projectDir = commander.projectPath || process.cwd(); | ||
// projectDir = '/Users/tsxuehu/youzan-workspace/isv/weipaopaoshangcheng-youzanyun/weipaopaoshangcheng-youzanyun-mp-extension' | ||
let gitRepoDir = path.resolve(projectDir, '..'); | ||
upload(gitRepoDir, projectDir); |
#!/usr/bin/env node | ||
const commander = require('commander'); | ||
const upload = require('./youzanyun-upload'); | ||
const save = require('./youzanyun-save'); | ||
const package = require('../package.json'); | ||
@@ -10,19 +8,16 @@ const checkVersion = require('../src/version'); | ||
commander | ||
.version(package.version) | ||
.usage('<command> [options]'); | ||
.version(package.version) | ||
.description('有赞云开发助手') | ||
.usage('<command> [options]'); | ||
commander | ||
.command('upload') | ||
.action(upload); | ||
.command('upload', '上传js') | ||
.command('save', '保存信息'); | ||
commander | ||
.command('save') | ||
.option('-m --mp', '小程序保存信息') | ||
.action(save); | ||
checkVersion(() => { | ||
commander.parse(process.argv); | ||
if(commander.args.length==0){ | ||
commander.help(); | ||
} | ||
commander.parse(process.argv); | ||
if (commander.args.length == 0) { | ||
commander.help(); | ||
} | ||
}); | ||
{ | ||
"name": "youzanyun", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "有赞云工具", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
module.exports = { | ||
CDN_DOMAIN: 'mall-cloud', | ||
LOGIN_API: 'http://127.0.0.1:8210/api/mall-cloud/auth', | ||
TOKEN_API: 'http://127.0.0.1:8210/api/mall-cloud/token', | ||
VERSION_API: 'http://127.0.0.1:8210/api/mall-cloud/info/save', | ||
LOGIN_API: 'http://diy.youzanyun.com/api/mall-cloud/auth', | ||
TOKEN_API: 'http://diy.youzanyun.com/api/mall-cloud/token', | ||
VERSION_API: 'http://diy.youzanyun.com/api/mall-cloud/info/save', | ||
MESSAGE: { | ||
@@ -7,0 +7,0 @@ CHECK: { |
@@ -8,3 +8,2 @@ const path = require("path"); | ||
const { LOGIN_API } = require("../constants"); | ||
// const { promiseSpawm } = require('../utils/run'); | ||
const userhome = require("../utils/userhome"); | ||
@@ -11,0 +10,0 @@ const { getGitInfo } = require('../utils/git'); |
@@ -1,56 +0,43 @@ | ||
const axios = require('axios'); | ||
const path = require('path'); | ||
const {checkGitStatus} = require('../utils/git'); | ||
const {getAuthResult} = require('../login'); | ||
const upload = require('../upload'); | ||
const {saveMp, saveH5} = require('./save'); | ||
const {logger, createInteractive} = require('../utils/logger'); | ||
const constants = require('../constants'); | ||
const { getInfo } = require(path.resolve(process.cwd(), 'scripts/info.js')); | ||
const { getGitInfo } = require('../utils/git'); | ||
const { createInteractive } = require('../utils/logger'); | ||
const { VERSION_API, MESSAGE } = constants; | ||
const {MESSAGE} = constants; | ||
/** | ||
* 保存页面组件信息 | ||
*/ | ||
module.exports = async function(type, urls) { | ||
const infoLogger = createInteractive({ | ||
scope: MESSAGE.INFO.SCOPE, | ||
}); | ||
infoLogger.start(MESSAGE.INFO.START); | ||
module.exports = async function (gitRepoDir, projectDir, type) { | ||
const checkLogger = createInteractive({ | ||
scope: MESSAGE.CHECK.SCOPE, | ||
}); | ||
const pages = await getInfo(urls); | ||
const gitInfo = await getGitInfo(); | ||
const params = { | ||
appName: gitInfo.appName, | ||
type, | ||
commitUser: gitInfo.username, | ||
commitHash: gitInfo.commitId, | ||
pages, | ||
} | ||
checkLogger.start(MESSAGE.CHECK.GIT); | ||
// 检查提交 | ||
const isClear = await checkGitStatus(gitRepoDir); | ||
if (!isClear) { | ||
// throw new Error('请先提交本地代码'); | ||
checkLogger.error(MESSAGE.CHECK.FAIL); | ||
logger.error('请先提交本地代码'); | ||
process.exit(-1); | ||
} | ||
try { | ||
await saveInfo(params); | ||
infoLogger.success(MESSAGE.INFO.SUCCESS); | ||
} catch (error) { | ||
const message = get(err, 'message', '') || get(err, 'response.data.message', ''); | ||
infoLogger.error(`${MESSAGE.INFO.FAIL}: ${message}`); | ||
} | ||
} | ||
checkLogger.await(MESSAGE.CHECK.USER); | ||
const authResult = await getAuthResult(); | ||
if (!authResult) { | ||
// throw new Error('用户名密码错误'); | ||
checkLogger.error(MESSAGE.CHECK.FAIL); | ||
logger.error('用户名密码错误'); | ||
process.exit(-1); | ||
} | ||
checkLogger.success(MESSAGE.CHECK.SUCCESS); | ||
async function saveInfo(data) { | ||
return new Promise((resolve, reject) => { | ||
axios.post(VERSION_API, data, { | ||
headers: { | ||
'X-Service-Chain': 'prj004121', | ||
} | ||
}) | ||
.then(function (res) { | ||
if (+res.data.code === 0) { | ||
resolve(res.data); | ||
} else { | ||
reject(res.data); | ||
} | ||
}) | ||
.catch(function (err) { | ||
reject(err); | ||
}); | ||
}); | ||
if (type == 'mp') { // 小程序 | ||
saveMp(gitRepoDir, projectDir); | ||
} else { | ||
const urls = await upload(); | ||
saveH5(gitRepoDir, projectDir, urls); | ||
} | ||
} |
@@ -1,135 +0,19 @@ | ||
const qiniu = require('qiniu'); | ||
const axios = require('axios'); | ||
const path = require('path'); | ||
const constants = require('../constants'); | ||
const { promiseSpawm } = require('../utils/run'); | ||
const { logger, createInteractive } = require('../utils/logger'); | ||
const { getUploadFiles } = require(path.resolve(process.cwd(), 'scripts/info.js')); | ||
const { getAuthResult } = require('../login'); | ||
const { checkGitStatus } = require('../utils/git'); | ||
const upload = require('./upload'); | ||
const { TOKEN_API, MESSAGE, CDN_DOMAIN } = constants; | ||
const putExtra = new qiniu.form_up.PutExtra(); | ||
const formUploader = new qiniu.form_up.FormUploader(getQiniuConfig()); | ||
module.exports = async function(){ | ||
const buildLogger = createInteractive({ | ||
scope: MESSAGE.BUILD.SCOPE, | ||
}); | ||
buildLogger.start(MESSAGE.BUILD.START); | ||
try { | ||
await promiseSpawm('npm', [ 'run', 'build' ], { | ||
cwd: '', | ||
}); | ||
buildLogger.success(MESSAGE.BUILD.SUCCESS); | ||
} catch (error) { | ||
buildLogger.error(MESSAGE.BUILD.FAIL); | ||
logger.error(error); | ||
module.exports = async function(projectDir) { | ||
// 检查提交 | ||
const isClear = await checkGitStatus(); | ||
if (!isClear) { | ||
throw new Error('请先提交本地代码'); | ||
} | ||
const uploadLogger = createInteractive({ | ||
scope: `${MESSAGE.CDN.SCOPE}`, | ||
}); | ||
uploadLogger.start(MESSAGE.CDN.START); | ||
const pageFiles = await getUploadFiles(); | ||
uploadLogger.await(MESSAGE.CDN.UPLOADING); | ||
try { | ||
const urls = await upload(pageFiles); | ||
uploadLogger.success(MESSAGE.CDN.SUCCESS); | ||
return urls; | ||
} catch (error) { | ||
uploadLogger.error(MESSAGE.CDN.FAIL); | ||
logger.error(error); | ||
const authResult = await getAuthResult(); | ||
if (!authResult) { | ||
throw new Error('用户名密码错误'); | ||
} | ||
} | ||
/** | ||
* 文件上传 | ||
* file: 本地文件路径 | ||
*/ | ||
async function upload(files) { | ||
let token; | ||
try { | ||
token = await getToken(); | ||
} catch (err) { | ||
// 获取上传token失败 | ||
return Promise.reject(err); | ||
} | ||
let currentFiles = []; | ||
if (typeof files !== 'string' && !(files instanceof Array)) { | ||
return Promise.reject('上传文件参数类型错误: expect "string" or "Array"'); | ||
} else if (typeof files === 'string') { | ||
currentFiles.push(files); | ||
} else { | ||
currentFiles = files; | ||
} | ||
// console.log('---currentFiles---', currentFiles); | ||
return Promise.all(currentFiles.map(file => { | ||
return new Promise((resolve, reject) => { | ||
const fileName = file.split(path.sep).pop(); | ||
formUploader.putFile( | ||
token, | ||
`${CDN_DOMAIN}/${fileName}`, | ||
file, | ||
putExtra, | ||
(respErr, respBody, respInfo) => { | ||
// 上传失败 | ||
if (respErr) { | ||
reject(respErr); | ||
} | ||
if (+respInfo.statusCode === 200) { | ||
const url = respBody.data.attachment_full_url; | ||
resolve(url.replace('http:', 'https:')); | ||
} else { | ||
// 上传返回信息不正确 | ||
reject(respInfo); | ||
} | ||
}, | ||
); | ||
}); | ||
})); | ||
const result = await upload(projectDir); | ||
return result; | ||
}; | ||
/** | ||
* 获取文件上传 Token | ||
*/ | ||
async function getToken() { | ||
return axios({ | ||
method: 'get', | ||
url: TOKEN_API, | ||
}).then((res) => { | ||
const { data } = res; | ||
if (+data.code === 0) { | ||
return data.data.upload_token; | ||
} else { | ||
throw new Error(data.msg); | ||
} | ||
}).catch(err => { | ||
throw new Error(err.msg || '获取token失败'); | ||
}); | ||
} | ||
/** | ||
* 获取 七牛 CDN 配置 | ||
*/ | ||
function getQiniuConfig() { | ||
return new qiniu.conf.Config({ | ||
// 空间对应的机房 | ||
zone: qiniu.zone.Zone_z0, | ||
// 是否使用 https 域名 | ||
useHttpsDomain: true, | ||
// 上传是否使用 cdn 加速 | ||
useCdnDomain: true, | ||
}); | ||
} |
@@ -5,5 +5,4 @@ const path = require("path"); | ||
const { promiseExec } = require('../utils/run'); | ||
const proDir = path.resolve(process.cwd(), '../'); | ||
module.exports.getGitInfo = async function() { | ||
module.exports.getGitInfo = async function(gitRepoDir) { | ||
const gitInfo = {}; | ||
@@ -13,3 +12,3 @@ try { | ||
const remoteInfo = await promiseExec('git remote -v', { | ||
cwd: proDir, | ||
cwd: gitRepoDir, | ||
}); | ||
@@ -21,3 +20,3 @@ const appNameArr = remoteInfo.split('/').pop().split('.'); | ||
const username = await promiseExec('git config user.name', { | ||
cwd: proDir, | ||
cwd: gitRepoDir, | ||
}); | ||
@@ -28,3 +27,3 @@ gitInfo.username = username || 'unknown'; | ||
const commitId = await promiseExec('git rev-parse HEAD', { | ||
cwd: proDir, | ||
cwd: gitRepoDir, | ||
}); | ||
@@ -39,6 +38,6 @@ gitInfo.commitId = commitId; | ||
module.exports.checkGitStatus = async function() { | ||
module.exports.checkGitStatus = async function(gitRepoDir) { | ||
try { | ||
const statusInfo = await promiseExec('git status', { | ||
cwd: proDir, | ||
cwd: gitRepoDir, | ||
}); | ||
@@ -57,2 +56,2 @@ const statusArr = statusInfo.split('\n') | ||
const r = module.exports.checkGitStatus() | ||
const r = module.exports.checkGitStatus() |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
18730
17
558
8