Skip to content

Commit 7467128

Browse files
committed
优化build脚本,统一使用make
1 parent e204c34 commit 7467128

File tree

6 files changed

+153
-59
lines changed

6 files changed

+153
-59
lines changed

Makefile

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,54 @@
1-
# ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/
2-
# ELECTRON_VERSION=1.6.5
3-
# BUILD=ELECTRON_MIRROR=$(ELECTRON_MIRROR) electron-packager ./dist --asar --overwrite --out=build --version $(ELECTRON_VERSION)
41

52
VERSION=1.3.3
63
NAME=oss-browser
4+
CUSTOM=./custom
5+
6+
GULP=node ./node_modules/gulp/bin/gulp.js
7+
PKGER=node node_modules/electron-packager/cli.js
8+
ZIP=node zip.js
9+
10+
ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/
11+
ELECTRON_VERSION=1.6.5
12+
BUILD=ELECTRON_MIRROR=$(ELECTRON_MIRROR) $(PKGER) ./dist $(NAME) --asar --overwrite --out=build --version $(ELECTRON_VERSION)
13+
714

815
i:
916
cnpm i
1017
clean:
11-
npm run clean
12-
find . -name .DS_Store | xargs rm -rf
13-
18+
rm -rf dist node_modules build releases node/crc64/cpp-addon/node_modules node/ossstore/node_modules
1419
dev:
1520
NODE_ENV=development electron .
1621

1722
run:
18-
npm run dev
23+
custom=$(CUSTOM) npm run dev
1924

2025
prod:
2126
npm run prod
2227
watch:
23-
npm run watch
28+
$(GULP) watch --custom=$(CUSTOM)
2429
build:
25-
npm run build
30+
$(GULP) build --custom=$(CUSTOM)
2631

2732
win64:
28-
app_name=$(NAME) npm run win64
33+
$(BUILD) --platform=win32 --arch=x64
2934
rm -rf releases/$(VERSION)/$(NAME)-win32-x64.zip && mkdir -p releases/$(VERSION)
30-
cd build && zip ../releases/$(VERSION)/$(NAME)-win32-x64.zip -r $(NAME)-win32-x64
35+
$(ZIP) releases/$(VERSION)/$(NAME)-win32-x64.zip build/$(NAME)-win32-x64/
3136
win32:
32-
app_name=$(NAME) npm run win32
37+
$(BUILD) --platform=win32 --arch=ia32
3338
rm -rf releases/$(VERSION)/$(NAME)-win32-ia32.zip && mkdir -p releases/$(VERSION)
34-
cd build && zip ../releases/$(VERSION)/$(NAME)-win32-ia32.zip -r $(NAME)-win32-ia32
39+
$(ZIP) releases/$(VERSION)/$(NAME)-win32-ia32.zip build/$(NAME)-win32-ia32/
3540
linux64:
36-
app_name=$(NAME) npm run linux64
41+
$(BUILD) --platform=linux --arch=x64
3742
rm -rf releases/$(VERSION)/$(NAME)-linux-x64.zip && mkdir -p releases/$(VERSION)
38-
cd build && zip ../releases/$(VERSION)/$(NAME)-linux-x64.zip -r $(NAME)-linux-x64
43+
$(ZIP) releases/$(VERSION)/$(NAME)-linux-x64.zip build/$(NAME)-linux-x64/
3944
linux32:
40-
app_name=$(NAME) npm run linux32
45+
$(BUILD) --platform=linux --arch=ia32
4146
rm -rf releases/$(VERSION)/$(NAME)-linux-ia32.zip && mkdir -p releases/$(VERSION)
42-
cd build && zip ../releases/$(VERSION)/$(NAME)-linux-ia32.zip -r $(NAME)-linux-ia32
47+
$(ZIP) releases/$(VERSION)/$(NAME)-linux-ia32.zip build/$(NAME)-linux-ia32/
4348
mac:
44-
app_name=$(NAME) npm run mac
49+
$(BUILD) --platform=darwin --arch=x64 --icon=$(CUSTOM)/icon.icns
4550
rm -rf releases/$(VERSION)/$(NAME)-darwin-x64.zip && mkdir -p releases/$(VERSION)
46-
cd build && zip ../releases/$(VERSION)/$(NAME)-darwin-x64.zip -r $(NAME)-darwin-x64
51+
$(ZIP) releases/$(VERSION)/$(NAME)-darwin-x64.zip build/$(NAME)-darwin-x64/
4752
dmg:
4853
rm build/$(NAME)-darwin-x64/LICENSE* build/$(NAME)-darwin-x64/version
4954
ln -s /Applications/ build/$(NAME)-darwin-x64/Applications
@@ -54,6 +59,7 @@ dmg:
5459
hdiutil create -size 250M -format UDZO -srcfolder build/$(NAME)-darwin-x64 releases/$(VERSION)/$(NAME).dmg
5560

