as-soon 0.0.3 → 0.0.5

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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
4
+ }
package/dist/cli.cjs CHANGED
@@ -85,10 +85,14 @@ if (!command) {
85
85
  error(`please specify a command`);
86
86
  }
87
87
  var commandToUse = command;
88
+ console.log(`"${commandToUse}"`);
88
89
  (0, import_ldenv.loadEnv)({ mode: deploymentContext });
89
90
  function _execute() {
90
91
  return __async(this, null, function* () {
91
- (0, import_child_process.execFileSync)(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
92
+ try {
93
+ (0, import_child_process.execFileSync)(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
94
+ } catch (e) {
95
+ }
92
96
  });
93
97
  }
94
98
  function subscribe_target(absolute_path, execute) {
@@ -112,25 +116,35 @@ function listen(absolute_path, execute) {
112
116
  if (import_node_fs.default.existsSync(absolute_path)) {
113
117
  subscribe_target(absolute_path, execute);
114
118
  } 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);
119
+ let tmp_subscription = yield import_watcher.default.subscribe(
120
+ import_node_path.default.dirname(absolute_path),
121
+ (err, events) => {
122
+ for (const event of events) {
123
+ if (event.type === "create" && import_node_path.default.normalize(event.path) === absolute_path) {
124
+ tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
125
+ tmp_subscription = void 0;
126
+ setTimeout((v) => {
127
+ subscribe_target(absolute_path, execute);
128
+ }, 500);
129
+ }
123
130
  }
124
131
  }
125
- });
132
+ );
126
133
  }
127
134
  });
128
135
  }
