Skip to content

Commit

Permalink
修改:
Browse files Browse the repository at this point in the history
  * 增加自动发布功能。
zenjava committed Nov 4, 2019
1 parent 16b2873 commit c31ba6a
Showing 5 changed files with 683 additions and 27 deletions.
159 changes: 159 additions & 0 deletions interval/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/**
*
* create by ligx
*
* @flow
*/

const { removeSync, writeJSON, readJSON } = require('fs-extra');
const crossSpawn = require('@lugia/mega-utils/lib/crossSpawn');
const path = require('path');
const replace = require('replace-in-file');
const OSS = require('ali-oss');
const fs = require('fs');
const glob = require('glob');

async function spawn(args, msg) {
console.info(msg, '开始');
const yarn = crossSpawn('yarn', args);
return new Promise((resolve, reject) => {
yarn.on('error', error => {
console.error(error);
reject(error);
});
yarn.stdout.on('data', chunk => {
console.info(chunk.toString());
});
yarn.on('exit', (code, error) => {
if (code === 0) {
console.info(msg, '完毕');
resolve(msg);
} else {
console.error(msg, error);
reject(msg);
}
});
});
}

async function uploadOSS(target, source) {
const client = OSS({
region: 'a',
accessKeyId: 'b',
accessKeySecret: 'c',
bucket: 'd',
timeout: '60s'
});
await client.putStream(target, fs.createReadStream(source));
}

async function getFiles(path, fileExt) {
return await new Promise((resolve, reject) => {
glob(
fileExt,
{
cwd: path
},
(error, files) => {
if (error) {
reject(error);
}
resolve(files);
}
);
});
}
async function getDirections(path) {
return await new Promise((resolve, reject) => {
glob(
'*/',
{
cwd: path
},
(error, files) => {
if (error) {
reject(error);
}
resolve(files);
}
);
});
}
async function publish(param) {
const dist = path.join(__dirname, '../dist');
// removeSync(dist);
console.info('清空打包目录');

const { base, version } = param;

const target = '../lugia.config.json';
await writeJSON(target, {
publicPath: `https://lugia.oss-cn-beijing.aliyuncs.com/lugia-site/${version}/`
});

// await spawn(['build'], '开始构建门户');

const getDistPath = target => path.join(dist, target);
const indexJS = getDistPath('index.*.js');

const replaceDownUrl = async (from, to) => {
await replace({
files: indexJS,
from,
to
});
};
const { mac, win, pdf } = param;
await replaceDownUrl('#DownLoadMac', mac);
await replaceDownUrl('#DownLoadWindows', win);
await replaceDownUrl('#DownLoadWindows', pdf);

console.info('替换下载地址');
console.info('上传JS文件');
const jsFiles = await getFiles(dist, '**/*.js');

const getAliBasePath = target => path.join('lugia-site', version, target);
jsFiles.forEach(async file => {
const target = getDistPath(file);
await uploadOSS(getAliBasePath(file), target);
console.info(`${target} done!`);
});
console.info('上传JS文件 done');

console.info('上传CSS文件');
const cssFiles = await getFiles(dist, '**/*.css');

cssFiles.forEach(async file => {
const target = getDistPath(file);
await uploadOSS(getAliBasePath(file), target);
console.info(`${target} done!`);
});

console.info('上传JS文件 done');

console.info('上传资源文件');
const dir = 'static';
console.info('处理目录', dir);
const files = await getFiles(getDistPath(dir), '**/*.*');

const getDirPath = target => path.join(dir, target);
for (let j = 0; j < files.length; j++) {
const file = files[j];
const target = getDirPath(file);

await uploadOSS(getAliBasePath(target), getDistPath(target));

console.info(`${target} done!`);
}
console.info('上传资源文件 done');
}

publish({
mac: 'https://lugia.oss-cn-beijing.aliyuncs.com/download/LugiaMega-1.1.4.dmg',
base: 'https://lugia.oss-cn-beijing.aliyuncs.com/',
win:
'https://lugia.oss-cn-beijing.aliyuncs.com/download/LugiaMega%20Setup%201.1.4.exe',
pdf:
'https://lugia.oss-cn-beijing.aliyuncs.com/download/lugiav1.1.0-%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8C%20%E4%B8%AD%E6%96%87%EF%BC%88%E7%AE%80%EF%BC%89.pdf',
version: '1.2.0'
});
4 changes: 3 additions & 1 deletion lugia.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const config = require('./lugia.config.json');

export default {
...config,
disableCSSModules: true,
cssModulesWithAffix: true,
publicPath: 'https://lugia.oss-cn-beijing.aliyuncs.com/',
extraBabelIncludes: [/decamelize/],
extraBabelPlugins: [
[
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -28,13 +28,17 @@
},
"devDependencies": {
"@lugia/mega-scripts": "^1.3.53",
"ali-oss": "^6.1.1",
"babel-jest": "23.4.2",
"babel-plugin-import": "^1.11.0",
"enzyme": "3.3.0",
"enzyme-adapter-react-16": "^1.5.0",
"flow": "^0.2.3",
"flow-bin": "^0.87.0",
"flow-typed": "^2.5.1",
"react-test-renderer": "^16.8.6"
"fs-extra": "^8.1.0",
"glob": "^7.1.5",
"react-test-renderer": "^16.8.6",
"replace-in-file": "^4.2.0"
}
}
8 changes: 4 additions & 4 deletions src/mega/index.js
Original file line number Diff line number Diff line change
@@ -218,18 +218,18 @@ export default class Mega extends React.Component {
<Tittle5>欢迎使用 Lugia Mega</Tittle5>
<Tittle2>请选择您要安装的操作系统</Tittle2>
<DownLoadBox>
<Mac href="https://lugia.oss-cn-beijing.aliyuncs.com/download/LugiaMega-1.1.3.dmg">
<Mac href="#DownLoadMac">
<MacLogo />
<Span>mac版本</Span>
</Mac>
<Window href="https://lugia.oss-cn-beijing.aliyuncs.com/download/LugiaMega%20Setup%201.1.3.exe">
<Window href="#DownLoadWindows">
<WindowLogo />
<Span>windows版本</Span>
</Window>
<DownLoad href="https://github.com/lugia-ysstech/lugia/raw/master/doc/lugia-v1.1.0-%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8C%20%E4%B8%AD%E6%96%87%EF%BC%88%E7%AE%80%EF%BC%89.pdf">
<DownLoad href="#DownLoadWindows">
<IconSpan>
<Icon
iconClass="lugia-icon-financial_pdf"
iconClass="#DownPdf"
theme={{
icon: {
Icon: {
533 changes: 512 additions & 21 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit c31ba6a

Please sign in to comment.