as-soon 0.0.10 → 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/dist/cli.cjs +15 -14
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +15 -14
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +20 -16
package/dist/cli.cjs
CHANGED
|
@@ -128,28 +128,29 @@ function listen(absolute_path, execute) {
|
|
|
128
128
|
return __async(this, null, function* () {
|
|
129
129
|
const exists = import_node_fs.default.existsSync(absolute_path);
|
|
130
130
|
if (exists) {
|
|
131
|
-
const isDirectory =
|
|
131
|
+
const isDirectory = import_node_fs.default.statSync(absolute_path).isDirectory();
|
|
132
132
|
if (isDirectory) {
|
|
133
133
|
subscribe_folder(absolute_path, execute);
|
|
134
134
|
} else {
|
|
135
135
|
subscribe_folder(import_node_path.default.dirname(absolute_path), execute, absolute_path);
|
|
136
136
|
}
|
|
137
137
|
} else {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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);
|
|
150
151
|
}
|
|
151
152
|
}
|
|
152
|
-
);
|
|
153
|
+
});
|
|
153
154
|
}
|
|
154
155
|
});
|
|
155
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 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 =
|
|
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,uBA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AAQ,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.js
CHANGED
|
@@ -88,28 +88,29 @@ function listen(absolute_path, execute) {
|
|
|
88
88
|
return __async(this, null, function* () {
|
|
89
89
|
const exists = fs.existsSync(absolute_path);
|
|
90
90
|
if (exists) {
|
|
91
|
-
const isDirectory =
|
|
91
|
+
const isDirectory = fs.statSync(absolute_path).isDirectory();
|
|
92
92
|
if (isDirectory) {
|
|
93
93
|
subscribe_folder(absolute_path, execute);
|
|
94
94
|
} else {
|
|
95
95
|
subscribe_folder(path.dirname(absolute_path), execute, absolute_path);
|
|
96
96
|
}
|
|
97
97
|
} else {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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);
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
|
-
);
|
|
113
|
+
});
|
|
113
114
|
}
|
|
114
115
|
});
|
|
115
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 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 =
|
|
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;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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,MAAM,EAAE;AACpD,aAAO,QAAQ,OAAO;AAAA,IACvB;AAAA,EACD;AAAA;AACA,KAAK;","names":[]}
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -93,30 +93,34 @@ async function listen(absolute_path: string, execute: () => void) {
|
|
|
93
93
|
const exists = fs.existsSync(absolute_path);
|
|
94
94
|
|
|
95
95
|
if (exists) {
|
|
96
|
-
const isDirectory =
|
|
96
|
+
const isDirectory = fs.statSync(absolute_path).isDirectory();
|
|
97
97
|
if (isDirectory) {
|
|
98
|
+
// console.log(`listen for folder changes...`);
|
|
98
99
|
subscribe_folder(absolute_path, execute);
|
|
99
100
|
} else {
|
|
101
|
+
// console.log(`listen for file changes...`);
|
|
100
102
|
subscribe_folder(path.dirname(absolute_path), execute, absolute_path);
|
|
101
103
|
}
|
|
102
104
|
} else {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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);
|
|
117
121
|
}
|
|
118
122
|
}
|
|
119
|
-
);
|
|
123
|
+
});
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
126
|
|