Skip to content

Commit 225a0db

Browse files
committed
1. 修复合并JS bug
2. 增加ES6编译支持 3. 增加SVG支持 4. 服务器配置增加端口配置 5. 优化编译成功时的提示,通过 Notifications 向用户发送通知
1 parent 5640494 commit 225a0db

File tree

12 files changed

+564
-61
lines changed

12 files changed

+564
-61
lines changed

app.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@
167167
<input type="checkbox" name="supportChanged" id="supportChanged">
168168
<label for="supportChanged">开启 文件变动增量编译支持</label>
169169
</div>
170+
<div class="ui-checkbox">
171+
<input type="checkbox" name="SVGGracefulDegradation" id="SVGGracefulDegradation">
172+
<label for="SVGGracefulDegradation">开启 SVG 降级,兼容不支持 svg 的浏览器</label>
173+
</div>
170174
</div>
171175
</div>
172176

@@ -187,6 +191,9 @@
187191
<div class="ui-text ui-text_short">
188192
<input type="password" name="ftp-pass" placeholder="密码" value="">
189193
</div>
194+
<div class="ui-text ui-text_short">
195+
<input type="text" name="ftp-port" placeholder="端口" value="">
196+
</div>
190197
<div class="ui-text">
191198
<input type="text" name="ftp-remotePath" placeholder="远程路径" value="">
192199
</div>

main.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const app = electron.app;
55
const dialog = electron.dialog;
66
const ipc = electron.ipcMain;
77
const BrowserWindow = electron.BrowserWindow;
8+
const autoUpdater = electron.autoUpdater;
89
const path = require('path');
910

1011
// Keep a global reference of the window object, if you don't, the window will
@@ -45,6 +46,22 @@ function createWindow() {
4546
mainWindow = null;
4647
});
4748

49+
checkUpdate();
50+
51+
}
52+
53+
function checkUpdate(){
54+
let updateFeed = '';
55+
let appVersion = '1.3.2';
56+
autoUpdater.setFeedURL(updateFeed + '?v=' + appVersion);
57+
58+
autoUpdater.on('checking-for-update', function(){
59+
console.log('checking-for-update');
60+
});
61+
62+
autoUpdater.on('update-not-available', function(){
63+
console.log('update-not-available');
64+
});
4865
}
4966

5067

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"start": "electron main.js",
99
"build:linux32": "rimraf dist && electron-packager ./ WeFlow --platform=linux --arch=ia32 --icon=./assets/img/WeFlow.icns --overwrite --out ./dist/$npm_package_version --version=0.37.8 --ignore='(.github|.DS_Store)'",
1010
"build:linux64": "rimraf dist && electron-packager ./ WeFlow --platform=linux --arch=x64 --icon=./assets/img/WeFlow.icns --overwrite --out ./dist/$npm_package_version --version=0.37.8 --ignore='(.github|.DS_Store)'",
11-
"build:mac": "rimraf dist && electron-packager ./ WeFlow --platform=darwin --arch=x64 --icon=./assets/img/WeFlow.icns --overwrite --out ./dist/$npm_package_version --version=0.37.8 --ignore='(.github|.DS_Store)'",
11+
"build:mac": "rimraf dist && electron-packager ./ WeFlow --platform=darwin --appBundleId='com.tencent.weflow' --osxSign.identity='Developer ID Application: ZiLi Huang (UAEM649DN3)' --arch=x64 --icon=./assets/img/WeFlow.icns --overwrite --out ./dist/$npm_package_version --version=0.37.8 --ignore='(.github|.DS_Store)'",
1212
"build:win32": "rimraf dist && electron-packager ./ WeFlow --platform=win32 --arch=ia32 --icon=./assets/img/WeFlow.png --overwrite --out ./dist --version=0.37.8 --ignore=.github",
1313
"build:win64": "rimraf dist && electron-packager ./ WeFlow --platform=win32 --arch=x64 --icon=./assets/img/WeFlow.png --overwrite --out ./dist --version=0.37.8 --ignore=.github",
1414
"pack": "build --target dir",
@@ -45,7 +45,11 @@
4545
"dependencies": {
4646
"async": "^2.0.0-rc.3",
4747
"autoprefixer": "^6.3.3",
48+
"babel-core": "^6.24.1",
49+
"babel-preset-es2015": "^6.24.1",
50+
"babel-preset-stage-2": "^6.24.1",
4851
"browser-sync": "^2.13.0",
52+
"cheerio": "^0.22.0",
4953
"crypto-md5": "^1.0.0",
5054
"del": "^2.2.0",
5155
"extract-zip": "^1.5.0",
@@ -64,6 +68,9 @@
6468
"gulp-rev-delete-original": "^0.1.0",
6569
"gulp-sass": "^2.3.2",
6670
"gulp-sftp": "^0.1.5",
71+
"gulp-svg-inline": "^1.0.1",
72+
"gulp-svg-sprite": "^1.3.6",
73+
"gulp-svgmin": "^1.2.3",
6774
"gulp-tmtsprite": "^0.0.22",
6875
"gulp-uglify": "^1.5.3",
6976
"gulp-useref": "^3.1.2",
@@ -77,7 +84,9 @@
7784
"qiniu": "^6.1.11",
7885
"rc": "^1.1.6",
7986
"rd": "^0.0.2",
87+
"svg-to-png": "^3.1.2",
8088
"tmt-ejs-helper": "^0.0.1",
89+
"vinyl-ftp": "^0.6.0",
8190
"weflow-imagemin": "^0.0.3",
8291
"weflow-rev-all": "^0.0.1"
8392
}

