Skip to content

Commit

Permalink
优化build脚本,统一使用make
Browse files Browse the repository at this point in the history
  • Loading branch information
aleelock committed Nov 25, 2017
1 parent e204c34 commit 7467128
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 59 deletions.
44 changes: 25 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
# ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/
# ELECTRON_VERSION=1.6.5
# BUILD=ELECTRON_MIRROR=$(ELECTRON_MIRROR) electron-packager ./dist --asar --overwrite --out=build --version $(ELECTRON_VERSION)

VERSION=1.3.3
NAME=oss-browser
CUSTOM=./custom

GULP=node ./node_modules/gulp/bin/gulp.js
PKGER=node node_modules/electron-packager/cli.js
ZIP=node zip.js

ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/
ELECTRON_VERSION=1.6.5
BUILD=ELECTRON_MIRROR=$(ELECTRON_MIRROR) $(PKGER) ./dist $(NAME) --asar --overwrite --out=build --version $(ELECTRON_VERSION)


i:
cnpm i
clean:
npm run clean
find . -name .DS_Store | xargs rm -rf

rm -rf dist node_modules build releases node/crc64/cpp-addon/node_modules node/ossstore/node_modules
dev:
NODE_ENV=development electron .

run:
npm run dev
custom=$(CUSTOM) npm run dev

prod:
npm run prod
watch:
npm run watch
$(GULP) watch --custom=$(CUSTOM)
build:
npm run build
$(GULP) build --custom=$(CUSTOM)

win64:
app_name=$(NAME) npm run win64
$(BUILD) --platform=win32 --arch=x64
rm -rf releases/$(VERSION)/$(NAME)-win32-x64.zip && mkdir -p releases/$(VERSION)
cd build && zip ../releases/$(VERSION)/$(NAME)-win32-x64.zip -r $(NAME)-win32-x64
$(ZIP) releases/$(VERSION)/$(NAME)-win32-x64.zip build/$(NAME)-win32-x64/
win32:
app_name=$(NAME) npm run win32
$(BUILD) --platform=win32 --arch=ia32
rm -rf releases/$(VERSION)/$(NAME)-win32-ia32.zip && mkdir -p releases/$(VERSION)
cd build && zip ../releases/$(VERSION)/$(NAME)-win32-ia32.zip -r $(NAME)-win32-ia32
$(ZIP) releases/$(VERSION)/$(NAME)-win32-ia32.zip build/$(NAME)-win32-ia32/
linux64:
app_name=$(NAME) npm run linux64
$(BUILD) --platform=linux --arch=x64
rm -rf releases/$(VERSION)/$(NAME)-linux-x64.zip && mkdir -p releases/$(VERSION)
cd build && zip ../releases/$(VERSION)/$(NAME)-linux-x64.zip -r $(NAME)-linux-x64
$(ZIP) releases/$(VERSION)/$(NAME)-linux-x64.zip build/$(NAME)-linux-x64/
linux32:
app_name=$(NAME) npm run linux32
$(BUILD) --platform=linux --arch=ia32
rm -rf releases/$(VERSION)/$(NAME)-linux-ia32.zip && mkdir -p releases/$(VERSION)
cd build && zip ../releases/$(VERSION)/$(NAME)-linux-ia32.zip -r $(NAME)-linux-ia32
$(ZIP) releases/$(VERSION)/$(NAME)-linux-ia32.zip build/$(NAME)-linux-ia32/
mac:
app_name=$(NAME) npm run mac
$(BUILD) --platform=darwin --arch=x64 --icon=$(CUSTOM)/icon.icns
rm -rf releases/$(VERSION)/$(NAME)-darwin-x64.zip && mkdir -p releases/$(VERSION)
cd build && zip ../releases/$(VERSION)/$(NAME)-darwin-x64.zip -r $(NAME)-darwin-x64
$(ZIP) releases/$(VERSION)/$(NAME)-darwin-x64.zip build/$(NAME)-darwin-x64/
dmg:
rm build/$(NAME)-darwin-x64/LICENSE* build/$(NAME)-darwin-x64/version
ln -s /Applications/ build/$(NAME)-darwin-x64/Applications
Expand All @@ -54,6 +59,7 @@ dmg:
hdiutil create -size 250M -format UDZO -srcfolder build/$(NAME)-darwin-x64 releases/$(VERSION)/$(NAME).dmg

all:win32 win64 linux32 linux64 mac
@echo 'Done'


.PHONY:build
17 changes: 12 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,30 @@ cnpm 是 npm(node 包管理工具)的中国镜像,可以提高下载依赖
cnpm i -g windows-build-tools
```

还需要下载make.exe,放到 `C:\windows\` 目录下

[make.exe(64位版本)](http://luogc.oss-cn-hangzhou.aliyuncs.com/oss-browser-publish/windows-tools/64/make.exe)

[make.exe(32位版本)](http://luogc.oss-cn-hangzhou.aliyuncs.com/oss-browser-publish/windows-tools/32/make.exe)


### (4) 下载代码

```
git clone [email protected]:aliyun/oss-browser.git
```

安装依赖(请使用cnpm):
安装依赖:

```
cnpm i
make i
```


### (5) 运行

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

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

```
npm run build # build前端代码到dist目录
make build # build前端代码到dist目录
```

```
npm run win64 # 打包win64程序, 可选: mac, linux64
make win64 # 打包win64程序, 可选: mac, linux64,linux32,win32,win64,all.
```


Expand Down
59 changes: 33 additions & 26 deletions custom/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,40 @@ git clone {git地址}
cd oss-browser
```

