Skip to content

Commit 14f0c1b

Browse files
committed
feat: added deep file watcher to CLI
1 parent 66df383 commit 14f0c1b

File tree

7 files changed

+43
-13
lines changed

7 files changed

+43
-13
lines changed

misc/development/cli/simple/services/index.js

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { testFunc } = require('../testlib');
2+
3+
exports.name = 'test-service2';
4+
5+
exports.started = function () {
6+
this.timer = setInterval(() => {
7+
}, 2000);
8+
};
9+
10+
exports.actions = {
11+
hello (context) {
12+
return context.data;
13+
}
14+
};
15+
16+
exports.started = async function () {
17+
testFunc();
18+
};

misc/development/tracing.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const { createZipkinExporter } = require('../../packages/tracing-adapters/zipkin
55

66
const app = createBroker({
77
nodeId: 'trace',
8-
watchServices: true,
98
logger: {
109
enabled: true
1110
},

packages/core/cli/lib/commands/start/createWatchMiddlewares.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const path = require('path');
22
const { debounce } = require('@weave-js/utils');
33
const fs = require('fs');
4-
// const watch = require('../../utils/watchRecursive');
54

65
function createWatchMiddleware (weaveCli) {
76
return function watchMiddleware (runtime) {
@@ -83,7 +82,7 @@ function createWatchMiddleware (weaveCli) {
8382
return;
8483
}
8584

86-
if (filename.includes('node_modules') !== -1) {
85+
if (filename.includes('node_modules')) {
8786
if (cache.get(filename)) {
8887
return;
8988
}
@@ -104,9 +103,11 @@ function createWatchMiddleware (weaveCli) {
104103
const watchItem = getFileWatchItem(filename);
105104
watchItem.restartBroker = true;
106105
} else {
107-
const watchItem = getFileWatchItem(filename);
108-
watchItem.otherFiles.push(filename);
109-
watchItem.restartAllServices = true;
106+
if (parents) {
107+
const watchItem = getFileWatchItem(filename);
108+
watchItem.otherFiles.push(filename);
109+
watchItem.restartAllServices = true;
110+
}
110111
}
111112

112113
if (module.children && module.children.length > 0) {
@@ -222,7 +223,7 @@ function createWatchMiddleware (weaveCli) {
222223
},
223224
serviceStarted () {
224225
if (runtime.state.isStarted) {
225-
// debouncedWatchProjectFiles();
226+
debouncedWatchProjectFiles();
226227
}
227228
},
228229
stopped () {

packages/core/cli/lib/commands/start/loadServices.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path');
22
const fs = require('fs');
3+
const { isFunction } = require('@weave-js/utils');
34

45
exports.loadServices = (broker, param) => {
56
const servicePathsParams = param.split(',');
@@ -13,6 +14,18 @@ exports.loadServices = (broker, param) => {
1314
const isDir = fs.lstatSync(servicePath).isDirectory();
1415

1516
if (isDir) {
17+
// if there is an index file in the folder, we use this file as factory
18+
// Otherwise we load all service files from the folder.
19+
// if (fs.existsSync(path.join(servicePath, 'index.js'))) {
20+
// const serviceFactory = require(path.join(servicePath, 'index.js'));
21+
// if (isFunction(serviceFactory)) {
22+
// serviceFactory(broker);
23+
// return;
24+
// } else {
25+
// broker.log.debug(`An index.js file was found in the "${servicePath}" folder. Since it is not a service loader function, it was ignored.`);
26+
// }
27+
// }
28+
1629
broker.loadServices(servicePath);
1730
} else {
1831
broker.loadService(servicePath);

packages/core/cli/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ program
2828
program
2929
.command('create <type> <name>')
3030
.description('create a new project powered by vue-cli-service')
31-
.option('-t,--template <teplate>', 'Start broker with config file.')
31+
.option('-t,--template <template>', 'Start broker with config file.')
3232
.option('-s,--suffix <suffix>', 'Service file suffix (default: service)')
3333
.action((type, name, options) => {
3434
require('./commands/create').handler(type, name, options);

packages/core/cli/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
"author": {
1717
"name": "Kevin Ries",
1818
"company": "Fachwerk Software",
19-
"email": "kevin.ries@fachwerk.io",
20-
"url": "https://weave-js.com"
19+
"email": "kevin.ries@fachwerk.io"
2120
},
2221
"license": "MIT",
2322
"dependencies": {
2423
"@weave-js/core": "^0.11.1",
2524
"@weave-js/repl": "^0.11.1",
2625
"@weave-js/utils": "^0.10.1",
27-
"commander": "^8.3.0",
28-
"consolidate": "^0.16.0",
29-
"inquirer": "^8.2.0",
26+
"commander": "^9.1.0",
27+
"ejs": "^3.1.6",
28+
"inquirer": "^8.2.2",
3029
"kleur": "^4.1.4",
3130
"update-notifier": "^5.1.0"
3231
},

0 commit comments

Comments
 (0)