Comparing version
@@ -91,3 +91,3 @@ #!/usr/bin/env node | ||
if (exists) { | ||
const isDirectory = exists && fs.statSync(absolute_path).isDirectory(); | ||
const isDirectory = fs.statSync(absolute_path).isDirectory(); | ||
if (isDirectory) { | ||
@@ -99,17 +99,18 @@ subscribe_folder(absolute_path, execute); | ||
} else { | ||
console.log(`${absolute_path} do not exist yet, listening on parent`); | ||
let tmp_subscription = yield watcher.subscribe( | ||
path.dirname(absolute_path), | ||
(err, events) => { | ||
for (const event of events) { | ||
if (event.type === "create" && path.normalize(event.path) === absolute_path) { | ||
tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe(); | ||
tmp_subscription = void 0; | ||
setTimeout((v) => { | ||
listen(absolute_path, execute); | ||
}, 500); | ||
} | ||
const parent = path.dirname(absolute_path); | ||
if (!fs.existsSync(parent)) { | ||
console.error(`cannot listen on folder who have no parent yet: ${absolute_path}`); | ||
process.exit(1); | ||
} | ||
let tmp_subscription = yield watcher.subscribe(parent, (err, events) => { | ||
for (const event of events) { | ||
if (event.type === "create" && path.normalize(event.path) === absolute_path) { | ||
tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe(); | ||
tmp_subscription = void 0; | ||
setTimeout((v) => { | ||
listen(absolute_path, execute); | ||
}, 500); | ||
} | ||
} | ||
); | ||
}); | ||
} | ||
@@ -116,0 +117,0 @@ }); |
{ | ||
"name": "as-soon", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "watch and execute", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -96,26 +96,30 @@ #!/usr/bin/env node | ||
if (exists) { | ||
const isDirectory = exists && fs.statSync(absolute_path).isDirectory(); | ||
const isDirectory = fs.statSync(absolute_path).isDirectory(); | ||
if (isDirectory) { | ||
// console.log(`listen for folder changes...`); | ||
subscribe_folder(absolute_path, execute); | ||
} else { | ||
// console.log(`listen for file changes...`); | ||
subscribe_folder(path.dirname(absolute_path), execute, absolute_path); | ||
} | ||
} else { | ||
console.log(`${absolute_path} do not exist yet, listening on parent`); | ||
let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe( | ||
path.dirname(absolute_path), | ||
(err, events) => { | ||
for (const event of events) { | ||
if (event.type === 'create' && path.normalize(event.path) === absolute_path) { | ||
// console.log(`${absolute_path} just got created, listening for it...`); | ||
tmp_subscription?.unsubscribe(); | ||
tmp_subscription = undefined; | ||
// wrap in a timeout to ensure @parcel/watcher hook on the correct inode? | ||
setTimeout((v) => { | ||
listen(absolute_path, execute); | ||
}, 500); | ||
} | ||
const parent = path.dirname(absolute_path); | ||
if (!fs.existsSync(parent)) { | ||
console.error(`cannot listen on folder who have no parent yet: ${absolute_path}`); | ||
process.exit(1); | ||
} | ||
// console.log(`${absolute_path} do not exist yet, listening on parent : ${parent}`); | ||
let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(parent, (err, events) => { | ||
for (const event of events) { | ||
if (event.type === 'create' && path.normalize(event.path) === absolute_path) { | ||
// console.log(`${absolute_path} just got created, listening for it...`); | ||
tmp_subscription?.unsubscribe(); | ||
tmp_subscription = undefined; | ||
// wrap in a timeout to ensure @parcel/watcher hook on the correct inode? | ||
setTimeout((v) => { | ||
listen(absolute_path, execute); | ||
}, 500); | ||
} | ||
} | ||
); | ||
}); | ||
} | ||
@@ -122,0 +126,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
34757
3.02%525
1.16%