elrh-cosca 0.1.0 → 0.1.1

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 y=require("path"),o=require("fs"),$=require("readline"),w=e=>e&&e.__esModule?e:{default:e},d=w(y),g=w($);async function u(e){const t=g.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(n=>{t.question(e+" (y/N): ",c=>{t.close(),n(/^y(es)?$/i.test(c.trim()))})})}async function m(e,t,n=!1){if(n||await u(`This will create '${t}' file. Continue?`)){const l=d.default.resolve(process.cwd(),e),i=d.default.resolve(process.cwd(),t);o.existsSync(l)||(console.error(`Template file not found at ${l}`),process.exit(1)),o.existsSync(i)&&(n||await u(`File '${t}' already exists. Overwrite?`)||(console.log("Aborted."),process.exit(0))),o.copyFileSync(l,i),console.log(`New file '${t}' successfully created.`)}else console.log(`Creation of '${t}' skipped.`)}async function S(e,t,n,c=!1){if(c||await u(`This will update '${e}' file. Continue?`)){const i=d.default.resolve(process.cwd(),e);if(!o.existsSync(i)){console.warn(`No '${e}' found in project root — skipping updates.`);return}const r=o.readFileSync(i,"utf8");let s;try{s=JSON.parse(r)}catch{console.error(`Could not parse '${e}' — skipping updates.`);return}s[t]=s[t]||{};let a=!1;for(const[f,p]of Object.entries(n))s[t][f]!==p&&(s[t][f]=p,a=!0);a?(o.writeFileSync(i,JSON.stringify(s,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,n=!1){if(n||await u(`This will update '${e}' file. Continue?`)){const l=d.default.resolve(process.cwd(),e);if(!o.existsSync(l)){console.warn(`No '${e}' found in project root — skipping updates.`);return}const r=o.readFileSync(l,"utf8").split(/\r?\n/);let s=!1;for(const a of t)r.includes(a)||(r.push(a),s=!0);s?(o.writeFileSync(l,r.join(`
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(`
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=m;exports.promptUser=u;exports.updateJsonFile=S;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=h;exports.promptUser=d;exports.updateJsonFile=U;exports.updateTextFile=x;
@@ -1,76 +1,77 @@
1
1
  import a from "path";
2
- import { existsSync as d, copyFileSync as m, readFileSync as w, writeFileSync as $ } from "fs";
3
- import y from "readline";
4
- async function u(e) {
5
- const o = y.createInterface({
2
+ import { existsSync as d, copyFileSync as $, readFileSync as m, writeFileSync as w } from "fs";
3
+ import { fileURLToPath as y } from "url";
4
+ import g from "readline";
5
+ async function f(e) {
6
+ const o = g.createInterface({
6
7
  input: process.stdin,
7
8
  output: process.stdout
8
9
  });
9
- return new Promise((t) => {
10
- o.question(e + " (y/N): ", (r) => {
11
- o.close(), t(/^y(es)?$/i.test(r.trim()));
10
+ return new Promise((n) => {
11
+ o.question(e + " (y/N): ", (c) => {
12
+ o.close(), n(/^y(es)?$/i.test(c.trim()));
12
13
  });
13
14
  });
14
15
  }
15
- async function h(e, o, t = !1) {
16
- if (t || await u(
16
+ async function k(e, o, n = !1) {
17
+ if (n || await f(
17
18
  `This will create '${o}' file. Continue?`
18
19
  )) {
19
- const n = a.resolve(process.cwd(), e), i = a.resolve(process.cwd(), o);
20
- d(n) || (console.error(`Template file not found at ${n}`), process.exit(1)), d(i) && (t || await u(
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(
21
22
  `File '${o}' already exists. Overwrite?`
22
- ) || (console.log("Aborted."), process.exit(0))), m(n, i), console.log(`New file '${o}' successfully created.`);
23
+ ) || (console.log("Aborted."), process.exit(0))), $(s, t), console.log(`New file '${o}' successfully created.`);
23
24
  } else
24
25
  console.log(`Creation of '${o}' skipped.`);
25
26
  }
26
- async function k(e, o, t, r = !1) {
27
- if (r || await u(
27
+ async function C(e, o, n, c = !1) {
28
+ if (c || await f(
28
29
  `This will update '${e}' file. Continue?`
29
30
  )) {
30
- const i = a.resolve(process.cwd(), e);
31
- if (!d(i)) {
31
+ const r = a.resolve(process.cwd(), e);
32
+ if (!d(r)) {
32
33
  console.warn(`No '${e}' found in project root — skipping updates.`);
33
34
  return;
34
35
  }
35
- const l = w(i, "utf8");
36
- let s;
36
+ const s = m(r, "utf8");
37
+ let t;
37
38
  try {
38
- s = JSON.parse(l);
39
+ t = JSON.parse(s);
39
40
  } catch {
40
41
  console.error(`Could not parse '${e}' — skipping updates.`);
41
42
  return;
42
43
  }
43
- s[o] = s[o] || {};
44
- let c = !1;
45
- for (const [f, p] of Object.entries(t))
46
- s[o][f] !== p && (s[o][f] = p, c = !0);
47
- c ? ($(i, JSON.stringify(s, null, 2) + `
44
+ 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) + `
48
49
  `, "utf8"), console.log(`'${e}' file updated.`)) : console.log(`'${e}' file already up to date.`);
49
50
  } else
50
51
  console.log(`Updating '${e}' skipped.`);
51
52
  }
52
- async function C(e, o, t = !1) {
53
- if (t || await u(
53
+ async function N(e, o, n = !1) {
54
+ if (n || await f(
54
55
  `This will update '${e}' file. Continue?`
55
56
  )) {
56
- const n = a.resolve(process.cwd(), e);
57
- if (!d(n)) {
57
+ const i = a.resolve(process.cwd(), e);
58
+ if (!d(i)) {
58
59
  console.warn(`No '${e}' found in project root — skipping updates.`);
59
60
  return;
60
61
  }
61
- const l = w(n, "utf8").split(/\r?\n/);
62
- let s = !1;
63
- for (const c of o)
64
- l.includes(c) || (l.push(c), s = !0);
65
- s ? ($(n, l.join(`
62
+ const s = m(i, "utf8").split(/\r?\n/);
63
+ 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
67
  `) + `
67
68
  `, "utf8"), console.log(`'${e}' file updated.`)) : console.log(`'${e}' file already up to date.`);
68
69
  } else
69
70
  console.log(`Updating '${e}' skipped.`);
70
71
  }
71
72
  export {
72
- h as createFileFromTemplate,
73
- u as promptUser,
74
- k as updateJsonFile,
75
- C as updateTextFile
73
+ k as createFileFromTemplate,
74
+ f as promptUser,
75
+ C as updateJsonFile,
76
+ N as updateTextFile
76
77
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elrh-cosca",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"