Skip to content

Commit 2993d84

Browse files
authored
Merge pull request #13 from aui/master
fix #11
2 parents f3a230f + ee6ab42 commit 2993d84

25 files changed

Lines changed: 257 additions & 189 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v1.0.4
2+
3+
1. 修复日志太多可能产生的溢出问题 [#11](https://github.com/huanleguang/ci-task-runner/issues/11)
4+
15
## v1.0.3
26

37
1. 修复子进程意外退出后的错误信息显示

README.ZH-CN.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,13 @@ ci-task-runner 缓存文件写入路径,用来保存上一次任务的信息
140140
141141
#### `program.options`
142142

143-
进程配置。参考:[child_process.exec](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)
143+
设置进程的选项
144144

145-
> `program.options` 中的 `timeout` 字段生效后会终止进程,并且抛出错误。这点和 `child_process.exec` 不一样,它只抛出错误。
145+
* `cwd` 当前子进程的工作目录
146+
* `env` 环境变量
147+
* `timeout` 超时时间
148+
* `uid` 设置进程的用户标识
149+
* `gid` 设置进程的组标识
146150

147151
#### 变量
148152

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,13 @@ Setting start command.
139139
140140
#### `program.options`
141141

142-
Progress configuration. Reference: [child_process.exec](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback).
142+
Progress configuration.
143143

144-
> The `timeout` field in `program.options` takes effect and terminates the process and throws an error. `child_process.exec` only throw error.
144+
* `cwd` Current working directory of the child process
145+
* `env` Environment key-value pairs
146+
* `timeout` Timeout
147+
* `uid` Sets the user identity of the process
148+
* `gid` Sets the group identity of the process
145149

146150
#### Variable
147151

lib/worker.js

Lines changed: 0 additions & 82 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ci-task-runner",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "this is a multiprocess building tasks scheduler",
55
"main": "src/index.js",
66
"bin": "bin/ci-task-runner",

src/parse.js renamed to src/create-tasks.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const path = require('path');
2-
const template = require('../lib/template');
2+
const template = require('./template');
33
const defaultsDeep = require('lodash.defaultsdeep');
44
const DEFAULT = require('./config/config.program.default.json');
55

@@ -41,10 +41,10 @@ class Task extends File {
4141
* @return {Task[]}
4242
*/
4343
module.exports = (options, context) => {
44-
let tasks = [];
44+
const tasks = [];
4545

4646

47-
let parseDependencie = lib => {
47+
const parseDependencie = lib => {
4848
if (typeof lib === 'string') {
4949
lib = {
5050
name: lib,
@@ -58,7 +58,7 @@ module.exports = (options, context) => {
5858
};
5959

6060

61-
let parseProgram = program => {
61+
const parseProgram = program => {
6262
if (typeof program === 'string') {
6363
program = {
6464
command: program,
@@ -71,14 +71,14 @@ module.exports = (options, context) => {
7171

7272

7373
// 设置字符串变量
74-
let setVariables = (target, variables) => {
75-
let type = typeof target;
74+
const setVariables = (target, variables) => {
75+
const type = typeof target;
7676
if (type === 'string') {
7777
return template(target, variables);
7878
} else if (Array.isArray(target)) {
7979
return target.map(target => setVariables(target, variables));
8080
} else if (type === 'object' && type !== null) {
81-
let object = {};
81+
const object = {};
8282
Object.keys(target).forEach(key => object[key] = setVariables(target[key], variables));
8383
return object;
8484
} else {
@@ -87,7 +87,7 @@ module.exports = (options, context) => {
8787
};
8888

8989

90-
let parseTask = (task, order) => {
90+
const parseTask = (task, order) => {
9191

9292
if (typeof task === 'string') {
9393
task = {
@@ -109,8 +109,8 @@ module.exports = (options, context) => {
109109
)
110110
};
111111

112-
let dependencies = task.dependencies.map(parseDependencie);
113-
let program = setVariables(task.program, {
112+
const dependencies = task.dependencies.map(parseDependencie);
113+
const program = setVariables(task.program, {
114114
taskName: task.name,
115115
taskPath: task.path,
116116
taskDirname: path.dirname(task.path)
@@ -126,7 +126,7 @@ module.exports = (options, context) => {
126126
});
127127
};
128128

129-
let each = (task, index) => {
129+
const each = (task, index) => {
130130
if (Array.isArray(task)) {
131131
task.forEach(task => each(task, index));
132132
} else {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const mkdirs = (dirname, callback) => {
2121
* @return {Promise}
2222
*/
2323
const writeFile = promiseify((...params) => {
24-
let file = params[0];
25-
let dirname = path.dirname(file);
24+
const file = params[0];
25+
const dirname = path.dirname(file);
2626
mkdirs(dirname, ()=> {
2727
fs.writeFile(...params);
2828
});

src/index.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
const path = require('path');
22
const findCacheDir = require('find-cache-dir');
3-
const fsp = require('../lib/fs-promise');
43
const defaultsDeep = require('lodash.defaultsdeep');
5-
const promiseTask = require('../lib/promise-task');
6-
const Repository = require('../lib/repository');
7-
const Loger = require('../lib/loger');
4+
const fsp = require('./fs-promise');
5+
const queue = require('./queue');
6+
const Repository = require('./repository');
7+
const Loger = require('./loger');
88
const DEFAULT = require('./config/config.default.json');
99
const CACHE_DEFAULT = require('./config/cache.default.json');
1010
const PACKAGE = require('../package.json');
11-
12-
const parse = require('./parse');
13-
const build = require('./build');
11+
const createTasks = require('./create-tasks');
12+
const runTasks = require('./run-tasks');
1413

1514

1615
/**
@@ -49,11 +48,11 @@ const taskRunner = (options = {}, context = process.cwd()) => {
4948

5049
const repository = new Repository(options.cache, options.repository, 'revision');
5150

52-
return promiseTask.serial([
51+
return queue.serial([
5352

5453

5554
// 将外部输入的配置转换成内部任务描述队列
56-
parse(options, context),
55+
createTasks(options, context),
5756

5857

5958
// 检查任务是否有变更
@@ -67,8 +66,8 @@ const taskRunner = (options = {}, context = process.cwd()) => {
6766

6867
]).then(([modCommit, ...libCommits]) => {
6968

70-
let modChanged = modCommit[0] !== modCommit[1];
71-
let libChanged = libCommits.filter(libCommit => libCommit[0] !== libCommit[1]).length !== 0;
69+
const modChanged = modCommit[0] !== modCommit[1];
70+
const libChanged = libCommits.filter(libCommit => libCommit[0] !== libCommit[1]).length !== 0;
7271
task.dirty = options.force || modChanged || libChanged;
7372

7473
cache.tasks[task.name] = {
@@ -102,7 +101,7 @@ const taskRunner = (options = {}, context = process.cwd()) => {
102101

103102
// 运行构建器
104103
tasks => {
105-
return build(tasks, options.parallel);
104+
return runTasks(tasks, options.parallel);
106105
},
107106

108107

@@ -113,7 +112,7 @@ const taskRunner = (options = {}, context = process.cwd()) => {
113112
.catch(() => defaultsDeep({}, CACHE_DEFAULT))
114113
.then(oldAssets => defaultsDeep(cache, oldAssets))
115114
.then(cache => {
116-
let json = JSON.stringify(cache, null, 2);
115+
const json = JSON.stringify(cache, null, 2);
117116
return fsp.writeFile(options.cache, json, 'utf8').then(() => cache);
118117
});
119118
},
@@ -126,7 +125,7 @@ const taskRunner = (options = {}, context = process.cwd()) => {
126125
}
127126

128127
]).then(results => {
129-
let timeEnd = Math.round((Date.now() - time) / 1000);
128+
const timeEnd = Math.round((Date.now() - time) / 1000);
130129
loger.log('░░', `${PACKAGE.name}:`, `${timeEnd}s`);
131130
return results[results.length - 1];
132131
});

lib/loger.js renamed to src/loger.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class StringStyle {
2020
Object.keys(TYPES).filter(key => {
2121
return this[key] !== undefined;
2222
}).forEach(key => {
23-
let value = this[key];
23+
const value = this[key];
2424
this[TYPES[key]](value);
2525
});
2626

@@ -41,7 +41,7 @@ class StringStyle {
4141
}
4242

4343
[textAlign](value) {
44-
let content = this.string.join('');
44+
const content = this.string.join('');
4545
let str;
4646
let length;
4747
switch (value) {
@@ -66,31 +66,31 @@ class StringStyle {
6666

6767
[color](value) {
6868
if (this.displayColor && StringStyle.colors[value]) {
69-
let style = StringStyle.colors[value];
69+
const style = StringStyle.colors[value];
7070
this.string.unshift(style[0]);
7171
this.string.push(style[1]);
7272
}
7373
}
7474

7575
[fontWeight](value) {
7676
if (this.displayColor && value === 'bold') {
77-
let style = ['\x1B[1m', '\x1B[22m'];
77+
const style = ['\x1B[1m', '\x1B[22m'];
7878
this.string.unshift(style[0]);
7979
this.string.push(style[1]);
8080
}
8181
}
8282

8383
[fontStyle](value) {
8484
if (this.displayColor && value === 'italic') {
85-
let style = ['\x1B[3m', '\x1B[23m'];
85+
const style = ['\x1B[3m', '\x1B[23m'];
8686
this.string.unshift(style[0]);
8787
this.string.push(style[1]);
8888
}
8989
}
9090

9191
[textDecoration](value) {
9292
if (this.displayColor && value === 'underline') {
93-
let style = ['\x1B[4m', '\x1B[24m'];
93+
const style = ['\x1B[4m', '\x1B[24m'];
9494
this.string.unshift(style[0]);
9595
this.string.push(style[1])
9696
}
@@ -136,8 +136,8 @@ class Loger {
136136

137137
setStyles(messages) {
138138
return messages.map((message, index) => {
139-
let stringStyle = new StringStyle(message, this.displayColor);
140-
let style = this.styles[index];
139+
const stringStyle = new StringStyle(message, this.displayColor);
140+
const style = this.styles[index];
141141

142142
Object.keys(style || {}).forEach(name => {
143143
stringStyle[name] = style[name];
File renamed without changes.

0 commit comments

Comments
 (0)