elrh-cosca 0.1.1 → 0.1.2

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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("path"),n=require("fs"),$=require("url"),S=require("readline");var f=typeof document<"u"?document.currentScript:null;const y=e=>e&&e.__esModule?e:{default:e},u=y(m),g=y(S);async function d(e){const t=g.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(l=>{t.question(e+" (y/N): ",a=>{t.close(),l(/^y(es)?$/i.test(a.trim()))})})}async function h(e,t,l=!1){if(l||await d(`This will create '${t}' file. Continue?`)){const r=$.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(r).href:f&&f.tagName.toUpperCase()==="SCRIPT"&&f.src||new URL("elrh-cosca.cjs",document.baseURI).href),i=u.default.dirname(r),s=u.default.resolve(i,e),o=u.default.resolve(process.cwd(),t);n.existsSync(s)||(console.error(`Template file not found at ${s}`),process.exit(1)),n.existsSync(o)&&(l||await d(`File '${t}' already exists. Overwrite?`)||(console.log("Aborted."),process.exit(0))),n.copyFileSync(s,o),console.log(`New file '${t}' successfully created.`)}else console.log(`Creation of '${t}' skipped.`)}async function U(e,t,l,a=!1){if(a||await d(`This will update '${e}' file. Continue?`)){const i=u.default.resolve(process.cwd(),e);if(!n.existsSync(i)){console.warn(`No '${e}' found in project root — skipping updates.`);return}const s=n.readFileSync(i,"utf8");let o;try{o=JSON.parse(s)}catch{console.error(`Could not parse '${e}' — skipping updates.`);return}o[t]=o[t]||{};let c=!1;for(const[p,w]of Object.entries(l))o[t][p]!==w&&(o[t][p]=w,c=!0);c?(n.writeFileSync(i,JSON.stringify(o,null,2)+`
2
- `,"utf8"),console.log(`'${e}' file updated.`)):console.log(`'${e}' file already up to date.`)}else console.log(`Updating '${e}' skipped.`)}async function x(e,t,l=!1){if(l||await d(`This will update '${e}' file. Continue?`)){const r=u.default.resolve(process.cwd(),e);if(!n.existsSync(r)){console.warn(`No '${e}' found in project root — skipping updates.`);return}const s=n.readFileSync(r,"utf8").split(/\r?\n/);let o=!1;for(const c of t)s.includes(c)||(s.push(c),o=!0);o?(n.writeFileSync(r,s.join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("path"),s=require("fs"),h=require("readline"),w=require("url");var c=typeof document<"u"?document.currentScript:null;const _=e=>e&&e.__esModule?e:{default:e},f=_(y),U=_(h);async function d(e){const t=U.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(n=>{t.question(e+" (y/N): ",a=>{t.close(),n(/^y(es)?$/i.test(a.trim()))})})}typeof __filename<"u"?__filename:w.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:c&&c.tagName.toUpperCase()==="SCRIPT"&&c.src||new URL("elrh-cosca.cjs",document.baseURI).href);const S=typeof __dirname<"u"?__dirname:y.dirname(w.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:c&&c.tagName.toUpperCase()==="SCRIPT"&&c.src||new URL("elrh-cosca.cjs",document.baseURI).href));async function $(e,t,n=!1){if(n||await d(`This will create '${t}' file. Continue?`)){const i=f.default.resolve(S,e),r=f.default.resolve(process.cwd(),t);s.existsSync(i)||(console.error(`Template file not found at ${i}`),process.exit(1)),s.existsSync(r)&&(n||await d(`File '${t}' already exists. Overwrite?`)||(console.log("Aborted."),process.exit(0))),s.copyFileSync(i,r),console.log(`New file '${t}' successfully created.`)}else console.log(`Creation of '${t}' skipped.`)}async function g(e,t,n,a=!1){if(a||await d(`This will update '${e}' file. Continue?`)){const r=f.default.resolve(process.cwd(),e);if(!s.existsSync(r)){console.warn(`No '${e}' found in project root — skipping updates.`);return}const l=s.readFileSync(r,"utf8");let o;try{o=JSON.parse(l)}catch{console.error(`Could not parse '${e}' — skipping updates.`);return}o[t]=o[t]||{};let u=!1;for(const[p,m]of Object.entries(n))o[t][p]!==m&&(o[t][p]=m,u=!0);u?(s.writeFileSync(r,JSON.stringify(o,null,2)+`
2
+ `,"utf8"),console.log(`'${e}' file updated.`)):console.log(`'${e}' file already up to date.`)}else console.log(`Updating '${e}' skipped.`)}async function R(e,t,n=!1){if(n||await d(`This will update '${e}' file. Continue?`)){const i=f.default.resolve(process.cwd(),e);if(!s.existsSync(i)){console.warn(`No '${e}' found in project root — skipping updates.`);return}const l=s.readFileSync(i,"utf8").split(/\r?\n/);let o=!1;for(const u of t)l.includes(u)||(l.push(u),o=!0);o?(s.writeFileSync(i,l.join(`
3
3
  `)+`
4
- `,"utf8"),console.log(`'${e}' file updated.`)):console.log(`'${e}' file already up to date.`)}else console.log(`Updating '${e}' skipped.`)}exports.createFileFromTemplate=h;exports.promptUser=d;exports.updateJsonFile=U;exports.updateTextFile=x;
4
+ `,"utf8"),console.log(`'${e}' file updated.`)):console.log(`'${e}' file already up to date.`)}else console.log(`Updating '${e}' skipped.`)}exports.createFileFromTemplate=$;exports.promptUser=d;exports.updateJsonFile=g;exports.updateTextFile=R;
@@ -1,77 +1,79 @@
1
- import a from "path";
2
- import { existsSync as d, copyFileSync as $, readFileSync as m, writeFileSync as w } from "fs";
1
+ import a, { dirname as $ } from "path";
2
+ import { existsSync as d, copyFileSync as g, readFileSync as m, writeFileSync as w } from "fs";
3
+ import x from "readline";
3
4
  import { fileURLToPath as y } from "url";
4
- import g from "readline";
5
5
  async function f(e) {
6
- const o = g.createInterface({
6
+ const o = x.createInterface({
7
7
  input: process.stdin,
8
8
  output: process.stdout
9
9
  });
10
- return new Promise((n) => {
11
- o.question(e + " (y/N): ", (c) => {
12
- o.close(), n(/^y(es)?$/i.test(c.trim()));
10
+ return new Promise((s) => {
11
+ o.question(e + " (y/N): ", (l) => {
12
+ o.close(), s(/^y(es)?$/i.test(l.trim()));
13
13
  });
14
14
  });
15
15
  }
16
- async function k(e, o, n = !1) {
17
- if (n || await f(
16
+ typeof __filename < "u" ? __filename : y(import.meta.url);
17
+ const _ = typeof __dirname < "u" ? __dirname : $(y(import.meta.url));
18
+ async function C(e, o, s = !1) {
19
+ if (s || await f(
18
20
  `This will create '${o}' file. Continue?`
19
21
  )) {
20
- const i = y(import.meta.url), r = a.dirname(i), s = a.resolve(r, e), t = a.resolve(process.cwd(), o);
21
- d(s) || (console.error(`Template file not found at ${s}`), process.exit(1)), d(t) && (n || await f(
22
+ const n = a.resolve(_, e), i = a.resolve(process.cwd(), o);
23
+ d(n) || (console.error(`Template file not found at ${n}`), process.exit(1)), d(i) && (s || await f(
22
24
  `File '${o}' already exists. Overwrite?`
23
- ) || (console.log("Aborted."), process.exit(0))), $(s, t), console.log(`New file '${o}' successfully created.`);
25
+ ) || (console.log("Aborted."), process.exit(0))), g(n, i), console.log(`New file '${o}' successfully created.`);
24
26
  } else
25
27
  console.log(`Creation of '${o}' skipped.`);
26
28
  }
27
- async function C(e, o, n, c = !1) {
28
- if (c || await f(
29
+ async function N(e, o, s, l = !1) {
30
+ if (l || await f(
29
31
  `This will update '${e}' file. Continue?`
30
32
  )) {
31
- const r = a.resolve(process.cwd(), e);
32
- if (!d(r)) {
33
+ const i = a.resolve(process.cwd(), e);
34
+ if (!d(i)) {
33
35
  console.warn(`No '${e}' found in project root — skipping updates.`);
34
36
  return;
35
37
  }
36
- const s = m(r, "utf8");
38
+ const r = m(i, "utf8");
37
39
  let t;
38
40
  try {
39
- t = JSON.parse(s);
41
+ t = JSON.parse(r);
40
42
  } catch {
41
43
  console.error(`Could not parse '${e}' — skipping updates.`);
42
44
  return;
43
45
  }
44
46
  t[o] = t[o] || {};
45
- let l = !1;
46
- for (const [u, p] of Object.entries(n))
47
- t[o][u] !== p && (t[o][u] = p, l = !0);
48
- l ? (w(r, JSON.stringify(t, null, 2) + `
47
+ let c = !1;
48
+ for (const [u, p] of Object.entries(s))
49
+ t[o][u] !== p && (t[o][u] = p, c = !0);
50
+ c ? (w(i, JSON.stringify(t, null, 2) + `
49
51
  `, "utf8"), console.log(`'${e}' file updated.`)) : console.log(`'${e}' file already up to date.`);
50
52
  } else
51
53
  console.log(`Updating '${e}' skipped.`);
52
54
  }
