lev-publisher
Advanced tools
Comparing version 1.0.0 to 1.0.1
138
bin/index.js
@@ -43,3 +43,9 @@ #! /usr/bin/env node | ||
const version = meta.version; | ||
publish(space, name, version, "dist", argv.override); | ||
publish(space, name, version, argv.override, "dist") | ||
.then(() => { | ||
confirmResult(space, name, version, argv.override, meta.lev); | ||
}) | ||
.catch((_) => { | ||
process.exit(1); | ||
}); | ||
}); | ||
@@ -49,5 +55,33 @@ }); | ||
function walkSync(currentDirPath, callback) { | ||
fs.readdirSync(currentDirPath).forEach(function (name) { | ||
const filePath = path.join(currentDirPath, name); | ||
const token = process.env["LEVHUB_TOKEN"]; | ||
function confirmResult(space, name, version, override, deps) { | ||
axios | ||
.post( | ||
`${host}/confirm`, | ||
{ | ||
space, | ||
name, | ||
version, | ||
override, | ||
deps, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: token, | ||
}, | ||
} | ||
) | ||
.then((res) => { | ||
const artifact = `${space}.${name}:${version}`; | ||
console.log(`🎉 publish ${artifact} successfully!\n`.green); | ||
}) | ||
.catch((error) => { | ||
console.log(`${error.response.data.msg.red}\n`); | ||
}); | ||
} | ||
function walkSync(current, callback) { | ||
fs.readdirSync(current).forEach(function (name) { | ||
const filePath = path.join(current, name); | ||
const stat = fs.statSync(filePath); | ||
@@ -62,45 +96,59 @@ if (stat.isFile()) { | ||
const token = process.env["LEVHUB_TOKEN"]; | ||
async function publish(space, name, version, override, folder) { | ||
const paths = []; | ||
function publish(space, name, version, folder, override) { | ||
walkSync(folder, function (filePath, stat) { | ||
let path = filePath.substring(folder.length + 1); | ||
axios | ||
.post( | ||
`${host}/presign_put`, | ||
{ | ||
space, | ||
name, | ||
version, | ||
path, | ||
override, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: token, | ||
walkSync(folder, function (file, stat) { | ||
let path = file.substring(folder.length + 1); | ||
paths.push({ file, path }); | ||
}); | ||
async function wrapper({ file, path }) { | ||
return new Promise((resolve, reject) => { | ||
axios | ||
.post( | ||
`${host}/presign_put`, | ||
{ | ||
space, | ||
name, | ||
version, | ||
path, | ||
override, | ||
}, | ||
} | ||
) | ||
.then((res) => { | ||
const data = res.data; | ||
if (!data.ok) { | ||
throw "exit"; | ||
} | ||
axios | ||
.put(data.payload, fs.readFileSync(filePath), { | ||
{ | ||
headers: { | ||
"Content-Type": "text/plain", | ||
Authorization: token, | ||
}, | ||
}) | ||
.then((res) => { | ||
console.log(`🎉 ${filePath} upload success\n`.green); | ||
}) | ||
.catch((error) => { | ||
console.log(`${error.response.red}\n`); | ||
}); | ||
}) | ||
.catch((error) => { | ||
console.error(`${error.response.data.msg.red}\n`); | ||
}); | ||
}); | ||
} | ||
) | ||
.then((res) => { | ||
const data = res.data; | ||
if (!data.ok) { | ||
reject(data.msg); | ||
return; | ||
} | ||
axios | ||
.put(data.payload, fs.readFileSync(file), { | ||
headers: { | ||
"Content-Type": "text/plain", | ||
}, | ||
maxContentLength: 20971520, | ||
maxBodyLength: 20971520, | ||
}) | ||
.then((res) => { | ||
console.log(`🎉 ${file} upload success\n`.green); | ||
resolve(res); | ||
}) | ||
.catch((error) => { | ||
console.log(`${error.response.red}\n`); | ||
reject(error); | ||
}); | ||
}) | ||
.catch((error) => { | ||
console.error(`${error.response.data.msg.red}\n`); | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
return await Promise.all(paths.map((path) => wrapper(path))); | ||
} | ||
@@ -161,4 +209,4 @@ | ||
if (isNil(token) || isEmpty(token)) { | ||
console.error("LEVHUB_TOKEN is missing"); | ||
process.exit(1); | ||
console.error("LEVHUB_TOKEN is missing".red); | ||
return; | ||
} | ||
@@ -165,0 +213,0 @@ |
{ | ||
"name": "lev-publisher", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "lev react component publisher", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
8438
315