as-soon 0.0.9 → 0.0.11
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 +44 -23
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.ts +0 -0
- package/dist/cli.js +44 -23
- package/dist/cli.js.map +1 -1
- package/funding.json +5 -0
- package/package.json +1 -1
- package/src/cli.ts +50 -26
- 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,41 +95,62 @@ 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 = 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 {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
const parent = import_node_path.default.dirname(absolute_path);
|
|
139
|
+
if (!import_node_fs.default.existsSync(parent)) {
|
|
140
|
+
console.error(`cannot listen on folder who have no parent yet: ${absolute_path}`);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
let tmp_subscription = yield import_watcher.default.subscribe(parent, (err, events) => {
|
|
144
|
+
for (const event of events) {
|
|
145
|
+
if (event.type === "create" && import_node_path.default.normalize(event.path) === absolute_path) {
|
|
146
|
+
tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
|
|
147
|
+
tmp_subscription = void 0;
|
|
148
|
+
setTimeout((v) => {
|
|
149
|
+
listen(absolute_path, execute);
|
|
150
|
+
}, 500);
|
|
130
151
|
}
|
|
131
152
|
}
|
|
132
|
-
);
|
|
153
|
+
});
|
|
133
154
|
}
|
|
134
155
|
});
|
|
135
156
|
}
|
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 = fs.statSync(absolute_path).isDirectory();\n\t\tif (isDirectory) {\n\t\t\t// console.log(`listen for folder changes...`);\n\t\t\tsubscribe_folder(absolute_path, execute);\n\t\t} else {\n\t\t\t// console.log(`listen for file changes...`);\n\t\t\tsubscribe_folder(path.dirname(absolute_path), execute, absolute_path);\n\t\t}\n\t} else {\n\t\tconst parent = path.dirname(absolute_path);\n\t\tif (!fs.existsSync(parent)) {\n\t\t\tconsole.error(`cannot listen on folder who have no parent yet: ${absolute_path}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t\t// console.log(`${absolute_path} do not exist yet, listening on parent : ${parent}`);\n\t\tlet tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(parent, (err, events) => {\n\t\t\tfor (const event of events) {\n\t\t\t\tif (event.type === 'create' && path.normalize(event.path) === absolute_path) {\n\t\t\t\t\t// console.log(`${absolute_path} just got created, listening for it...`);\n\t\t\t\t\ttmp_subscription?.unsubscribe();\n\t\t\t\t\ttmp_subscription = undefined;\n\t\t\t\t\t// wrap in a timeout to ensure @parcel/watcher hook on the correct inode?\n\t\t\t\t\tsetTimeout((v) => {\n\t\t\t\t\t\tlisten(absolute_path, execute);\n\t\t\t\t\t}, 500);\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,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U,QAAQ,CAAC,KAAK,WAAW;AACtG,mBAAW,SAAS,QAAQ;AAC3B,cAAI,MAAM,SAAS,YAAY,iBAAAD,QAAK,UAAU,MAAM,IAAI,MAAM,eAAe;AAE5E,iEAAkB;AAClB,+BAAmB;AAEnB,uBAAW,CAAC,MAAM;AACjB,qBAAO,eAAe,OAAO;AAAA,YAC9B,GAAG,GAAG;AAAA,UACP;AAAA,QACD;AAAA,MACD,CAAC;AAAA,IACF;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,41 +55,62 @@ 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 = 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 {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
98
|
+
const parent = path.dirname(absolute_path);
|
|
99
|
+
if (!fs.existsSync(parent)) {
|
|
100
|
+
console.error(`cannot listen on folder who have no parent yet: ${absolute_path}`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
let tmp_subscription = yield watcher.subscribe(parent, (err, events) => {
|
|
104
|
+
for (const event of events) {
|
|
105
|
+
if (event.type === "create" && path.normalize(event.path) === absolute_path) {
|
|
106
|
+
tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
|
|
107
|
+
tmp_subscription = void 0;
|
|
108
|
+
setTimeout((v) => {
|
|
109
|
+
listen(absolute_path, execute);
|
|
110
|
+
}, 500);
|
|
90
111
|
}
|
|
91
112
|
}
|
|
92
|
-
);
|
|
113
|
+
});
|
|
93
114
|
}
|
|
94
115
|
});
|
|
95
116
|
}
|
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 = fs.statSync(absolute_path).isDirectory();\n\t\tif (isDirectory) {\n\t\t\t// console.log(`listen for folder changes...`);\n\t\t\tsubscribe_folder(absolute_path, execute);\n\t\t} else {\n\t\t\t// console.log(`listen for file changes...`);\n\t\t\tsubscribe_folder(path.dirname(absolute_path), execute, absolute_path);\n\t\t}\n\t} else {\n\t\tconst parent = path.dirname(absolute_path);\n\t\tif (!fs.existsSync(parent)) {\n\t\t\tconsole.error(`cannot listen on folder who have no parent yet: ${absolute_path}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t\t// console.log(`${absolute_path} do not exist yet, listening on parent : ${parent}`);\n\t\tlet tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(parent, (err, events) => {\n\t\t\tfor (const event of events) {\n\t\t\t\tif (event.type === 'create' && path.normalize(event.path) === absolute_path) {\n\t\t\t\t\t// console.log(`${absolute_path} just got created, listening for it...`);\n\t\t\t\t\ttmp_subscription?.unsubscribe();\n\t\t\t\t\ttmp_subscription = undefined;\n\t\t\t\t\t// wrap in a timeout to ensure @parcel/watcher hook on the correct inode?\n\t\t\t\t\tsetTimeout((v) => {\n\t\t\t\t\t\tlisten(absolute_path, execute);\n\t\t\t\t\t}, 500);\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;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SAAS;AAC7B,eAAO,QAAQ,OAAO;AAEtB,gBAAQ,IAAI,oBAAoB,MAAM,EAAE;AACxC,gBAAQ,IAAI,uCAAuC;AAAA,MACpD;AAAA,IACD,OAAO;AACN,YAAM,SAAS,KAAK,UAAU,QAAQ,IAAI,CAAC;AAC3C,cAAQ,IAAI,gCAAgC,MAAM,EAAE;AACpD,aAAO,QAAQ,OAAO;AAAA,IACvB;AAAA,EACD;AAAA;AACA,KAAK;","names":[]}
|
package/funding.json
ADDED
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -59,44 +59,68 @@ function _execute() {
|
|
|
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 = fs.statSync(absolute_path).isDirectory();
|
|
97
|
+
if (isDirectory) {
|
|
98
|
+
// console.log(`listen for folder changes...`);
|
|
99
|
+
subscribe_folder(absolute_path, execute);
|
|
100
|
+
} else {
|
|
101
|
+
// console.log(`listen for file changes...`);
|
|
102
|
+
subscribe_folder(path.dirname(absolute_path), execute, absolute_path);
|
|
103
|
+
}
|
|
82
104
|
} else {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
105
|
+
const parent = path.dirname(absolute_path);
|
|
106
|
+
if (!fs.existsSync(parent)) {
|
|
107
|
+
console.error(`cannot listen on folder who have no parent yet: ${absolute_path}`);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
// console.log(`${absolute_path} do not exist yet, listening on parent : ${parent}`);
|
|
111
|
+
let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(parent, (err, events) => {
|
|
112
|
+
for (const event of events) {
|
|
113
|
+
if (event.type === 'create' && path.normalize(event.path) === absolute_path) {
|
|
114
|
+
// console.log(`${absolute_path} just got created, listening for it...`);
|
|
115
|
+
tmp_subscription?.unsubscribe();
|
|
116
|
+
tmp_subscription = undefined;
|
|
117
|
+
// wrap in a timeout to ensure @parcel/watcher hook on the correct inode?
|
|
118
|
+
setTimeout((v) => {
|
|
119
|
+
listen(absolute_path, execute);
|
|
120
|
+
}, 500);
|
|
97
121
|
}
|
|
98
122
|
}
|
|
99
|
-
);
|
|
123
|
+
});
|
|
100
124
|
}
|
|
101
125
|
}
|
|
102
126
|
|
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":[]}
|