Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
feifeipan committed Jul 12, 2017
1 parent 45c85a8 commit 69a4cc3
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tinycode
========

snipper
snippet
收集经常用到的代码片段,脑子笨记不住
49 changes: 49 additions & 0 deletions React_eventProxy/eventProxy.js
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;
10 changes: 10 additions & 0 deletions React_eventProxy/test.js
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);
});
121 changes: 121 additions & 0 deletions execCommandSync.js
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);
});

0 comments on commit 69a4cc3

Please sign in to comment.