-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
feifeipan
committed
Jul 12, 2017
1 parent
45c85a8
commit 69a4cc3
Showing
4 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
tinycode | ||
======== | ||
|
||
snipper | ||
snippet | ||
收集经常用到的代码片段,脑子笨记不住 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// eventProxy.js | ||
'use strict'; | ||
const eventProxy = { | ||
onObj: {}, | ||
oneObj: {}, | ||
on: function(key, fn) { | ||
if(this.onObj[key] === undefined) { | ||
this.onObj[key] = []; | ||
} | ||
|
||
this.onObj[key].push(fn); | ||
}, | ||
one: function(key, fn) { | ||
if(this.oneObj[key] === undefined) { | ||
this.oneObj[key] = []; | ||
} | ||
|
||
this.oneObj[key].push(fn); | ||
}, | ||
off: function(key) { | ||
this.onObj[key] = []; | ||
this.oneObj[key] = []; | ||
}, | ||
trigger: function() { | ||
let key, args; | ||
if(arguments.length == 0) { | ||
return false; | ||
} | ||
key = arguments[0]; | ||
args = [].concat(Array.prototype.slice.call(arguments, 1)); | ||
|
||
if(this.onObj[key] !== undefined | ||
&& this.onObj[key].length > 0) { | ||
for(let i in this.onObj[key]) { | ||
this.onObj[key][i].apply(null, args); | ||
} | ||
} | ||
if(this.oneObj[key] !== undefined | ||
&& this.oneObj[key].length > 0) { | ||
for(let i in this.oneObj[key]) { | ||
this.oneObj[key][i].apply(null, args); | ||
this.oneObj[key][i] = undefined; | ||
} | ||
this.oneObj[key] = []; | ||
} | ||
} | ||
}; | ||
|
||
export default eventProxy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** react 兄弟页面传递消息 **/ | ||
/** sender **/ | ||
eventProxy.trigger('updatelist', data); | ||
|
||
|
||
/** receiver **/ | ||
eventProxy.on('updatelist', (data) => { | ||
console.log("get triggered updatelist",data); | ||
this.initPkgList(data); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** 同步执行多条command **/ | ||
|
||
var child_process = window.require("child_process"); | ||
var process = window.require("process"); | ||
var spawn = child_process.spawn; | ||
import thunkify from "thunkify"; | ||
var path = window.require("path"); | ||
const ipc = window.require('electron').ipcRenderer | ||
|
||
var execCommand = thunkify(function(arg1, arg2, ondata_callback, callback) { | ||
try { | ||
console.log(arg1); | ||
console.log(arg2); | ||
var commandId = spawn(arg1, arg2); | ||
commandId.stdout.on('data', (data) => { | ||
console.log("data", `${data}`) | ||
ondata_callback(`${data}`); | ||
}); | ||
|
||
commandId.stderr.on('data', (data) => { | ||
console.log("error", `${data}`) | ||
callback(null, { | ||
"state": "error", | ||
"data": `${data}` | ||
}); | ||
}); | ||
|
||
commandId.on('close', (code) => { | ||
if (code != 0) { | ||
callback(null, { | ||
"state": "error", | ||
"data": "failed" | ||
}); | ||
} else { | ||
callback(null, { | ||
"state": "success", | ||
"data": "success finish" | ||
}); | ||
} | ||
|
||
}); | ||
} catch (e) { | ||
console.log(e.message); | ||
} | ||
|
||
}); | ||
|
||
|
||
|
||
var commitCommand = function*(config, ondata_callback) { | ||
|
||
config.execPath = ipc.sendSync('getBuildServicePath'); | ||
config.mavenPath = ipc.sendSync("getMavenPath"); | ||
console.log("mavenPath:", config.mavenPath); | ||
|
||
var commandList = [{ | ||
"command": config.execPath, | ||
"params": [ | ||
// "../node_modules/@ctrip/ares-builder/bin/ares-builder", | ||
"pom", | ||
"--cwd", | ||
config.homePath, //"/Users/feifeipan/Code/test/testares/testares4", | ||
"--build", | ||
config.buildPath, //"/Users/feifeipan/.ares/build", | ||
"--dev", | ||
"--spec", | ||
config.buildSpec, //"default" | ||
"--tranc", | ||
"ares.json" | ||
] | ||
}, { | ||
"command": config.mavenPath, | ||
"params": [ | ||
"clean", | ||
"package", | ||
"--settings", | ||
config.mavenSettingPath, //"/Users/feifeipan/.ares/config/maven-settings.xml" | ||
] | ||
}, { | ||
"command": config.mavenPath, | ||
"params": [ | ||
"deploy", | ||
"-P", | ||
"test", | ||
"--settings", | ||
config.mavenSettingPath, //"/Users/feifeipan/.ares/config/maven-settings.xml" | ||
] | ||
}, ]; | ||
|
||
|
||
console.log("commandList", commandList); | ||
|
||
var ret; | ||
var item = commandList[0]; | ||
process.chdir(config.homePath); | ||
ret = yield execCommand(commandList[0]["command"], commandList[0]["params"], ondata_callback); | ||
if (ret.state == "error") { | ||
return ret; | ||
} | ||
process.chdir(config.homePath); | ||
ret = yield execCommand(commandList[1]["command"], commandList[1]["params"], ondata_callback); | ||
if (ret.state == "error") { | ||
return ret; | ||
} | ||
process.chdir(config.homePath); | ||
ret = yield execCommand(commandList[2]["command"], commandList[2]["params"], ondata_callback); | ||
return ret; | ||
} | ||
|
||
/*** exec command function**/ | ||
co(myBuildService.commitCommand(config, (data) => { | ||
// var arr = data.match(/(\[\d\d\:\d\d\:\d\d\])([^\[]*)/g) | ||
this.setState({ | ||
"buildLog": this.state.buildLog.concat(data) | ||
}); | ||
})).then((data) => { | ||
console.log("co data:", data); | ||
}, (err) => { | ||
console.log("co error"); | ||
console.log(err.message); | ||
}); |