64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
|
/* eslint-disable */
|
||
|
const path = require('path');
|
||
|
const fsEx = require('fs-extra');
|
||
|
const chalk = require('chalk')
|
||
|
const archiver = require('archiver');
|
||
|
const fs = require('fs');
|
||
|
const root = process.cwd()
|
||
|
const moment=require('moment')
|
||
|
console.log(chalk.green(`root path :${root}`))
|
||
|
const resolve = (url) => {
|
||
|
return path.join(root, url)
|
||
|
}
|
||
|
|
||
|
const copy = async (from, to) => {
|
||
|
try {
|
||
|
await fsEx.copy(resolve(from), resolve(to));
|
||
|
console.log(chalk.green(`success:${from}===>${to}`));
|
||
|
} catch (error) {
|
||
|
console.log(chalk.red(`errors:=>${error}`));
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const copyFile = async () => {
|
||
|
await Promise.all([
|
||
|
copy('/static/', '/server/static/'),
|
||
|
copy('/.nuxt/', '/server/.nuxt/'),
|
||
|
copy('/ecosystem.config.js', '/server/ecosystem.config.js'),
|
||
|
copy('/package.json', '/server/package.json'),
|
||
|
copy('/nuxt.config.js', '/server/nuxt.config.js'),
|
||
|
]);
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
function zipFile() {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
const archive = archiver('zip', {
|
||
|
zlib: {
|
||
|
level: 5,
|
||
|
},
|
||
|
}).on('error', (err) => {
|
||
|
reject(err)
|
||
|
});
|
||
|
const output = fs.createWriteStream(`${root}/Limx${moment(new Date()).format('HH时mm分ss秒')}.zip`)
|
||
|
.on('close', (err) => {
|
||
|
if (err) {
|
||
|
reject(err)
|
||
|
}
|
||
|
resolve();
|
||
|
});
|
||
|
archive.pipe(output);
|
||
|
archive.directory(path.join(root, `/server`), `/server`);
|
||
|
archive.finalize();
|
||
|
})
|
||
|
}
|
||
|
|
||
|
|
||
|
// copyFile();
|
||
|
module.exports = {
|
||
|
copy,
|
||
|
copyFile,
|
||
|
zipFile
|
||
|
}
|