53
- async function N(e, o, n = !1) {
54
- if (n || await f(
55
+ async function O(e, o, s = !1) {
56
+ if (s || await f(
55
57
  `This will update '${e}' file. Continue?`
56
58
  )) {
57
- const i = a.resolve(process.cwd(), e);
58
- if (!d(i)) {
59
+ const n = a.resolve(process.cwd(), e);
60
+ if (!d(n)) {
59
61
  console.warn(`No '${e}' found in project root — skipping updates.`);
60
62
  return;
61
63
  }
62
- const s = m(i, "utf8").split(/\r?\n/);
64
+ const r = m(n, "utf8").split(/\r?\n/);
63
65
  let t = !1;
64
- for (const l of o)
65
- s.includes(l) || (s.push(l), t = !0);
66
- t ? (w(i, s.join(`
66
+ for (const c of o)
67
+ r.includes(c) || (r.push(c), t = !0);
68
+ t ? (w(n, r.join(`
67
69
  `) + `
68
70
  `, "utf8"), console.log(`'${e}' file updated.`)) : console.log(`'${e}' file already up to date.`);
69
71
  } else
70
72
  console.log(`Updating '${e}' skipped.`);
71
73
  }
72
74
  export {
73
- k as createFileFromTemplate,
75
+ C as createFileFromTemplate,
74
76
  f as promptUser,
75
- C as updateJsonFile,
76
- N as updateTextFile
77
+ N as updateJsonFile,
78
+ O as updateTextFile
77
79
  };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Normalized __filename that works in both ESM (.mjs) and CJS (.cjs).
3
+ * In CJS, __filename is available as a global variable.
4
+ * In MJS, import.meta.url is available instead.
5
+ */
6
+ export declare const module_file: string;
7
+ /**
8
+ * Normalized __dirname that works in both ESM (.mjs) and CJS (.cjs).
9
+ * In CJS, __filename is available as a global variable.
10
+ * In MJS, import.meta.url is available instead.
11
+ */
12
+ export declare const module_dir: string;
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "elrh-cosca",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
7
7
  ],
8
- "main": "./dist/elrh-cosca.cjs",
9
- "module": "./dist/elrh-cosca.mjs",
10
- "types": "./dist/types/index.d.ts",
11
8
  "exports": {
12
9
  ".": {
13
10
  "types": "./dist/types/index.d.ts",
14
- "import": "./dist/elrh-cosca.cjs",
15
- "require": "./dist/elrh-cosca.mjs"
11
+ "import": "./dist/elrh-cosca.mjs",
12
+ "require": "./dist/elrh-cosca.cjs",
13
+ "default": "./dist/elrh-cosca.mjs"
16
14
  }
17
15
  },
16
+ "main": "./dist/elrh-cosca.cjs",
17
+ "module": "./dist/elrh-cosca.mjs",
18
+ "types": "./dist/types/index.d.ts",
18
19
  "devDependencies": {
19
20
  "@types/node": "^24.3.0",
20
21
  "typescript": "^5.9.2",