as-soon 0.0.3 → 0.0.5
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 +26 -12
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +26 -12
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +85 -70
package/dist/cli.cjs
CHANGED
|
@@ -85,10 +85,14 @@ if (!command) {
|
|
|
85
85
|
error(`please specify a command`);
|
|
86
86
|
}
|
|
87
87
|
var commandToUse = command;
|
|
88
|
+
console.log(`"${commandToUse}"`);
|
|
88
89
|
(0, import_ldenv.loadEnv)({ mode: deploymentContext });
|
|
89
90
|
function _execute() {
|
|
90
91
|
return __async(this, null, function* () {
|
|
91
|
-
|
|
92
|
+
try {
|
|
93
|
+
(0, import_child_process.execFileSync)(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
|
|
94
|
+
} catch (e) {
|
|
95
|
+
}
|
|
92
96
|
});
|
|
93
97
|
}
|
|
94
98
|
function subscribe_target(absolute_path, execute) {
|
|
@@ -112,25 +116,35 @@ function listen(absolute_path, execute) {
|
|
|
112
116
|
if (import_node_fs.default.existsSync(absolute_path)) {
|
|
113
117
|
subscribe_target(absolute_path, execute);
|
|
114
118
|
} else {
|
|
115
|
-
let tmp_subscription = yield import_watcher.default.subscribe(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
}
|
|
123
130
|
}
|
|
124
131
|
}
|
|
125
|
-
|
|
132
|
+
);
|
|
126
133
|
}
|
|
127
134
|
});
|
|
128
135
|
}
|
|
129
136
|
function main() {
|
|
130
137
|
return __async(this, null, function* () {
|
|
131
138
|
const execute = (0, import_lodash.debounce)(_execute, 50);
|
|
132
|
-
|
|
133
|
-
|
|
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());
|
|
134
148
|
listen(absolute_path, execute);
|
|
135
149
|
}
|
|
136
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}\"`);\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;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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,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,10 +45,14 @@ if (!command) {
|
|
|
45
45
|
error(`please specify a command`);
|
|
46
46
|
}
|
|
47
47
|
var commandToUse = command;
|
|
48
|
+
console.log(`"${commandToUse}"`);
|
|
48
49
|
loadEnv({ mode: deploymentContext });
|
|
49
50
|
function _execute() {
|
|
50
51
|
return __async(this, null, function* () {
|
|
51
|
-
|
|
52
|
+
try {
|
|
53
|
+
execFileSync(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
|
|
54
|
+
} catch (e) {
|
|
55
|
+
}
|
|
52
56
|
});
|
|
53
57
|
}
|
|
54
58
|
function subscribe_target(absolute_path, execute) {
|
|
@@ -72,25 +76,35 @@ function listen(absolute_path, execute) {
|
|
|
72
76
|
if (fs.existsSync(absolute_path)) {
|
|
73
77
|
subscribe_target(absolute_path, execute);
|
|
74
78
|
} else {
|
|
75
|
-
let tmp_subscription = yield watcher.subscribe(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
}
|
|
83
90
|
}
|
|
84
91
|
}
|
|
85
|
-
|
|
92
|
+
);
|
|
86
93
|
}
|
|
87
94
|
});
|
|
88
95
|
}
|
|
89
96
|
function main() {
|
|
90
97
|
return __async(this, null, function* () {
|
|
91
98
|
const execute = debounce(_execute, 50);
|
|
92
|
-
|
|
93
|
-
|
|
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());
|
|
94
108
|
listen(absolute_path, execute);
|
|
95
109
|
}
|
|
96
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}\"`);\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,MAA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;AAEN,UAAI,mBAAkD,MAAM,QAAQ;AAAA,QACnE,KAAK,QAAQ,aAAa;AAAA,QAC1B,CAAC,KAAK,WAAW;AAChB,qBAAW,SAAS,QAAQ;AAC3B,gBAAI,MAAM,SAAS,YAAY,KAAK,UAAU,MAAM,IAAI,MAAM,eAAe;AAE5E,mEAAkB;AAClB,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,101 +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}"`);
|
|
49
|
+
|
|
50
|
+
loadEnv({mode: deploymentContext});
|
|
49
51
|
|
|
50
52
|
async function _execute() {
|
|
51
|
-
|
|
53
|
+
try {
|
|
54
|
+
execFileSync(commandToUse, commandArgs, {stdio: ['inherit', 'inherit', 'inherit']});
|
|
55
|
+
} catch {}
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
// let counter = 0;
|
|
55
59
|
async function subscribe_target(absolute_path: string, execute: () => void) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
+
});
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
async function listen(absolute_path: string, execute: () => void) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
+
}
|
|
91
98
|
}
|
|
92
99
|
|
|
93
100
|
async function main() {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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();
|
|
100
115
|
}
|
|
101
116
|
main();
|