as-soon 0.0.8 → 0.0.10
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/LICENSE +21 -0
- package/dist/cli.cjs +33 -15
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.ts +0 -0
- package/dist/cli.js +33 -15
- package/dist/cli.js.map +1 -1
- package/funding.json +5 -0
- package/package.json +1 -1
- package/src/cli.ts +34 -16
- package/dist/chunk-I7R4HAJ6.js +0 -25
- package/dist/chunk-I7R4HAJ6.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Ronan Sandford
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/cli.cjs
CHANGED
|
@@ -95,27 +95,47 @@ function _execute() {
|
|
|
95
95
|
}
|
|
96
96
|
console.log(`-------------------------------------`);
|
|
97
97
|
}
|
|
98
|
-
function
|
|
98
|
+
function subscribe_folder(absolute_path, execute, filename) {
|
|
99
99
|
return __async(this, null, function* () {
|
|
100
|
-
const p = import_node_path.default.relative(process.cwd(), absolute_path);
|
|
100
|
+
const p = import_node_path.default.relative(process.cwd(), absolute_path) || ".";
|
|
101
101
|
const subscription = yield import_watcher.default.subscribe(absolute_path, (err, events) => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
if (filename) {
|
|
103
|
+
for (const event of events) {
|
|
104
|
+
if (import_node_path.default.normalize(event.path) === filename) {
|
|
105
|
+
console.log(`"${import_node_path.default.basename(filename)}" changed under ${p}`);
|
|
106
|
+
execute();
|
|
107
|
+
} else if (event.type === "delete" && event.path === absolute_path) {
|
|
108
|
+
subscription.unsubscribe();
|
|
109
|
+
listen(filename, execute);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
console.log(`Files changed under ${p}`);
|
|
115
|
+
for (const event of events) {
|
|
116
|
+
if (event.type === "delete" && event.path === absolute_path) {
|
|
117
|
+
subscription.unsubscribe();
|
|
118
|
+
listen(absolute_path, execute);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
108
121
|
}
|
|
122
|
+
execute();
|
|
109
123
|
}
|
|
110
|
-
execute();
|
|
111
124
|
});
|
|
112
125
|
});
|
|
113
126
|
}
|
|
114
127
|
function listen(absolute_path, execute) {
|
|
115
128
|
return __async(this, null, function* () {
|
|
116
|
-
|
|
117
|
-
|
|
129
|
+
const exists = import_node_fs.default.existsSync(absolute_path);
|
|
130
|
+
if (exists) {
|
|
131
|
+
const isDirectory = exists && import_node_fs.default.statSync(absolute_path).isDirectory();
|
|
132
|
+
if (isDirectory) {
|
|
133
|
+
subscribe_folder(absolute_path, execute);
|
|
134
|
+
} else {
|
|
135
|
+
subscribe_folder(import_node_path.default.dirname(absolute_path), execute, absolute_path);
|
|
136
|
+
}
|
|
118
137
|
} else {
|
|
138
|
+
console.log(`${absolute_path} do not exist yet, listening on parent`);
|
|
119
139
|
let tmp_subscription = yield import_watcher.default.subscribe(
|
|
120
140
|
import_node_path.default.dirname(absolute_path),
|
|
121
141
|
(err, events) => {
|
|
@@ -124,7 +144,7 @@ function listen(absolute_path, execute) {
|
|
|
124
144
|
tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
|
|
125
145
|
tmp_subscription = void 0;
|
|
126
146
|
setTimeout((v) => {
|
|
127
|
-
|
|
147
|
+
listen(absolute_path, execute);
|
|
128
148
|
}, 500);
|
|
129
149
|
}
|
|
130
150
|
}
|
|
@@ -135,9 +155,7 @@ function listen(absolute_path, execute) {
|
|
|
135
155
|
}
|
|
136
156
|
function main() {
|
|
137
157
|
return __async(this, null, function* () {
|
|
138
|
-
const execute = (0, import_lodash.debounce)(_execute,
|
|
139
|
-
leading: true
|
|
140
|
-
});
|
|
158
|
+
const execute = (0, import_lodash.debounce)(_execute, 200);
|
|
141
159
|
execute();
|
|
142
160
|
if (options["w"]) {
|
|
143
161
|
const folders = options["w"].map((p) => import_node_path.default.normalize(import_node_path.default.join(process.cwd(), p)));
|
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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\nfunction _execute() {\n\ttry {\n\t\texecFileSync(commandToUse, commandArgs, {stdio: ['inherit', 'inherit', 'inherit']});\n\t} catch (err) {\n\t\tconsole.error('failed to execue', err);\n\t}\n\tconsole.log(`-------------------------------------`);\n}\n\n// let counter = 0;\nasync function
|
|
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\nfunction _execute() {\n\ttry {\n\t\texecFileSync(commandToUse, commandArgs, {stdio: ['inherit', 'inherit', 'inherit']});\n\t} catch (err) {\n\t\tconsole.error('failed to execue', err);\n\t}\n\tconsole.log(`-------------------------------------`);\n}\n\n// let counter = 0;\nasync function subscribe_folder(absolute_path: string, execute: () => void, filename?: string) {\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\tif (filename) {\n\t\t\tfor (const event of events) {\n\t\t\t\tif (path.normalize(event.path) === filename) {\n\t\t\t\t\tconsole.log(`\"${path.basename(filename)}\" changed under ${p}`);\n\t\t\t\t\texecute();\n\t\t\t\t} else if (event.type === 'delete' && event.path === absolute_path) {\n\t\t\t\t\tsubscription.unsubscribe();\n\t\t\t\t\tlisten(filename, execute);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconsole.log(`Files changed under ${p}`);\n\t\t\tfor (const event of events) {\n\t\t\t\tif (event.type === 'delete' && event.path === absolute_path) {\n\t\t\t\t\tsubscription.unsubscribe();\n\t\t\t\t\tlisten(absolute_path, execute);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\texecute();\n\t\t}\n\t});\n}\n\nasync function listen(absolute_path: string, execute: () => void) {\n\tconst exists = fs.existsSync(absolute_path);\n\n\tif (exists) {\n\t\tconst isDirectory = exists && fs.statSync(absolute_path).isDirectory();\n\t\tif (isDirectory) {\n\t\t\tsubscribe_folder(absolute_path, execute);\n\t\t} else {\n\t\t\tsubscribe_folder(path.dirname(absolute_path), execute, absolute_path);\n\t\t}\n\t} else {\n\t\tconsole.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\tlisten(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, 200);\n\texecute();\n\tif (options['w']) {\n\t\tconst folders = options['w'].map((p) => path.normalize(path.join(process.cwd(), p)));\n\t\tfor (const folder of folders) {\n\t\t\tlisten(folder, execute);\n\n\t\t\tconsole.log(`Now listening on ${folder}`);\n\t\t\tconsole.log(`-------------------------------------`);\n\t\t}\n\t} else {\n\t\tconst folder = path.normalize(process.cwd());\n\t\tconsole.log(`listening on current folder: ${folder}`);\n\t\tlisten(folder, execute);\n\t}\n}\nmain();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2BAA2B;AAC3B,qBAAyC;AACzC,uBAAiB;AACjB,qBAAe;AACf,oBAAuB;AACvB,mBAAsB;AAEtB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;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;AACjB,uBAAO,eAAe,OAAO;AAAA,cAC9B,GAAG,GAAG;AAAA,YACP;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA;AAEA,SAAe,OAAO;AAAA;AACrB,UAAM,cAAU,wBAAS,UAAU,GAAG;AACtC,YAAQ;AACR,QAAI,QAAQ,GAAG,GAAG;AACjB,YAAM,UAAU,QAAQ,GAAG,EAAE,IAAI,CAAC,MAAM,iBAAAA,QAAK,UAAU,iBAAAA,QAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAC;AACnF,iBAAW,UAAU,SAAS;AAC7B,eAAO,QAAQ,OAAO;AAEtB,gBAAQ,IAAI,oBAAoB,MAAM,EAAE;AACxC,gBAAQ,IAAI,uCAAuC;AAAA,MACpD;AAAA,IACD,OAAO;AACN,YAAM,SAAS,iBAAAA,QAAK,UAAU,QAAQ,IAAI,CAAC;AAC3C,cAAQ,IAAI,gCAAgC,MAAM,EAAE;AACpD,aAAO,QAAQ,OAAO;AAAA,IACvB;AAAA,EACD;AAAA;AACA,KAAK;","names":["path","watcher","fs"]}
|
package/dist/cli.d.ts
CHANGED
|
File without changes
|
package/dist/cli.js
CHANGED
|
@@ -55,27 +55,47 @@ function _execute() {
|
|
|
55
55
|
}
|
|
56
56
|
console.log(`-------------------------------------`);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function subscribe_folder(absolute_path, execute, filename) {
|
|
59
59
|
return __async(this, null, function* () {
|
|
60
|
-
const p = path.relative(process.cwd(), absolute_path);
|
|
60
|
+
const p = path.relative(process.cwd(), absolute_path) || ".";
|
|
61
61
|
const subscription = yield watcher.subscribe(absolute_path, (err, events) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
if (filename) {
|
|
63
|
+
for (const event of events) {
|
|
64
|
+
if (path.normalize(event.path) === filename) {
|
|
65
|
+
console.log(`"${path.basename(filename)}" changed under ${p}`);
|
|
66
|
+
execute();
|
|
67
|
+
} else if (event.type === "delete" && event.path === absolute_path) {
|
|
68
|
+
subscription.unsubscribe();
|
|
69
|
+
listen(filename, execute);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
console.log(`Files changed under ${p}`);
|
|
75
|
+
for (const event of events) {
|
|
76
|
+
if (event.type === "delete" && event.path === absolute_path) {
|
|
77
|
+
subscription.unsubscribe();
|
|
78
|
+
listen(absolute_path, execute);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
68
81
|
}
|
|
82
|
+
execute();
|
|
69
83
|
}
|
|
70
|
-
execute();
|
|
71
84
|
});
|
|
72
85
|
});
|
|
73
86
|
}
|
|
74
87
|
function listen(absolute_path, execute) {
|
|
75
88
|
return __async(this, null, function* () {
|
|
76
|
-
|
|
77
|
-
|
|
89
|
+
const exists = fs.existsSync(absolute_path);
|
|
90
|
+
if (exists) {
|
|
91
|
+
const isDirectory = exists && fs.statSync(absolute_path).isDirectory();
|
|
92
|
+
if (isDirectory) {
|
|
93
|
+
subscribe_folder(absolute_path, execute);
|
|
94
|
+
} else {
|
|
95
|
+
subscribe_folder(path.dirname(absolute_path), execute, absolute_path);
|
|
96
|
+
}
|
|
78
97
|
} else {
|
|
98
|
+
console.log(`${absolute_path} do not exist yet, listening on parent`);
|
|
79
99
|
let tmp_subscription = yield watcher.subscribe(
|
|
80
100
|
path.dirname(absolute_path),
|
|
81
101
|
(err, events) => {
|
|
@@ -84,7 +104,7 @@ function listen(absolute_path, execute) {
|
|
|
84
104
|
tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
|
|
85
105
|
tmp_subscription = void 0;
|
|
86
106
|
setTimeout((v) => {
|
|
87
|
-
|
|
107
|
+
listen(absolute_path, execute);
|
|
88
108
|
}, 500);
|
|
89
109
|
}
|
|
90
110
|
}
|
|
@@ -95,9 +115,7 @@ function listen(absolute_path, execute) {
|
|
|
95
115
|
}
|
|
96
116
|
function main() {
|
|
97
117
|
return __async(this, null, function* () {
|
|
98
|
-
const execute = debounce(_execute,
|
|
99
|
-
leading: true
|
|
100
|
-
});
|
|
118
|
+
const execute = debounce(_execute, 200);
|
|
101
119
|
execute();
|
|
102
120
|
if (options["w"]) {
|
|
103
121
|
const folders = options["w"].map((p) => path.normalize(path.join(process.cwd(), p)));
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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\nfunction _execute() {\n\ttry {\n\t\texecFileSync(commandToUse, commandArgs, {stdio: ['inherit', 'inherit', 'inherit']});\n\t} catch (err) {\n\t\tconsole.error('failed to execue', err);\n\t}\n\tconsole.log(`-------------------------------------`);\n}\n\n// let counter = 0;\nasync function
|
|
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\nfunction _execute() {\n\ttry {\n\t\texecFileSync(commandToUse, commandArgs, {stdio: ['inherit', 'inherit', 'inherit']});\n\t} catch (err) {\n\t\tconsole.error('failed to execue', err);\n\t}\n\tconsole.log(`-------------------------------------`);\n}\n\n// let counter = 0;\nasync function subscribe_folder(absolute_path: string, execute: () => void, filename?: string) {\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\tif (filename) {\n\t\t\tfor (const event of events) {\n\t\t\t\tif (path.normalize(event.path) === filename) {\n\t\t\t\t\tconsole.log(`\"${path.basename(filename)}\" changed under ${p}`);\n\t\t\t\t\texecute();\n\t\t\t\t} else if (event.type === 'delete' && event.path === absolute_path) {\n\t\t\t\t\tsubscription.unsubscribe();\n\t\t\t\t\tlisten(filename, execute);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconsole.log(`Files changed under ${p}`);\n\t\t\tfor (const event of events) {\n\t\t\t\tif (event.type === 'delete' && event.path === absolute_path) {\n\t\t\t\t\tsubscription.unsubscribe();\n\t\t\t\t\tlisten(absolute_path, execute);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\texecute();\n\t\t}\n\t});\n}\n\nasync function listen(absolute_path: string, execute: () => void) {\n\tconst exists = fs.existsSync(absolute_path);\n\n\tif (exists) {\n\t\tconst isDirectory = exists && fs.statSync(absolute_path).isDirectory();\n\t\tif (isDirectory) {\n\t\t\tsubscribe_folder(absolute_path, execute);\n\t\t} else {\n\t\t\tsubscribe_folder(path.dirname(absolute_path), execute, absolute_path);\n\t\t}\n\t} else {\n\t\tconsole.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\tlisten(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, 200);\n\texecute();\n\tif (options['w']) {\n\t\tconst folders = options['w'].map((p) => path.normalize(path.join(process.cwd(), p)));\n\t\tfor (const folder of folders) {\n\t\t\tlisten(folder, execute);\n\n\t\t\tconsole.log(`Now listening on ${folder}`);\n\t\t\tconsole.log(`-------------------------------------`);\n\t\t}\n\t} else {\n\t\tconst folder = path.normalize(process.cwd());\n\t\tconsole.log(`listening on current folder: ${folder}`);\n\t\tlisten(folder, execute);\n\t}\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;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;AAA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|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// let counter = 0;
|
|
62
|
-
async function
|
|
62
|
+
async function subscribe_folder(absolute_path: string, execute: () => void, filename?: string) {
|
|
63
63
|
// const c = ++counter;
|
|
64
|
-
const p = path.relative(process.cwd(), absolute_path);
|
|
64
|
+
const p = path.relative(process.cwd(), absolute_path) || '.';
|
|
65
65
|
const subscription = await watcher.subscribe(absolute_path, (err, events) => {
|
|
66
66
|
// console.log(`Files changed under ${p} (${c})`);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
if (filename) {
|
|
68
|
+
for (const event of events) {
|
|
69
|
+
if (path.normalize(event.path) === filename) {
|
|
70
|
+
console.log(`"${path.basename(filename)}" changed under ${p}`);
|
|
71
|
+
execute();
|
|
72
|
+
} else if (event.type === 'delete' && event.path === absolute_path) {
|
|
73
|
+
subscription.unsubscribe();
|
|
74
|
+
listen(filename, execute);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
console.log(`Files changed under ${p}`);
|
|
80
|
+
for (const event of events) {
|
|
81
|
+
if (event.type === 'delete' && event.path === absolute_path) {
|
|
82
|
+
subscription.unsubscribe();
|
|
83
|
+
listen(absolute_path, execute);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
73
86
|
}
|
|
87
|
+
execute();
|
|
74
88
|
}
|
|
75
|
-
execute();
|
|
76
89
|
});
|
|
77
90
|
}
|
|
78
91
|
|
|
79
92
|
async function listen(absolute_path: string, execute: () => void) {
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
const exists = fs.existsSync(absolute_path);
|
|
94
|
+
|
|
95
|
+
if (exists) {
|
|
96
|
+
const isDirectory = exists && fs.statSync(absolute_path).isDirectory();
|
|
97
|
+
if (isDirectory) {
|
|
98
|
+
subscribe_folder(absolute_path, execute);
|
|
99
|
+
} else {
|
|
100
|
+
subscribe_folder(path.dirname(absolute_path), execute, absolute_path);
|
|
101
|
+
}
|
|
82
102
|
} else {
|
|
83
|
-
|
|
103
|
+
console.log(`${absolute_path} do not exist yet, listening on parent`);
|
|
84
104
|
let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(
|
|
85
105
|
path.dirname(absolute_path),
|
|
86
106
|
(err, events) => {
|
|
@@ -91,7 +111,7 @@ async function listen(absolute_path: string, execute: () => void) {
|
|
|
91
111
|
tmp_subscription = undefined;
|
|
92
112
|
// wrap in a timeout to ensure @parcel/watcher hook on the correct inode?
|
|
93
113
|
setTimeout((v) => {
|
|
94
|
-
|
|
114
|
+
listen(absolute_path, execute);
|
|
95
115
|
}, 500);
|
|
96
116
|
}
|
|
97
117
|
}
|
|
@@ -101,9 +121,7 @@ async function listen(absolute_path: string, execute: () => void) {
|
|
|
101
121
|
}
|
|
102
122
|
|
|
103
123
|
async function main() {
|
|
104
|
-
const execute = debounce(_execute,
|
|
105
|
-
leading: true,
|
|
106
|
-
});
|
|
124
|
+
const execute = debounce(_execute, 200);
|
|
107
125
|
execute();
|
|
108
126
|
if (options['w']) {
|
|
109
127
|
const folders = options['w'].map((p) => path.normalize(path.join(process.cwd(), p)));
|
package/dist/chunk-I7R4HAJ6.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
__async
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=chunk-I7R4HAJ6.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|