as-soon 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json.default +4 -0
- package/dist/cli.cjs +22 -11
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +22 -11
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +85 -72
package/dist/cli.cjs
CHANGED
|
@@ -85,6 +85,7 @@ if (!command) {
|
|
|
85
85
|
error(`please specify a command`);
|
|
86
86
|
}
|
|
87
87
|
var commandToUse = command;
|
|
88
|
+
console.log(`"${commandToUse} ${(commandArgs == null ? void 0 : commandArgs.join(" ")) || ""}"`);
|
|
88
89
|
(0, import_ldenv.loadEnv)({ mode: deploymentContext });
|
|
89
90
|
function _execute() {
|
|
90
91
|
return __async(this, null, function* () {
|
|
@@ -115,25 +116,35 @@ function listen(absolute_path, execute) {
|
|
|
115
116
|
if (import_node_fs.default.existsSync(absolute_path)) {
|
|
116
117
|
subscribe_target(absolute_path, execute);
|
|
117
118
|
} else {
|
|
118
|
-
let tmp_subscription = yield import_watcher.default.subscribe(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
let tmp_subscription = yield import_watcher.default.subscribe(
|
|
120
|
+
import_node_path.default.dirname(absolute_path),
|
|
121
|
+
(err, events) => {
|
|
122
|
+
for (const event of events) {
|
|
123
|
+
if (event.type === "create" && import_node_path.default.normalize(event.path) === absolute_path) {
|
|
124
|
+
tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
|
|
125
|
+
tmp_subscription = void 0;
|
|
126
|
+
setTimeout((v) => {
|
|
127
|
+
subscribe_target(absolute_path, execute);
|
|
128
|
+
}, 500);
|
|
129
|
+
}
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
|
-
|
|
132
|
+
);
|
|
129
133
|
}
|
|
130
134
|
});
|
|
131
135
|
}
|
|
132
136
|
function main() {
|
|
133
137
|
return __async(this, null, function* () {
|
|
134
138
|
const execute = (0, import_lodash.debounce)(_execute, 50);
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
if (options["w"]) {
|
|
140
|
+
console.log(`listening on: ${options["w"].join(", ")}`);
|
|
141
|
+
for (const p of options["w"]) {
|
|
142
|
+
const absolute_path = import_node_path.default.normalize(import_node_path.default.join(process.cwd(), p));
|
|
143
|
+
listen(absolute_path, execute);
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
console.log(`listening on current folder`);
|
|
147
|
+
const absolute_path = import_node_path.default.normalize(process.cwd());
|
|
137
148
|
listen(absolute_path, execute);
|
|
138
149
|
}
|
|
139
150
|
execute();
|
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport {execFileSync} from 'child_process';\nimport watcher, {AsyncSubscription} from '@parcel/watcher';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport {debounce} from 'lodash';\nimport {loadEnv} from 'ldenv';\n\nconst args = process.argv.slice(2);\n\nfunction error(msg: string) {\n\tconsole.error(msg);\n\tprocess.exit(1);\n}\n\nlet deploymentContext = 'localhost';\nlet argToConsume;\nlet command: string | undefined;\nlet commandArgs: string[] | undefined;\nconst options: {[key: string]: string[]} = {};\nfor (let i = 0; i < args.length; i++) {\n\tconst arg = args[i];\n\tif (arg.startsWith('--')) {\n\t\targToConsume = arg.substring(2);\n\t} else if (arg.startsWith('-')) {\n\t\targToConsume = arg.substring(1);\n\t} else {\n\t\tif (argToConsume) {\n\t\t\tif (options[argToConsume]) {\n\t\t\t\toptions[argToConsume].push(arg);\n\t\t\t} else {\n\t\t\t\toptions[argToConsume] = [arg];\n\t\t\t}\n\t\t\targToConsume = undefined;\n\t\t} else {\n\t\t\tcommand = arg;\n\t\t\tcommandArgs = args.slice(i + 1);\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nif (!command) {\n\terror(`please specify a command`);\n}\nconst commandToUse = command!;\n\nconsole.log(`\"${commandToUse} ${commandArgs?.join(' ') || ''}\"`);\n\nloadEnv({mode: deploymentContext});\n\nasync function _execute() {\n\ttry {\n\t\texecFileSync(commandToUse, commandArgs, {stdio: ['inherit', 'inherit', 'inherit']});\n\t} catch {}\n}\n\n// let counter = 0;\nasync function subscribe_target(absolute_path: string, execute: () => void) {\n\t// const c = ++counter;\n\tconst p = path.relative(process.cwd(), absolute_path);\n\tconst subscription = await watcher.subscribe(absolute_path, (err, events) => {\n\t\t// console.log(`Files changed under ${p} (${c})`);\n\t\tconsole.log(`Files changed under ${p}`);\n\t\tfor (const event of events) {\n\t\t\tif (event.type === 'delete' && event.path === absolute_path) {\n\t\t\t\tsubscription.unsubscribe();\n\t\t\t\tlisten(absolute_path, execute);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\texecute();\n\t});\n}\n\nasync function listen(absolute_path: string, execute: () => void) {\n\tif (fs.existsSync(absolute_path)) {\n\t\tsubscribe_target(absolute_path, execute);\n\t} else {\n\t\t// console.log(`${absolute_path} do not exist yet, listening on parent`)\n\t\tlet tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(\n\t\t\tpath.dirname(absolute_path),\n\t\t\t(err, events) => {\n\t\t\t\tfor (const event of events) {\n\t\t\t\t\tif (event.type === 'create' && path.normalize(event.path) === absolute_path) {\n\t\t\t\t\t\t// console.log(`${absolute_path} just got created, listening for it...`);\n\t\t\t\t\t\ttmp_subscription?.unsubscribe();\n\t\t\t\t\t\ttmp_subscription = undefined;\n\t\t\t\t\t\t// wrap in a timeout to ensure @parcel/watcher hook on the correct inode?\n\t\t\t\t\t\tsetTimeout((v) => {\n\t\t\t\t\t\t\tsubscribe_target(absolute_path, execute);\n\t\t\t\t\t\t}, 500);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n}\n\nasync function main() {\n\tconst execute = debounce(_execute, 50);\n\tif (options['w']) {\n\t\tconsole.log(`listening on: ${options['w'].join(', ')}`);\n\t\tfor (const p of options['w']) {\n\t\t\tconst absolute_path = path.normalize(path.join(process.cwd(), p));\n\t\t\tlisten(absolute_path, execute);\n\t\t}\n\t} else {\n\t\tconsole.log(`listening on current folder`);\n\t\tconst absolute_path = path.normalize(process.cwd());\n\t\tlisten(absolute_path, execute);\n\t}\n\n\texecute();\n}\nmain();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2BAA2B;AAC3B,qBAAyC;AACzC,uBAAiB;AACjB,qBAAe;AACf,oBAAuB;AACvB,mBAAsB;AAEtB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,SAAS,MAAM,KAAa;AAC3B,UAAQ,MAAM,GAAG;AACjB,UAAQ,KAAK,CAAC;AACf;AAEA,IAAI,oBAAoB;AACxB,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAM,UAAqC,CAAC;AAC5C,SAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACrC,QAAM,MAAM,KAAK,CAAC;AAClB,MAAI,IAAI,WAAW,IAAI,GAAG;AACzB,mBAAe,IAAI,UAAU,CAAC;AAAA,EAC/B,WAAW,IAAI,WAAW,GAAG,GAAG;AAC/B,mBAAe,IAAI,UAAU,CAAC;AAAA,EAC/B,OAAO;AACN,QAAI,cAAc;AACjB,UAAI,QAAQ,YAAY,GAAG;AAC1B,gBAAQ,YAAY,EAAE,KAAK,GAAG;AAAA,MAC/B,OAAO;AACN,gBAAQ,YAAY,IAAI,CAAC,GAAG;AAAA,MAC7B;AACA,qBAAe;AAAA,IAChB,OAAO;AACN,gBAAU;AACV,oBAAc,KAAK,MAAM,IAAI,CAAC;AAC9B;AAAA,IACD;AAAA,EACD;AACD;AAEA,IAAI,CAA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AAA,EACD;AAAA;AAEA,SAAe,OAAO;AAAA;AACrB,UAAM,cAAU,wBAAS,UAAU,EAAE;AACrC,QAAI,QAAQ,GAAG,GAAG;AACjB,cAAQ,IAAI,iBAAiB,QAAQ,GAAG,EAAE,KAAK,IAAI,GAAG;AACtD,iBAAW,KAAK,QAAQ,GAAG,GAAG;AAC7B,cAAM,gBAAgB,iBAAAA,QAAK,UAAU,iBAAAA,QAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,CAAC;AAChE,eAAO,eAAe,OAAO;AAAA,MAC9B;AAAA,IACD,OAAO;AACN,cAAQ,IAAI,6BAA6B;AACzC,YAAM,gBAAgB,iBAAAA,QAAK,UAAU,QAAQ,IAAI,CAAC;AAClD,aAAO,eAAe,OAAO;AAAA,IAC9B;AAEA,YAAQ;AAAA,EACT;AAAA;AACA,KAAK;","names":["path","watcher","fs"]}
|
package/dist/cli.js
CHANGED
|
@@ -45,6 +45,7 @@ if (!command) {
|
|
|
45
45
|
error(`please specify a command`);
|
|
46
46
|
}
|
|
47
47
|
var commandToUse = command;
|
|
48
|
+
console.log(`"${commandToUse} ${(commandArgs == null ? void 0 : commandArgs.join(" ")) || ""}"`);
|
|
48
49
|
loadEnv({ mode: deploymentContext });
|
|
49
50
|
function _execute() {
|
|
50
51
|
return __async(this, null, function* () {
|
|
@@ -75,25 +76,35 @@ function listen(absolute_path, execute) {
|
|
|
75
76
|
if (fs.existsSync(absolute_path)) {
|
|
76
77
|
subscribe_target(absolute_path, execute);
|
|
77
78
|
} else {
|
|
78
|
-
let tmp_subscription = yield watcher.subscribe(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
let tmp_subscription = yield watcher.subscribe(
|
|
80
|
+
path.dirname(absolute_path),
|
|
81
|
+
(err, events) => {
|
|
82
|
+
for (const event of events) {
|
|
83
|
+
if (event.type === "create" && path.normalize(event.path) === absolute_path) {
|
|
84
|
+
tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
|
|
85
|
+
tmp_subscription = void 0;
|
|
86
|
+
setTimeout((v) => {
|
|
87
|
+
subscribe_target(absolute_path, execute);
|
|
88
|
+
}, 500);
|
|
89
|
+
}
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
|
-
|
|
92
|
+
);
|
|
89
93
|
}
|
|
90
94
|
});
|
|
91
95
|
}
|
|
92
96
|
function main() {
|
|
93
97
|
return __async(this, null, function* () {
|
|
94
98
|
const execute = debounce(_execute, 50);
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
if (options["w"]) {
|
|
100
|
+
console.log(`listening on: ${options["w"].join(", ")}`);
|
|
101
|
+
for (const p of options["w"]) {
|
|
102
|
+
const absolute_path = path.normalize(path.join(process.cwd(), p));
|
|
103
|
+
listen(absolute_path, execute);
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
console.log(`listening on current folder`);
|
|
107
|
+
const absolute_path = path.normalize(process.cwd());
|
|
97
108
|
listen(absolute_path, execute);
|
|
98
109
|
}
|
|
99
110
|
execute();
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport {execFileSync} from 'child_process';\nimport watcher, {AsyncSubscription} from '@parcel/watcher';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport {debounce} from 'lodash';\nimport {loadEnv} from 'ldenv';\n\nconst args = process.argv.slice(2);\n\nfunction error(msg: string) {\n\tconsole.error(msg);\n\tprocess.exit(1);\n}\n\nlet deploymentContext = 'localhost';\nlet argToConsume;\nlet command: string | undefined;\nlet commandArgs: string[] | undefined;\nconst options: {[key: string]: string[]} = {};\nfor (let i = 0; i < args.length; i++) {\n\tconst arg = args[i];\n\tif (arg.startsWith('--')) {\n\t\targToConsume = arg.substring(2);\n\t} else if (arg.startsWith('-')) {\n\t\targToConsume = arg.substring(1);\n\t} else {\n\t\tif (argToConsume) {\n\t\t\tif (options[argToConsume]) {\n\t\t\t\toptions[argToConsume].push(arg);\n\t\t\t} else {\n\t\t\t\toptions[argToConsume] = [arg];\n\t\t\t}\n\t\t\targToConsume = undefined;\n\t\t} else {\n\t\t\tcommand = arg;\n\t\t\tcommandArgs = args.slice(i + 1);\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nif (!command) {\n\terror(`please specify a command`);\n}\nconst commandToUse = command!;\n\nconsole.log(`\"${commandToUse} ${commandArgs?.join(' ') || ''}\"`);\n\nloadEnv({mode: deploymentContext});\n\nasync function _execute() {\n\ttry {\n\t\texecFileSync(commandToUse, commandArgs, {stdio: ['inherit', 'inherit', 'inherit']});\n\t} catch {}\n}\n\n// let counter = 0;\nasync function subscribe_target(absolute_path: string, execute: () => void) {\n\t// const c = ++counter;\n\tconst p = path.relative(process.cwd(), absolute_path);\n\tconst subscription = await watcher.subscribe(absolute_path, (err, events) => {\n\t\t// console.log(`Files changed under ${p} (${c})`);\n\t\tconsole.log(`Files changed under ${p}`);\n\t\tfor (const event of events) {\n\t\t\tif (event.type === 'delete' && event.path === absolute_path) {\n\t\t\t\tsubscription.unsubscribe();\n\t\t\t\tlisten(absolute_path, execute);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\texecute();\n\t});\n}\n\nasync function listen(absolute_path: string, execute: () => void) {\n\tif (fs.existsSync(absolute_path)) {\n\t\tsubscribe_target(absolute_path, execute);\n\t} else {\n\t\t// console.log(`${absolute_path} do not exist yet, listening on parent`)\n\t\tlet tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(\n\t\t\tpath.dirname(absolute_path),\n\t\t\t(err, events) => {\n\t\t\t\tfor (const event of events) {\n\t\t\t\t\tif (event.type === 'create' && path.normalize(event.path) === absolute_path) {\n\t\t\t\t\t\t// console.log(`${absolute_path} just got created, listening for it...`);\n\t\t\t\t\t\ttmp_subscription?.unsubscribe();\n\t\t\t\t\t\ttmp_subscription = undefined;\n\t\t\t\t\t\t// wrap in a timeout to ensure @parcel/watcher hook on the correct inode?\n\t\t\t\t\t\tsetTimeout((v) => {\n\t\t\t\t\t\t\tsubscribe_target(absolute_path, execute);\n\t\t\t\t\t\t}, 500);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n}\n\nasync function main() {\n\tconst execute = debounce(_execute, 50);\n\tif (options['w']) {\n\t\tconsole.log(`listening on: ${options['w'].join(', ')}`);\n\t\tfor (const p of options['w']) {\n\t\t\tconst absolute_path = path.normalize(path.join(process.cwd(), p));\n\t\t\tlisten(absolute_path, execute);\n\t\t}\n\t} else {\n\t\tconsole.log(`listening on current folder`);\n\t\tconst absolute_path = path.normalize(process.cwd());\n\t\tlisten(absolute_path, execute);\n\t}\n\n\texecute();\n}\nmain();\n"],"mappings":";;;;;;AACA,SAAQ,oBAAmB;AAC3B,OAAO,aAAkC;AACzC,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAQ,gBAAe;AACvB,SAAQ,eAAc;AAEtB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,SAAS,MAAM,KAAa;AAC3B,UAAQ,MAAM,GAAG;AACjB,UAAQ,KAAK,CAAC;AACf;AAEA,IAAI,oBAAoB;AACxB,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAM,UAAqC,CAAC;AAC5C,SAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACrC,QAAM,MAAM,KAAK,CAAC;AAClB,MAAI,IAAI,WAAW,IAAI,GAAG;AACzB,mBAAe,IAAI,UAAU,CAAC;AAAA,EAC/B,WAAW,IAAI,WAAW,GAAG,GAAG;AAC/B,mBAAe,IAAI,UAAU,CAAC;AAAA,EAC/B,OAAO;AACN,QAAI,cAAc;AACjB,UAAI,QAAQ,YAAY,GAAG;AAC1B,gBAAQ,YAAY,EAAE,KAAK,GAAG;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B,iCAAmB;AAEnB,yBAAW,CAAC,MAAM;AACjB,iCAAiB,eAAe,OAAO;AAAA,cACxC,GAAG,GAAG;AAAA,YACP;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA;AAEA,SAAe,OAAO;AAAA;AACrB,UAAM,UAAU,SAAS,UAAU,EAAE;AACrC,QAAI,QAAQ,GAAG,GAAG;AACjB,cAAQ,IAAI,iBAAiB,QAAQ,GAAG,EAAE,KAAK,IAAI,GAAG;AACtD,iBAAW,KAAK,QAAQ,GAAG,GAAG;AAC7B,cAAM,gBAAgB,KAAK,UAAU,KAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,CAAC;AAChE,eAAO,eAAe,OAAO;AAAA,MAC9B;AAAA,IACD,OAAO;AACN,cAAQ,IAAI,6BAA6B;AACzC,YAAM,gBAAgB,KAAK,UAAU,QAAQ,IAAI,CAAC;AAClD,aAAO,eAAe,OAAO;AAAA,IAC9B;AAEA,YAAQ;AAAA,EACT;AAAA;AACA,KAAK;","names":[]}
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -1,103 +1,116 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import watcher, {
|
|
4
|
-
import path from
|
|
5
|
-
import fs from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import {execFileSync} from 'child_process';
|
|
3
|
+
import watcher, {AsyncSubscription} from '@parcel/watcher';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import {debounce} from 'lodash';
|
|
7
|
+
import {loadEnv} from 'ldenv';
|
|
8
8
|
|
|
9
9
|
const args = process.argv.slice(2);
|
|
10
10
|
|
|
11
11
|
function error(msg: string) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
console.error(msg);
|
|
13
|
+
process.exit(1);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
let deploymentContext =
|
|
16
|
+
let deploymentContext = 'localhost';
|
|
17
17
|
let argToConsume;
|
|
18
18
|
let command: string | undefined;
|
|
19
19
|
let commandArgs: string[] | undefined;
|
|
20
|
-
const options: {
|
|
20
|
+
const options: {[key: string]: string[]} = {};
|
|
21
21
|
for (let i = 0; i < args.length; i++) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
const arg = args[i];
|
|
23
|
+
if (arg.startsWith('--')) {
|
|
24
|
+
argToConsume = arg.substring(2);
|
|
25
|
+
} else if (arg.startsWith('-')) {
|
|
26
|
+
argToConsume = arg.substring(1);
|
|
27
|
+
} else {
|
|
28
|
+
if (argToConsume) {
|
|
29
|
+
if (options[argToConsume]) {
|
|
30
|
+
options[argToConsume].push(arg);
|
|
31
|
+
} else {
|
|
32
|
+
options[argToConsume] = [arg];
|
|
33
|
+
}
|
|
34
|
+
argToConsume = undefined;
|
|
35
|
+
} else {
|
|
36
|
+
command = arg;
|
|
37
|
+
commandArgs = args.slice(i + 1);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (!command) {
|
|
44
|
-
|
|
44
|
+
error(`please specify a command`);
|
|
45
45
|
}
|
|
46
46
|
const commandToUse = command!;
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
console.log(`"${commandToUse} ${commandArgs?.join(' ') || ''}"`);
|
|
49
|
+
|
|
50
|
+
loadEnv({mode: deploymentContext});
|
|
49
51
|
|
|
50
52
|
async function _execute() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
try {
|
|
54
|
+
execFileSync(commandToUse, commandArgs, {stdio: ['inherit', 'inherit', 'inherit']});
|
|
55
|
+
} catch {}
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
// let counter = 0;
|
|
57
59
|
async function subscribe_target(absolute_path: string, execute: () => void) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
// const c = ++counter;
|
|
61
|
+
const p = path.relative(process.cwd(), absolute_path);
|
|
62
|
+
const subscription = await watcher.subscribe(absolute_path, (err, events) => {
|
|
63
|
+
// console.log(`Files changed under ${p} (${c})`);
|
|
64
|
+
console.log(`Files changed under ${p}`);
|
|
65
|
+
for (const event of events) {
|
|
66
|
+
if (event.type === 'delete' && event.path === absolute_path) {
|
|
67
|
+
subscription.unsubscribe();
|
|
68
|
+
listen(absolute_path, execute);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
execute();
|
|
73
|
+
});
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
async function listen(absolute_path: string, execute: () => void) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
77
|
+
if (fs.existsSync(absolute_path)) {
|
|
78
|
+
subscribe_target(absolute_path, execute);
|
|
79
|
+
} else {
|
|
80
|
+
// console.log(`${absolute_path} do not exist yet, listening on parent`)
|
|
81
|
+
let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(
|
|
82
|
+
path.dirname(absolute_path),
|
|
83
|
+
(err, events) => {
|
|
84
|
+
for (const event of events) {
|
|
85
|
+
if (event.type === 'create' && path.normalize(event.path) === absolute_path) {
|
|
86
|
+
// console.log(`${absolute_path} just got created, listening for it...`);
|
|
87
|
+
tmp_subscription?.unsubscribe();
|
|
88
|
+
tmp_subscription = undefined;
|
|
89
|
+
// wrap in a timeout to ensure @parcel/watcher hook on the correct inode?
|
|
90
|
+
setTimeout((v) => {
|
|
91
|
+
subscribe_target(absolute_path, execute);
|
|
92
|
+
}, 500);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
93
98
|
}
|
|
94
99
|
|
|
95
100
|
async function main() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
const execute = debounce(_execute, 50);
|
|
102
|
+
if (options['w']) {
|
|
103
|
+
console.log(`listening on: ${options['w'].join(', ')}`);
|
|
104
|
+
for (const p of options['w']) {
|
|
105
|
+
const absolute_path = path.normalize(path.join(process.cwd(), p));
|
|
106
|
+
listen(absolute_path, execute);
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
console.log(`listening on current folder`);
|
|
110
|
+
const absolute_path = path.normalize(process.cwd());
|
|
111
|
+
listen(absolute_path, execute);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
execute();
|
|
102
115
|
}
|
|
103
116
|
main();
|