129
136
  function main() {
130
137
  return __async(this, null, function* () {
131
138
  const execute = (0, import_lodash.debounce)(_execute, 50);
132
- for (const p of options["w"]) {
133
- const absolute_path = import_node_path.default.normalize(import_node_path.default.join(process.cwd(), p));
139
+ if (options["w"]) {
140
+ console.log(`listening on: ${options["w"].join(", ")}`);
141
+ for (const p of options["w"]) {
142
+ const absolute_path = import_node_path.default.normalize(import_node_path.default.join(process.cwd(), p));
143
+ listen(absolute_path, execute);
144
+ }
145
+ } else {
146
+ console.log(`listening on current folder`);
147
+ const absolute_path = import_node_path.default.normalize(process.cwd());
134
148
  listen(absolute_path, execute);
135
149
  }
136
150
  execute();
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 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,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D,MAAM,eAAAD,QAAQ,UAAU,iBAAAD,QAAK,QAAQ,aAAa,GAAG,CAAC,KAAK,WAAW;AAC1H,mBAAW,SAAS,QAAQ;AAC1B,cAAI,MAAM,SAAS,YAAY,iBAAAA,QAAK,UAAU,MAAM,IAAI,MAAM,eAAe;AAE3E,iEAAkB;AAClB,+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"]}
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}\"`);\n\nloadEnv({mode: deploymentContext});\n\nasync function _execute() {\n\ttry {\n\t\texecFileSync(commandToUse, commandArgs, {stdio: ['inherit', 'inherit', 'inherit']});\n\t} catch {}\n}\n\n// let counter = 0;\nasync function subscribe_target(absolute_path: string, execute: () => void) {\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\tconsole.log(`Files changed under ${p}`);\n\t\tfor (const event of events) {\n\t\t\tif (event.type === 'delete' && event.path === absolute_path) {\n\t\t\t\tsubscription.unsubscribe();\n\t\t\t\tlisten(absolute_path, execute);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\texecute();\n\t});\n}\n\nasync function listen(absolute_path: string, execute: () => void) {\n\tif (fs.existsSync(absolute_path)) {\n\t\tsubscribe_target(absolute_path, execute);\n\t} else {\n\t\t// console.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\tsubscribe_target(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, 50);\n\tif (options['w']) {\n\t\tconsole.log(`listening on: ${options['w'].join(', ')}`);\n\t\tfor (const p of options['w']) {\n\t\t\tconst absolute_path = path.normalize(path.join(process.cwd(), p));\n\t\t\tlisten(absolute_path, execute);\n\t\t}\n\t} else {\n\t\tconsole.log(`listening on current folder`);\n\t\tconst absolute_path = path.normalize(process.cwd());\n\t\tlisten(absolute_path, execute);\n\t}\n\n\texecute();\n}\nmain();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2BAA2B;AAC3B,qBAAyC;AACzC,uBAAiB;AACjB,qBAAe;AACf,oBAAuB;AACvB,mBAAsB;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;AAAA,IACD;A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AAAA,EACD;AAAA;AAEA,SAAe,OAAO;AAAA;AACrB,UAAM,cAAU,wBAAS,UAAU,EAAE;AACrC,QAAI,QAAQ,GAAG,GAAG;AACjB,cAAQ,IAAI,iBAAiB,QAAQ,GAAG,EAAE,KAAK,IAAI,GAAG;AACtD,iBAAW,KAAK,QAAQ,GAAG,GAAG;AAC7B,cAAM,gBAAgB,iBAAAA,QAAK,UAAU,iBAAAA,QAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,CAAC;AAChE,eAAO,eAAe,OAAO;AAAA,MAC9B;AAAA,IACD,OAAO;AACN,cAAQ,IAAI,6BAA6B;AACzC,YAAM,gBAAgB,iBAAAA,QAAK,UAAU,QAAQ,IAAI,CAAC;AAClD,aAAO,eAAe,OAAO;AAAA,IAC9B;AAEA,YAAQ;AAAA,EACT;AAAA;AACA,KAAK;","names":["path","watcher","fs"]}
package/dist/cli.js CHANGED
@@ -45,10 +45,14 @@ if (!command) {
45
45
  error(`please specify a command`);
46
46
  }
47
47
  var commandToUse = command;
48
+ console.log(`"${commandToUse}"`);
48
49
  loadEnv({ mode: deploymentContext });
49
50
  function _execute() {
50
51
  return __async(this, null, function* () {
51
- execFileSync(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
52
+ try {
53
+ execFileSync(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
54
+ } catch (e) {
55
+ }
52
56
  });
53
57
  }
54
58
  function subscribe_target(absolute_path, execute) {
@@ -72,25 +76,35 @@ function listen(absolute_path, execute) {
72
76
  if (fs.existsSync(absolute_path)) {
73
77
  subscribe_target(absolute_path, execute);
74
78
  } 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);
79
+ let tmp_subscription = yield watcher.subscribe(
80
+ path.dirname(absolute_path),
81
+ (err, events) => {
82
+ for (const event of events) {
83
+ if (event.type === "create" && path.normalize(event.path) === absolute_path) {
84
+ tmp_subscription == null ? void 0 : tmp_subscription.unsubscribe();
85
+ tmp_subscription = void 0;
86
+ setTimeout((v) => {
87
+ subscribe_target(absolute_path, execute);
88
+ }, 500);
89
+ }
83
90
  }
84
91
  }
85
- });
92
+ );
86
93
  }
87
94
  });
88
95
  }