### (4) 安装 make 命令

ubuntu 和 mac 默认有 make 命令。

windows 需要下载make.exe,放到 `C:\windows\` 目录下:

[make.exe(64位版本)](http://luogc.oss-cn-hangzhou.aliyuncs.com/oss-browser-publish/windows-tools/64/make.exe)

[make.exe(32位版本)](http://luogc.oss-cn-hangzhou.aliyuncs.com/oss-browser-publish/windows-tools/32/make.exe)

在centos 下,使用以下命令安装:

```
yum install make
```


## 2. 开始尝试启动

```
cnpm i # 安装 node 模块依赖
npm run build # 生成dist目录
make i # 安装 node 模块依赖
make build # 生成dist目录
```

启动界面:
```
npm run dev # 开发模式启动
make run # 开发模式启动
```

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


## 3. 自定义 custom 配置


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

Makefile有3个变量,可以替换,分别为:NAME,CUSTOM,VERSION.

* 假设你的应用名为: my-oss-browser
* 假设你的custom目录为: ~/Desktop/custom/

然后指定custom路径 build:
```
C=~/Desktop/custom/ npm run build
make build NAME=my-oss-browser CUSTOM=~/Desktop/custom/
```

开发模式启动:
```
C=~/Desktop/custom/ npm run dev #开发模式启动
```

## 4. build

* 如果在 windows系统下运行

```
npm run all
# npm run all app_name=oss-browser # 自定义app_name
make run NAME=my-oss-browser CUSTOM=~/Desktop/custom/
```
会在 build 下生成几个文件夹。即是安装文件。你可以手动zip一下,再发布。


* 如果是在 mac 下运行,

先修改Makefile中的 VERSION 和 NAME 变量,VERSION 需要和 custom/index.js中的version相同,NAME需要和appId相同。
## 4. build

然后运行:

```
make all NAME=oss-browser
make all NAME=my-oss-browser CUSTOM=~/Desktop/custom/
```

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



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

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



Expand Down
Binary file modified custom/icon.ico
Binary file not shown.
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@
"dev:run": "cross-env NODE_ENV=development electron .",
"postbuild": "node gen",
"prod": "cross-env NODE_ENV=production cd dist && electron .",
"clean": "rm -rf dist node_modules build releases node/crc64/cpp-addon/node_modules node/ossstore/node_modules",
"watch": "gulp watch --custom=${C}",
"build": "gulp build --custom=${C}",
"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",
"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",
"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",
"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",
"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",
"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/"
"watch": "gulp watch --custom=$custom",
"build": "gulp build --custom=$custom"
},
"engines": {
"node": "7.9.0"
Expand Down
81 changes: 81 additions & 0 deletions zip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// require modules
var fs = require('fs');
var archiver = require('archiver');
var pkg = require('./package');
var sh = require('shelljs')
var app_name = process.env.name || pkg.name;
var app_version = process.env.version || pkg.version;

if(process.argv.length>3){
var dest = process.argv[2].trim();
var src = process.argv[3].trim();
zip(src+'**/*', dest)
// var fileName='';
// sh.mkdir('-p',`releases/${app_version}`)
// switch(type){
// case 'mac': fileName = `${app_name}-darwin-x64`; break;
// case 'win32': fileName = `${app_name}-win32-ia32`; break;
// case 'win64': fileName= `${app_name}-win32-x64`; break;
// case 'linux32': fileName = `${app_name}-linux-ia32`; break;
// case 'linux64': fileName= `${app_name}-linux-x64`; break;
// }
// sh.rm('-rf',`releases/${app_version}/${fileName}`)
// zip(`./build/${fileName}/**/*`, `./releases/${app_version}/${fileName}.zip`);
}



/**
* @param src 'subdir/*.txt'
* @param dest 'a.zip'
*/
function zip(src, dest){
return new Promise((a,b)=>{
// create a file to stream archive data to.
var output = fs.createWriteStream(dest);//__dirname + '/example.zip'
var archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});

// listen for all archive data to be written
// 'close' event is fired only when a file descriptor is involved
output.on('close', function() {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
a();
});

// This event is fired when the data source is drained no matter what was the data source.
// It is not part of this library but rather from the NodeJS Stream API.
// @see: https://nodejs.org/api/stream.html#stream_event_end
output.on('end', function() {
console.log('Data has been drained');
});

// good practice to catch warnings (ie stat failures and other non-blocking errors)
archive.on('warning', function(err) {
if (err.code === 'ENOENT') {
// log warning
console.warning(err);
} else {
// throw error
b(err)
}
});

// good practice to catch this error explicitly
archive.on('error', function(err) {
b(err);
});

// pipe archive data to the file
archive.pipe(output);

// append files from a glob pattern
archive.glob(src, false);

// finalize the archive (ie we are done appending files but streams have to finish yet)
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
archive.finalize();
});
}

0 comments on commit 7467128

Please sign in to comment.