5661
all:win32 win64 linux32 linux64 mac
62+
@echo 'Done'
5763

5864

5965
.PHONY:build

Readme.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,30 @@ cnpm 是 npm(node 包管理工具)的中国镜像,可以提高下载依赖
101101
cnpm i -g windows-build-tools
102102
```
103103

104+
还需要下载make.exe,放到 `C:\windows\` 目录下
105+
106+
[make.exe(64位版本)](http://luogc.oss-cn-hangzhou.aliyuncs.com/oss-browser-publish/windows-tools/64/make.exe)
107+
108+
[make.exe(32位版本)](http://luogc.oss-cn-hangzhou.aliyuncs.com/oss-browser-publish/windows-tools/32/make.exe)
109+
110+
104111
### (4) 下载代码
105112

106113
```
107114
git clone [email protected]:aliyun/oss-browser.git
108115
```
109116

110-
安装依赖(请使用cnpm):
117+
安装依赖:
111118

112119
```
113-
cnpm i
120+
make i
114121
```
115122

116123

117124
### (5) 运行
118125

119126
```
120-
npm run dev # 开发模式运行, command+option+i 可用打开调试界面, win或linux按 F12.
127+
make run # 开发模式运行, command+option+i 可用打开调试界面, win或linux按 F12.
121128
```
122129

123130
开发模式下,会自动监听源码,如有修改,会自动build 前端代码到dist目录。
@@ -126,11 +133,11 @@ npm run dev # 开发模式运行, command+option+i 可用打开调试界面, wi
126133
### (6) 打包
127134

128135
```
129-
npm run build # build前端代码到dist目录
136+
make build # build前端代码到dist目录
130137
```
131138

132139
```
133-
npm run win64 # 打包win64程序, 可选: mac, linux64
140+
make win64 # 打包win64程序, 可选: mac, linux64,linux32,win32,win64,all.
134141
```
135142

136143

custom/Readme.md

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,40 @@ git clone {git地址}
3333
cd oss-browser
3434
```
3535

36+
### (4) 安装 make 命令
37+
38+
ubuntu 和 mac 默认有 make 命令。
39+
40+
windows 需要下载make.exe,放到 `C:\windows\` 目录下:
41+
42+
[make.exe(64位版本)](http://luogc.oss-cn-hangzhou.aliyuncs.com/oss-browser-publish/windows-tools/64/make.exe)
43+
44+
[make.exe(32位版本)](http://luogc.oss-cn-hangzhou.aliyuncs.com/oss-browser-publish/windows-tools/32/make.exe)
45+
46+
在centos 下,使用以下命令安装:
47+
48+
```
49+
yum install make
50+
```
51+
3652

3753
## 2. 开始尝试启动
3854

3955
```
40-
cnpm i # 安装 node 模块依赖
41-
npm run build # 生成dist目录
56+
make i # 安装 node 模块依赖
57+
make build # 生成dist目录
4258
```
4359

4460
启动界面:
4561
```
46-
npm run dev # 开发模式启动
62+
make run # 开发模式启动
4763
```
4864

4965
这时,你可以看到界面了(开发模式,可以按 command+r 刷新)。
5066

5167

5268
## 3. 自定义 custom 配置
5369

54-
5570
```
5671
oss-browser/
5772
|-- custom
@@ -60,50 +75,42 @@ oss-browser/
6075
将 custom 目录复制一份到其他地方,比如 ~/Desktop/custom/,
6176
修改目录下的 index.js 配置 和 图标即可。
6277