89
96
  function main() {
90
97
  return __async(this, null, function* () {
91
98
  const execute = debounce(_execute, 50);
92
- for (const p of options["w"]) {
93
- const absolute_path = path.normalize(path.join(process.cwd(), p));
99
+ if (options["w"]) {
100
+ console.log(`listening on: ${options["w"].join(", ")}`);
101
+ for (const p of options["w"]) {
102
+ const absolute_path = path.normalize(path.join(process.cwd(), p));
103
+ listen(absolute_path, execute);
104
+ }
105
+ } else {
106
+ console.log(`listening on current folder`);
107
+ const absolute_path = path.normalize(process.cwd());
94
108
  listen(absolute_path, execute);
95
109
  }
96
110
  execute();
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 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;AAC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V,CAAC;AAAA,EACH;AAAA;AAEA,SAAe,OAAO,eAAuB,SAAqB;AAAA;AAChE,QAAI,GAAG,WAAW,aAAa,GAAG;AAChC,uBAAiB,eAAe,OAAO;AAAA,IACzC,OAAO;AAEL,UAAI,mBAAkD,MAAM,QAAQ,UAAU,KAAK,QAAQ,aAAa,GAAG,CAAC,KAAK,WAAW;AAC1H,mBAAW,SAAS,QAAQ;AAC1B,cAAI,MAAM,SAAS,YAAY,KAAK,UAAU,MAAM,IAAI,MAAM,eAAe;AAE3E,iEAAkB;AAClB,+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,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":[]}
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}\"`);\n\nloadEnv({mode: deploymentContext});\n\nasync function _execute() {\n\ttry {\n\t\texecFileSync(commandToUse, commandArgs, {stdio: ['inherit', 'inherit', 'inherit']});\n\t} catch {}\n}\n\n// let counter = 0;\nasync function subscribe_target(absolute_path: string, execute: () => void) {\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\tconsole.log(`Files changed under ${p}`);\n\t\tfor (const event of events) {\n\t\t\tif (event.type === 'delete' && event.path === absolute_path) {\n\t\t\t\tsubscription.unsubscribe();\n\t\t\t\tlisten(absolute_path, execute);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\texecute();\n\t});\n}\n\nasync function listen(absolute_path: string, execute: () => void) {\n\tif (fs.existsSync(absolute_path)) {\n\t\tsubscribe_target(absolute_path, execute);\n\t} else {\n\t\t// console.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\tsubscribe_target(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, 50);\n\tif (options['w']) {\n\t\tconsole.log(`listening on: ${options['w'].join(', ')}`);\n\t\tfor (const p of options['w']) {\n\t\t\tconst absolute_path = path.normalize(path.join(process.cwd(), p));\n\t\t\tlisten(absolute_path, execute);\n\t\t}\n\t} else {\n\t\tconsole.log(`listening on current folder`);\n\t\tconst absolute_path = path.normalize(process.cwd());\n\t\tlisten(absolute_path, execute);\n\t}\n\n\texecute();\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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A,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA;AAEA,SAAe,OAAO;AAAA;AACrB,UAAM,UAAU,SAAS,UAAU,EAAE;AACrC,QAAI,QAAQ,GAAG,GAAG;AACjB,cAAQ,IAAI,iBAAiB,QAAQ,GAAG,EAAE,KAAK,IAAI,GAAG;AACtD,iBAAW,KAAK,QAAQ,GAAG,GAAG;AAC7B,cAAM,gBAAgB,KAAK,UAAU,KAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,CAAC;AAChE,eAAO,eAAe,OAAO;AAAA,MAC9B;AAAA,IACD,OAAO;AACN,cAAQ,IAAI,6BAA6B;AACzC,YAAM,gBAAgB,KAAK,UAAU,QAAQ,IAAI,CAAC;AAClD,aAAO,eAAe,OAAO;AAAA,IAC9B;AAEA,YAAQ;AAAA,EACT;AAAA;AACA,KAAK;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "as-soon",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "watch and execute",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/cli.ts CHANGED
@@ -1,101 +1,116 @@
1
1
  #!/usr/bin/env node
2
- import { execFileSync } from 'child_process';
3
- import watcher, { AsyncSubscription } from "@parcel/watcher";
4
- import path from "node:path";
5
- import fs from "node:fs";
6
- import { debounce } from "lodash";
7
- import { loadEnv } from "ldenv";
2
+ import {execFileSync} from 'child_process';
3
+ import watcher, {AsyncSubscription} from '@parcel/watcher';
4
+ import path from 'node:path';
5
+ import fs from 'node:fs';
6
+ import {debounce} from 'lodash';
7
+ import {loadEnv} from 'ldenv';
8
8
 
9
9
  const args = process.argv.slice(2);
10
10
 
11
11
  function error(msg: string) {
12
- console.error(msg);
13
- process.exit(1);
12
+ console.error(msg);
13
+ process.exit(1);
14
14
  }
15
15
 
16
- let deploymentContext = "localhost";
16
+ let deploymentContext = 'localhost';
17
17
  let argToConsume;
18
18
  let command: string | undefined;
19
19
  let commandArgs: string[] | undefined;
20
- const options: { [key: string]: string[] } = {};
20
+ const options: {[key: string]: string[]} = {};
21
21
  for (let i = 0; i < args.length; i++) {
22
- const arg = args[i];
23
- if (arg.startsWith("--")) {
24
- argToConsume = arg.substring(2);
25
- } else if (arg.startsWith("-")) {
26
- argToConsume = arg.substring(1);
27
- } else {
28
- if (argToConsume) {
29
- if (options[argToConsume]) {
30
- options[argToConsume].push(arg);
31
- } else {
32
- options[argToConsume] = [arg];
33
- }
34
- argToConsume = undefined;
35
- } else {
36
- command = arg;
37
- commandArgs = args.slice(i + 1);
38
- break;
39
- }
40
- }
22
+ const arg = args[i];
23
+ if (arg.startsWith('--')) {
24
+ argToConsume = arg.substring(2);
25
+ } else if (arg.startsWith('-')) {
26
+ argToConsume = arg.substring(1);
27
+ } else {
28
+ if (argToConsume) {
29
+ if (options[argToConsume]) {
30
+ options[argToConsume].push(arg);
31
+ } else {
32
+ options[argToConsume] = [arg];
33
+ }
34
+ argToConsume = undefined;
35
+ } else {
36
+ command = arg;
37
+ commandArgs = args.slice(i + 1);
38
+ break;
39
+ }
40
+ }
41
41
  }
42
42
 
43
43
  if (!command) {
44
- error(`please specify a command`);
44
+ error(`please specify a command`);
45
45
  }
46
46
  const commandToUse = command!;
47
47
 
48
- loadEnv({ mode: deploymentContext });
48
+ console.log(`"${commandToUse}"`);
49
+
50
+ loadEnv({mode: deploymentContext});
49
51
 
50
52
  async function _execute() {
51
- execFileSync(commandToUse, commandArgs, { stdio: ["inherit", "inherit", "inherit"] });
53
+ try {
54
+ execFileSync(commandToUse, commandArgs, {stdio: ['inherit', 'inherit', 'inherit']});
55
+ } catch {}
52
56
  }
53
57
 
54
58
  // let counter = 0;
55
59
  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
- });
60
+ // const c = ++counter;
61
+ const p = path.relative(process.cwd(), absolute_path);
62
+ const subscription = await watcher.subscribe(absolute_path, (err, events) => {
63
+ // console.log(`Files changed under ${p} (${c})`);
64
+ console.log(`Files changed under ${p}`);
65
+ for (const event of events) {
66
+ if (event.type === 'delete' && event.path === absolute_path) {
67
+ subscription.unsubscribe();
68
+ listen(absolute_path, execute);
69
+ return;
70
+ }
71
+ }
72
+ execute();
73
+ });
70
74
  }