src/_tasks/common/parseSVG.js

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/**
2+
* Created by doubleluo
3+
*/
4+
var gulp = require('gulp');
5+
var replace = require('gulp-replace');
6+
var through = require('through2');
7+
var fs = require('fs');
8+
var path = require('path');
9+
var File = require('vinyl');
10+
var util = require(path.join(__dirname, '../lib/util'));
11+
var cheerio = require('cheerio');
12+
13+
module.exports = function (options) {
14+
15+
var mkdirs = function(dirpath, callback) {
16+
fs.exists(dirpath, function(exists) {
17+
if(exists) {
18+
callback(dirpath);
19+
} else {
20+
mkdirs(path.dirname(dirpath), function(){
21+
fs.mkdir(dirpath, callback);
22+
});
23+
}
24+
});
25+
}
26+
27+
var mkdirone = false;
28+
var marchRegInline = /<img.*?src=['"].*?(\w+)\.svg\?i['"].*?>/gi;
29+
var marchRegSybmol = /<img.*?src=['"].*?(\w+)\.svg\?s['"].*?>/gi;
30+
var marchRegBase = /<img.*?src=['"].*?(\w+)\.svg['"].*?>/gi;
31+
var src = [],id,style,className,data,width,height,newcontent,$;
32+
33+
function getBase(){
34+
id = $.attr('id');
35+
style = $.attr('style');
36+
className = $.attr('class');
37+
data = fs.readFileSync(path.join(options.devPath+'/img', src[0])).toString();
38+
width = data.match(/<svg(.*?)width=["|'](.*?)(px)?["|']/)[2];
39+
height = data.match(/<svg(.*?)height=["|'](.*?)(px)?["|']/)[2];
40+
fileName = src[0].substr(src[0].lastIndexOf('/')+1,src[0].indexOf('.svg')-7);
41+
newcontent = [];
42+
}
43+
44+
function getAttr(){
45+
if(id){
46+
newcontent.push(' id="'+ id +'"');
47+
}
48+
if(style){
49+
newcontent.push(' style="'+ style +'"');
50+
}
51+
if(className){
52+
newcontent.push(' class="'+ className +'"');
53+
}
54+
}
55+
56+
function inline(contents){
57+
getAttr();
58+
data = data.replace('<svg','<svg width="'+ width +'" height="'+ height +'"'+newcontent.join(''));
59+
if(options.SVGGracefulDegradation){
60+
data = data.replace('>','><image width="'+ width +'" height="'+ height +'" src="'+src[0].replace('.svg','.png')+'" />');
61+
}
62+
return data;
63+
}
64+
function sybmol(contents){
65+
var newFile = path.join(options.devPath + '/symboltemp/', fileName);
66+
fs.writeFile(newFile, data, {encoding: 'utf8'});
67+
newcontent.push('<svg width="'+ width +'" height="'+ height +'" xmlns="http://www.w3.org/2000/svg"');
68+
getAttr();
69+
newcontent.push('>');
70+
if(options.SVGGracefulDegradation){
71+
newcontent.push('<image src="'+src[0].replace('.svg','.png')+'"',' />');
72+
}
73+
newcontent.push('<use xlink:href="'+ ((options && options.symbolBaseUrl)||'../symbolsvg/symbol.svg')+ '#' + fileName.replace('.svg','') +'"/>');
74+
newcontent.push('</svg>');
75+
return newcontent.join('');
76+
}
77+
function base(contents){
78+
newcontent.push('<svg width="'+ width +'" height="'+ height +'" xmlns="http://www.w3.org/2000/svg"');
79+
getAttr();
80+
newcontent.push('>');
81+
if(options.SVGGracefulDegradation){
82+
newcontent.push('<image width="'+ width +'" height="'+ height +'" src="'+src[0].replace('.svg','.png')+'" xlink:href="'+src[0]+'">');
83+
}else{
84+
newcontent.push('<image width="'+ width +'" height="'+ height +'" xlink:href="'+src[0]+'">');
85+
}
86+
newcontent.push('</svg>');
87+
return newcontent.join('');
88+
}
89+
90+
function run(regData,contents,marchReg){
91+
if(regData){
92+
for(var i = 0;i<regData.length;i++){
93+
var replaceData = '';
94+
$ = cheerio(regData[i]);
95+
src = $.attr('src').split('?');
96+
if(src[0].indexOf('.svg')>-1){
97+
getBase();
98+
if(src[1] == 'i'){
99+
replaceData = inline(contents);
100+
}else if(src[1] == 's'){
101+
replaceData = sybmol(contents);
102+
}else{
103+
replaceData = base(contents);
104+
}
105+
}
106+
107+
contents = contents.replace(regData[i], replaceData);
108+
109+
}
110+
}
111+
return contents;
112+
}
113+
114+
return through.obj(function (file, enc, cb) {
115+
116+
var _this = this;
117+
118+
119+
if (file.isNull()) {
120+
cb(null, file);
121+
} else {
122+
if (util.fileExist(file.path)) {
123+
var contents = file.contents.toString();
124+
var regData;
125+
if(options.onlyInline){
126+
regData = contents.match(marchRegInline);
127+
contents = run(regData,contents,marchRegInline);
128+
}else{
129+
if(!mkdirone){
130+
mkdirone = true;
131+
fs.exists(options.devPath +'/symboltemp', function(exists) {
132+
if(!exists){
133+
fs.mkdir(options.devPath +'/symboltemp');
134+
regData = contents.match(marchRegInline);
135+
contents = run(regData,contents,marchRegInline);
136+
regData = contents.match(marchRegSybmol);
137+
contents = run(regData,contents,marchRegSybmol);
138+
regData = contents.match(marchRegBase);
139+
contents = run(regData,contents,marchRegBase);
140+
}
141+
});
142+
}else{
143+
regData = contents.match(marchRegInline);
144+
contents = run(regData,contents,marchRegInline);
145+
regData = contents.match(marchRegSybmol);
146+
contents = run(regData,contents,marchRegSybmol);
147+
regData = contents.match(marchRegBase);
148+
contents = run(regData,contents,marchRegBase);
149+
}
150+
151+
}
152+
153+
154+
_this.push(new File({
155+
base: file.base,
156+
path: file.path,
157+
contents: new Buffer(contents)
158+
}));
159+
cb(null);
160+
} else {
161+
cb(null, file);
162+
}
163+
}
164+
});
165+
}

src/_tasks/common/svgToPng.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Created by doubleluo on 15/5/3.
3+
*/
4+
var gulp = require('gulp');
5+
var replace = require('gulp-replace');
6+
var through = require('through2');
7+
var fs = require('fs');
8+
var path = require('path');
9+
var util = require(path.join(__dirname, '../lib/util'));
10+
var File = require('vinyl');
11+
var svg_to_png = require('svg-to-png');
12+
13+
module.exports = function (options) {
14+
return through.obj(function (file, enc, cb) {
15+
16+
var _this = this;
17+
18+
19+
if (file.isNull()) {
20+
cb(null, file);
21+
} else {
22+
if (util.fileExist(file.path)) {
23+
svg_to_png.convert(file.path, file.path.substr(0,file.path.lastIndexOf('/')).replace('/src/','/dist/'));
24+
25+
_this.push(new File({
26+
base: file.base,
27+
path: file.path,
28+
contents: file.contents
29+
}));
30+
cb(null);
31+
} else {
32+
cb(null, file);
33+
}
34+
}
35+
});
36+
}

0 commit comments

Comments
 (0)