78+
Makefile有3个变量,可以替换,分别为:NAME,CUSTOM,VERSION.
79+
80+
* 假设你的应用名为: my-oss-browser
81+
* 假设你的custom目录为: ~/Desktop/custom/
6382

6483
然后指定custom路径 build:
6584
```
66-
C=~/Desktop/custom/ npm run build
85+
make build NAME=my-oss-browser CUSTOM=~/Desktop/custom/
6786
```
6887

6988
开发模式启动:
7089
```
71-
C=~/Desktop/custom/ npm run dev #开发模式启动
72-
```
73-
74-
## 4. build
75-
76-
* 如果在 windows系统下运行
77-
78-
```
79-
npm run all
80-
81-
# npm run all app_name=oss-browser # 自定义app_name
90+
make run NAME=my-oss-browser CUSTOM=~/Desktop/custom/
8291
```
83-
会在 build 下生成几个文件夹。即是安装文件。你可以手动zip一下,再发布。
8492

8593

86-
* 如果是在 mac 下运行,
87-
88-
先修改Makefile中的 VERSION 和 NAME 变量,VERSION 需要和 custom/index.js中的version相同,NAME需要和appId相同。
94+
## 4. build
8995

90-
然后运行:
9196

9297
```
93-
make all NAME=oss-browser
98+
make all NAME=my-oss-browser CUSTOM=~/Desktop/custom/
9499
```
95100

96-
* 可以指定 NAME 和 VERSION 变量(可选).
101+
* Makefile中的 VERSION 和 NAME 变量,VERSION 需要和 custom/index.js 中的version相同,NAME需要和appId相同。
102+
* 可以指定 NAME,CUSTOM 和 VERSION 变量.
97103
* 除了会在 build 下生成几个目录,还会在 releases 目录下,生成几个压缩包(绿色免安装版)。
98104

99105

100106

101-
### (可选) 其他平台相关的安装文件(包含安装向导的):
107+
### (可选) mac平台相关的安装文件
102108

103109
```
104-
make dmg NAME=oss-browser # 只能在mac系统下build, *.dmg 文件
110+
make dmg NAME=oss-browser # 只能在mac系统下build,生成 releases/${VERSION}/oss-browser.dmg 文件
105111
```
106-
* 可以指定 NAME 和 VERSION 变量(可选).
112+
* 此命令需要在 make mac 或者 make all 命令后执行。
113+
* 可以指定 NAME, CUSTOM 和 VERSION 变量。
107114

108115

109116

custom/icon.ico

49.5 KB
Binary file not shown.

