Skip to content

Commit a6b185d

Browse files
committed
feat: check log dir when feflow init.
1 parent c5f98b2 commit a6b185d

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

lib/core/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Feflow {
3434
this.rcPath = rcPath;
3535
this.pkgPath = pathFn.join(base, 'package.json');
3636
this.pluginDir = pathFn.join(base, 'node_modules') + sep;
37+
this.logDir = pathFn.join(base, 'logs');
3738

3839
this.config = utils.parseYaml(rcPath); // Read feflow local config.
3940

lib/core/initClient.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ class Client {
8787
}
8888
});
8989
}
90+
91+
initLogs() {
92+
const ctx = this.ctx;
93+
const {logDir, log} = ctx;
94+
return new Promise(function (resolve) {
95+
if (!fs.existsSync(logDir)) {
96+
fs.mkdirsSync(logDir);
97+
}
98+
log.debug('.feflow/logs 日志文件夹已经创建');
99+
resolve(ctx);
100+
});
101+
}
90102
}
91103

92104

@@ -96,6 +108,7 @@ module.exports = function (ctx) {
96108
return Promise.all([
97109
client.initHome(),
98110
client.initPkg(),
99-
client.initLocalRc()
111+
client.initLocalRc(),
112+
client.initLogs()
100113
]);
101114
};

lib/core/logger.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ const levelColors = {
2626
60: 'bgRed'
2727
};
2828

29-
const logDir = pathFn.join(osenv.home(), './.feflow/logs');
30-
3129
function ConsoleStream(env) {
3230
Writable.call(this, {objectMode: true});
3331

@@ -61,11 +59,8 @@ ConsoleStream.prototype._write = function (data, enc, callback) {
6159
} else {
6260
process.stdout.write(msg);
6361
}
64-
65-
if (!fs.existsSync(logDir)) {
66-
fs.mkdirsSync(logDir);
67-
}
68-
62+
63+
const logDir = pathFn.join(osenv.home(), './.feflow/logs');
6964
const today = formatDate('yyyy-MM-dd', new Date());
7065
const logPath = pathFn.join(logDir, `${today}.log`);
7166
fs.appendFileSync(logPath, msg);

0 commit comments

Comments
 (0)