as-soon 0.0.2 → 0.0.3
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 +38 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +38 -4
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +42 -5
package/dist/cli.cjs
CHANGED
|
@@ -47,6 +47,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
47
47
|
var import_child_process = require("child_process");
|
|
48
48
|
var import_watcher = __toESM(require("@parcel/watcher"), 1);
|
|
49
49
|
var import_node_path = __toESM(require("path"), 1);
|
|
50
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
50
51
|
var import_lodash = require("lodash");
|
|
51
52
|
var import_ldenv = require("ldenv");
|
|
52
53
|
var args = process.argv.slice(2);
|
|
@@ -90,14 +91,47 @@ function _execute() {
|
|
|
90
91
|
(0, import_child_process.execFileSync)(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
|
|
91
92
|
});
|
|
92
93
|
}
|
|
94
|
+
function subscribe_target(absolute_path, execute) {
|
|
95
|
+
return __async(this, null, function* () {
|
|
96
|
+
const p = import_node_path.default.relative(process.cwd(), absolute_path);
|
|
97
|
+
const subscription = yield import_watcher.default.subscribe(absolute_path, (err, events) => {
|
|
98
|
+
console.log(`Files changed under ${p}`);
|
|
99
|
+
for (const event of events) {
|
|
100
|
+
if (event.type === "delete" && event.path === absolute_path) {
|
|
101
|
+
subscription.unsubscribe();
|
|
102
|
+
listen(absolute_path, execute);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
execute();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function listen(absolute_path, execute) {
|
|
111
|
+
return __async(this, null, function* () {
|
|
112
|
+
if (import_node_fs.default.existsSync(absolute_path)) {
|
|
113
|
+
subscribe_target(absolute_path, execute);
|
|
114
|
+
} else {
|
|
115
|
+
let tmp_subscription = yield import_watcher.default.subscribe(import_node_path.default.dirname(absolute_path), (err, events) => {
|
|
116
|
+
for (const event of events) {
|
|
117
|
+
if (event.type === "create" && import_node_path.default.normalize(event.path) === absolute_path) {
|
|
118
|
+
tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
|
|
119
|
+
tmp_subscription = void 0;
|
|
120
|
+
setTimeout((v) => {
|
|
121
|
+
subscribe_target(absolute_path, execute);
|
|
122
|
+
}, 500);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
93
129
|
function main() {
|
|
94
130
|
return __async(this, null, function* () {
|
|
95
131
|
const execute = (0, import_lodash.debounce)(_execute, 50);
|
|
96
132
|
for (const p of options["w"]) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
execute();
|
|
100
|
-
});
|
|
133
|
+
const absolute_path = import_node_path.default.normalize(import_node_path.default.join(process.cwd(), p));
|
|
134
|
+
listen(absolute_path, execute);
|
|
101
135
|
}
|
|
102
136
|
execute();
|
|
103
137
|
});
|
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 from \"@parcel/watcher\";\nimport path from \"node:path\";\nimport { debounce } from \"lodash\";\nimport { loadEnv } from \"ldenv\";\n\nconst args = process.argv.slice(2);\n\nfunction error(msg: string) {\n console.error(msg);\n process.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 const arg = args[i];\n if (arg.startsWith(\"--\")) {\n argToConsume = arg.substring(2);\n } else if (arg.startsWith(\"-\")) {\n argToConsume = arg.substring(1);\n } else {\n if (argToConsume) {\n if (options[argToConsume]) {\n options[argToConsume].push(arg);\n } else {\n options[argToConsume] = [arg];\n }\n argToConsume = undefined;\n } else {\n command = arg;\n commandArgs = args.slice(i + 1);\n break;\n }\n }\n}\n\nif (!command) {\n error(`please specify a command`);\n}\nconst commandToUse = command!;\n\nloadEnv({ mode: deploymentContext });\n\nasync function _execute() {\n execFileSync(commandToUse, commandArgs, { stdio: [\"inherit\", \"inherit\", \"inherit\"] });\n}\n\n
|
|
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 console.error(msg);\n process.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 const arg = args[i];\n if (arg.startsWith(\"--\")) {\n argToConsume = arg.substring(2);\n } else if (arg.startsWith(\"-\")) {\n argToConsume = arg.substring(1);\n } else {\n if (argToConsume) {\n if (options[argToConsume]) {\n options[argToConsume].push(arg);\n } else {\n options[argToConsume] = [arg];\n }\n argToConsume = undefined;\n } else {\n command = arg;\n commandArgs = args.slice(i + 1);\n break;\n }\n }\n}\n\nif (!command) {\n error(`please specify a command`);\n}\nconst commandToUse = command!;\n\nloadEnv({ mode: deploymentContext });\n\nasync function _execute() {\n execFileSync(commandToUse, commandArgs, { stdio: [\"inherit\", \"inherit\", \"inherit\"] });\n}\n\n// let counter = 0;\nasync function subscribe_target(absolute_path: string, execute: () => void) {\n // const c = ++counter;\n const p = path.relative(process.cwd(), absolute_path);\n const subscription = await watcher.subscribe(absolute_path, (err, events) => {\n // console.log(`Files changed under ${p} (${c})`);\n console.log(`Files changed under ${p}`);\n for (const event of events) {\n if (event.type === 'delete' && event.path === absolute_path) {\n subscription.unsubscribe();\n listen(absolute_path, execute);\n return;\n }\n }\n execute();\n });\n}\n\nasync function listen(absolute_path: string, execute: () => void) {\n if (fs.existsSync(absolute_path)) {\n subscribe_target(absolute_path, execute);\n } else {\n // console.log(`${absolute_path} do not exist yet, listening on parent`)\n let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(path.dirname(absolute_path), (err, events) => {\n for (const event of events) {\n if (event.type === 'create' && path.normalize(event.path) === absolute_path) {\n // console.log(`${absolute_path} just got created, listening for it...`);\n tmp_subscription?.unsubscribe();\n tmp_subscription = undefined;\n // wrap in a timeout to ensure @parcel/watcher hook on the correct inode?\n setTimeout(v => {\n subscribe_target(absolute_path, execute);\n }, 500);\n }\n }\n });\n }\n}\n\nasync function main() {\n const execute = debounce(_execute, 50);\n for (const p of options[\"w\"]) {\n const absolute_path = path.normalize(path.join(process.cwd(), p));\n listen(absolute_path, execute);\n }\n execute();\n}\nmain();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2BAA6B;AAC7B,qBAA2C;AAC3C,uBAAiB;AACjB,qBAAe;AACf,oBAAyB;AACzB,mBAAwB;AAExB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,SAAS,MAAM,KAAa;AAC1B,UAAQ,MAAM,GAAG;AACjB,UAAQ,KAAK,CAAC;AAChB;AAEA,IAAI,oBAAoB;AACxB,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAM,UAAuC,CAAC;AAC9C,SAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,QAAM,MAAM,KAAK,CAAC;AAClB,MAAI,IAAI,WAAW,IAAI,GAAG;AACxB,mBAAe,IAAI,UAAU,CAAC;AAAA,EAChC,WAAW,IAAI,WAAW,GAAG,GAAG;AAC9B,mBAAe,IAAI,UAAU,CAAC;AAAA,EAChC,OAAO;AACL,QAAI,cAAc;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AClB,+BAAmB;AAEnB,uBAAW,OAAK;AACd,+BAAiB,eAAe,OAAO;AAAA,YACzC,GAAG,GAAG;AAAA,UACR;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAEA,SAAe,OAAO;AAAA;AACpB,UAAM,cAAU,wBAAS,UAAU,EAAE;AACrC,eAAW,KAAK,QAAQ,GAAG,GAAG;AAC5B,YAAM,gBAAgB,iBAAAA,QAAK,UAAU,iBAAAA,QAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,CAAC;AAChE,aAAO,eAAe,OAAO;AAAA,IAC/B;AACA,YAAQ;AAAA,EACV;AAAA;AACA,KAAK;","names":["path","watcher","fs"]}
|
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import { execFileSync } from "child_process";
|
|
8
8
|
import watcher from "@parcel/watcher";
|
|
9
9
|
import path from "path";
|
|
10
|
+
import fs from "fs";
|
|
10
11
|
import { debounce } from "lodash";
|
|
11
12
|
import { loadEnv } from "ldenv";
|
|
12
13
|
var args = process.argv.slice(2);
|
|
@@ -50,14 +51,47 @@ function _execute() {
|
|
|
50
51
|
execFileSync(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
|
|
51
52
|
});
|
|
52
53
|
}
|
|
54
|
+
function subscribe_target(absolute_path, execute) {
|
|
55
|
+
return __async(this, null, function* () {
|
|
56
|
+
const p = path.relative(process.cwd(), absolute_path);
|
|
57
|
+
const subscription = yield watcher.subscribe(absolute_path, (err, events) => {
|
|
58
|
+
console.log(`Files changed under ${p}`);
|
|
59
|
+
for (const event of events) {
|
|
60
|
+
if (event.type === "delete" && event.path === absolute_path) {
|
|
61
|
+
subscription.unsubscribe();
|
|
62
|
+
listen(absolute_path, execute);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
execute();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function listen(absolute_path, execute) {
|
|
71
|
+
return __async(this, null, function* () {
|
|
72
|
+
if (fs.existsSync(absolute_path)) {
|
|
73
|
+
subscribe_target(absolute_path, execute);
|
|
74
|
+
} else {
|
|
75
|
+
let tmp_subscription = yield watcher.subscribe(path.dirname(absolute_path), (err, events) => {
|
|
76
|
+
for (const event of events) {
|
|
77
|
+
if (event.type === "create" && path.normalize(event.path) === absolute_path) {
|
|
78
|
+
tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
|
|
79
|
+
tmp_subscription = void 0;
|
|
80
|
+
setTimeout((v) => {
|
|
81
|
+
subscribe_target(absolute_path, execute);
|
|
82
|
+
}, 500);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
53
89
|
function main() {
|
|
54
90
|
return __async(this, null, function* () {
|
|
55
91
|
const execute = debounce(_execute, 50);
|
|
56
92
|
for (const p of options["w"]) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
execute();
|
|
60
|
-
});
|
|
93
|
+
const absolute_path = path.normalize(path.join(process.cwd(), p));
|
|
94
|
+
listen(absolute_path, execute);
|
|
61
95
|
}
|
|
62
96
|
execute();
|
|
63
97
|
});
|
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 from \"@parcel/watcher\";\nimport path from \"node:path\";\nimport { debounce } from \"lodash\";\nimport { loadEnv } from \"ldenv\";\n\nconst args = process.argv.slice(2);\n\nfunction error(msg: string) {\n console.error(msg);\n process.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 const arg = args[i];\n if (arg.startsWith(\"--\")) {\n argToConsume = arg.substring(2);\n } else if (arg.startsWith(\"-\")) {\n argToConsume = arg.substring(1);\n } else {\n if (argToConsume) {\n if (options[argToConsume]) {\n options[argToConsume].push(arg);\n } else {\n options[argToConsume] = [arg];\n }\n argToConsume = undefined;\n } else {\n command = arg;\n commandArgs = args.slice(i + 1);\n break;\n }\n }\n}\n\nif (!command) {\n error(`please specify a command`);\n}\nconst commandToUse = command!;\n\nloadEnv({ mode: deploymentContext });\n\nasync function _execute() {\n execFileSync(commandToUse, commandArgs, { stdio: [\"inherit\", \"inherit\", \"inherit\"] });\n}\n\n
|
|
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 console.error(msg);\n process.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 const arg = args[i];\n if (arg.startsWith(\"--\")) {\n argToConsume = arg.substring(2);\n } else if (arg.startsWith(\"-\")) {\n argToConsume = arg.substring(1);\n } else {\n if (argToConsume) {\n if (options[argToConsume]) {\n options[argToConsume].push(arg);\n } else {\n options[argToConsume] = [arg];\n }\n argToConsume = undefined;\n } else {\n command = arg;\n commandArgs = args.slice(i + 1);\n break;\n }\n }\n}\n\nif (!command) {\n error(`please specify a command`);\n}\nconst commandToUse = command!;\n\nloadEnv({ mode: deploymentContext });\n\nasync function _execute() {\n execFileSync(commandToUse, commandArgs, { stdio: [\"inherit\", \"inherit\", \"inherit\"] });\n}\n\n// let counter = 0;\nasync function subscribe_target(absolute_path: string, execute: () => void) {\n // const c = ++counter;\n const p = path.relative(process.cwd(), absolute_path);\n const subscription = await watcher.subscribe(absolute_path, (err, events) => {\n // console.log(`Files changed under ${p} (${c})`);\n console.log(`Files changed under ${p}`);\n for (const event of events) {\n if (event.type === 'delete' && event.path === absolute_path) {\n subscription.unsubscribe();\n listen(absolute_path, execute);\n return;\n }\n }\n execute();\n });\n}\n\nasync function listen(absolute_path: string, execute: () => void) {\n if (fs.existsSync(absolute_path)) {\n subscribe_target(absolute_path, execute);\n } else {\n // console.log(`${absolute_path} do not exist yet, listening on parent`)\n let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(path.dirname(absolute_path), (err, events) => {\n for (const event of events) {\n if (event.type === 'create' && path.normalize(event.path) === absolute_path) {\n // console.log(`${absolute_path} just got created, listening for it...`);\n tmp_subscription?.unsubscribe();\n tmp_subscription = undefined;\n // wrap in a timeout to ensure @parcel/watcher hook on the correct inode?\n setTimeout(v => {\n subscribe_target(absolute_path, execute);\n }, 500);\n }\n }\n });\n }\n}\n\nasync function main() {\n const execute = debounce(_execute, 50);\n for (const p of options[\"w\"]) {\n const absolute_path = path.normalize(path.join(process.cwd(), p));\n listen(absolute_path, execute);\n }\n execute();\n}\nmain();\n"],"mappings":";;;;;;AACA,SAAS,oBAAoB;AAC7B,OAAO,aAAoC;AAC3C,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAS,gBAAgB;AACzB,SAAS,eAAe;AAExB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,SAAS,MAAM,KAAa;AAC1B,UAAQ,MAAM,GAAG;AACjB,UAAQ,KAAK,CAAC;AAChB;AAEA,IAAI,oBAAoB;AACxB,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAM,UAAuC,CAAC;AAC9C,SAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,QAAM,MAAM,KAAK,CAAC;AAClB,MAAI,IAAI,WAAW,IAAI,GAAG;AACxB,mBAAe,IAAI,UAAU,CAAC;AAAA,EAChC,WAAW,IAAI,WAAW,GAAG,GAAG;AAC9B,mBAAe,IAAI,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AAmB;AAEnB,uBAAW,OAAK;AACd,+BAAiB,eAAe,OAAO;AAAA,YACzC,GAAG,GAAG;AAAA,UACR;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAEA,SAAe,OAAO;AAAA;AACpB,UAAM,UAAU,SAAS,UAAU,EAAE;AACrC,eAAW,KAAK,QAAQ,GAAG,GAAG;AAC5B,YAAM,gBAAgB,KAAK,UAAU,KAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,CAAC;AAChE,aAAO,eAAe,OAAO;AAAA,IAC/B;AACA,YAAQ;AAAA,EACV;AAAA;AACA,KAAK;","names":[]}
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execFileSync } from 'child_process';
|
|
3
|
-
import watcher from "@parcel/watcher";
|
|
3
|
+
import watcher, { AsyncSubscription } from "@parcel/watcher";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import fs from "node:fs";
|
|
5
6
|
import { debounce } from "lodash";
|
|
6
7
|
import { loadEnv } from "ldenv";
|
|
7
8
|
|
|
@@ -50,14 +51,50 @@ async function _execute() {
|
|
|
50
51
|
execFileSync(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
// let counter = 0;
|
|
55
|
+
async function subscribe_target(absolute_path: string, execute: () => void) {
|
|
56
|
+
// const c = ++counter;
|
|
57
|
+
const p = path.relative(process.cwd(), absolute_path);
|
|
58
|
+
const subscription = await watcher.subscribe(absolute_path, (err, events) => {
|
|
59
|
+
// console.log(`Files changed under ${p} (${c})`);
|
|
60
|
+
console.log(`Files changed under ${p}`);
|
|
61
|
+
for (const event of events) {
|
|
62
|
+
if (event.type === 'delete' && event.path === absolute_path) {
|
|
63
|
+
subscription.unsubscribe();
|
|
64
|
+
listen(absolute_path, execute);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
execute();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function listen(absolute_path: string, execute: () => void) {
|
|
73
|
+
if (fs.existsSync(absolute_path)) {
|
|
74
|
+
subscribe_target(absolute_path, execute);
|
|
75
|
+
} else {
|
|
76
|
+
// console.log(`${absolute_path} do not exist yet, listening on parent`)
|
|
77
|
+
let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(path.dirname(absolute_path), (err, events) => {
|
|
78
|
+
for (const event of events) {
|
|
79
|
+
if (event.type === 'create' && path.normalize(event.path) === absolute_path) {
|
|
80
|
+
// console.log(`${absolute_path} just got created, listening for it...`);
|
|
81
|
+
tmp_subscription?.unsubscribe();
|
|
82
|
+
tmp_subscription = undefined;
|
|
83
|
+
// wrap in a timeout to ensure @parcel/watcher hook on the correct inode?
|
|
84
|
+
setTimeout(v => {
|
|
85
|
+
subscribe_target(absolute_path, execute);
|
|
86
|
+
}, 500);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
53
92
|
|
|
54
93
|
async function main() {
|
|
55
94
|
const execute = debounce(_execute, 50);
|
|
56
95
|
for (const p of options["w"]) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
execute();
|
|
60
|
-
});
|
|
96
|
+
const absolute_path = path.normalize(path.join(process.cwd(), p));
|
|
97
|
+
listen(absolute_path, execute);
|
|
61
98
|
}
|
|
62
99
|
execute();
|
|
63
100
|
}
|