package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,8 @@
88
"dev:run": "cross-env NODE_ENV=development electron .",
99
"postbuild": "node gen",
1010
"prod": "cross-env NODE_ENV=production cd dist && electron .",
11-
"clean": "rm -rf dist node_modules build releases node/crc64/cpp-addon/node_modules node/ossstore/node_modules",
12-
"watch": "gulp watch --custom=${C}",
13-
"build": "gulp build --custom=${C}",
14-
"win64": "cross-env ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ electron-packager ./dist ${app_name} --asar --overwrite --out=build --version=${npm_package_devDependencies_electron} --platform=win32 --arch=x64",
15-
"win32": "cross-env ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ electron-packager ./dist ${app_name} --asar --overwrite --out=build --version=${npm_package_devDependencies_electron} --platform=win32 --arch=ia32",
16-
"mac": "cross-env ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ electron-packager ./dist ${app_name} --asar --overwrite --out=build --version=${npm_package_devDependencies_electron} --platform=darwin --arch=x64 --icon=./dist/custom/icon.icns",
17-
"linux32": "cross-env ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ electron-packager ./dist ${app_name} --asar --overwrite --out=build --version=${npm_package_devDependencies_electron} --platform=linux --arch=ia32",
18-
"linux64": "cross-env ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ electron-packager ./dist ${app_name} --asar --overwrite --out=build --version=${npm_package_devDependencies_electron} --platform=linux --arch=x64",
19-
"all": "cross-env ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ electron-packager ./dist ${app_name} --asar --overwrite --out=build --version=${npm_package_devDependencies_electron} --all --icon=./dist/custom/"
11+
"watch": "gulp watch --custom=$custom",
12+
"build": "gulp build --custom=$custom"
2013
},
2114
"engines": {
2215
"node": "7.9.0"

zip.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// require modules
2+
var fs = require('fs');
3+
var archiver = require('archiver');
4+
var pkg = require('./package');
5+
var sh = require('shelljs')
6+
var app_name = process.env.name || pkg.name;
7+
var app_version = process.env.version || pkg.version;
8+
9+
if(process.argv.length>3){
10+
var dest = process.argv[2].trim();
11+
var src = process.argv[3].trim();
12+
zip(src+'**/*', dest)
13+
// var fileName='';
14+
// sh.mkdir('-p',`releases/${app_version}`)
15+
// switch(type){
16+
// case 'mac': fileName = `${app_name}-darwin-x64`; break;
17+
// case 'win32': fileName = `${app_name}-win32-ia32`; break;
18+
// case 'win64': fileName= `${app_name}-win32-x64`; break;
19+
// case 'linux32': fileName = `${app_name}-linux-ia32`; break;
20+
// case 'linux64': fileName= `${app_name}-linux-x64`; break;
21+
// }
22+
// sh.rm('-rf',`releases/${app_version}/${fileName}`)
23+
// zip(`./build/${fileName}/**/*`, `./releases/${app_version}/${fileName}.zip`);
24+
}
25+
26+
27+
28+
/**
29+
* @param src 'subdir/*.txt'
30+
* @param dest 'a.zip'
31+
*/
32+
function zip(src, dest){
33+
return new Promise((a,b)=>{
34+
// create a file to stream archive data to.
35+
var output = fs.createWriteStream(dest);//__dirname + '/example.zip'
36+
var archive = archiver('zip', {
37+
zlib: { level: 9 } // Sets the compression level.
38+
});
39+
40+
// listen for all archive data to be written
41+
// 'close' event is fired only when a file descriptor is involved
42+
output.on('close', function() {
43+
console.log(archive.pointer() + ' total bytes');
44+
console.log('archiver has been finalized and the output file descriptor has closed.');
45+
a();
46+
});
47+
48+
// This event is fired when the data source is drained no matter what was the data source.
49+
// It is not part of this library but rather from the NodeJS Stream API.
50+
// @see: https://nodejs.org/api/stream.html#stream_event_end
51+
output.on('end', function() {
52+
console.log('Data has been drained');
53+
});
54+
55+
// good practice to catch warnings (ie stat failures and other non-blocking errors)
56+
archive.on('warning', function(err) {
57+
if (err.code === 'ENOENT') {
58+
// log warning
59+
console.warning(err);
60+
} else {
61+
// throw error
62+
b(err)
63+
}
64+
});
65+
66+
// good practice to catch this error explicitly
67+
archive.on('error', function(err) {
68+
b(err);
69+
});
70+
71+
// pipe archive data to the file
72+
archive.pipe(output);
73+
74+
// append files from a glob pattern
75+
archive.glob(src, false);
76+
77+
// finalize the archive (ie we are done appending files but streams have to finish yet)
78+
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
79+
archive.finalize();
80+
});
81+
}

0 commit comments

Comments
 (0)