71
75
 
72
76
  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
- }
77
+ if (fs.existsSync(absolute_path)) {
78
+ subscribe_target(absolute_path, execute);
79
+ } else {
80
+ // console.log(`${absolute_path} do not exist yet, listening on parent`)
81
+ let tmp_subscription: AsyncSubscription | undefined = await watcher.subscribe(
82
+ path.dirname(absolute_path),
83
+ (err, events) => {
84
+ for (const event of events) {
85
+ if (event.type === 'create' && path.normalize(event.path) === absolute_path) {
86
+ // console.log(`${absolute_path} just got created, listening for it...`);
87
+ tmp_subscription?.unsubscribe();
88
+ tmp_subscription = undefined;
89
+ // wrap in a timeout to ensure @parcel/watcher hook on the correct inode?
90
+ setTimeout((v) => {
91
+ subscribe_target(absolute_path, execute);
92
+ }, 500);
93
+ }
94
+ }
95
+ }
96
+ );
97
+ }
91
98
  }
92
99
 
93
100
  async function main() {
94
- const execute = debounce(_execute, 50);
95
- for (const p of options["w"]) {
96
- const absolute_path = path.normalize(path.join(process.cwd(), p));
97
- listen(absolute_path, execute);
98
- }
99
- execute();
101
+ const execute = debounce(_execute, 50);
102
+ if (options['w']) {
103
+ console.log(`listening on: ${options['w'].join(', ')}`);
104
+ for (const p of options['w']) {
105
+ const absolute_path = path.normalize(path.join(process.cwd(), p));
106
+ listen(absolute_path, execute);
107
+ }
108
+ } else {
109
+ console.log(`listening on current folder`);
110
+ const absolute_path = path.normalize(process.cwd());
111
+ listen(absolute_path, execute);
112
+ }
113
+
114
+ execute();
100
115
  }
101
116
  main();