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.
- package/dist/elrh-cosca.cjs +3 -3
- package/dist/elrh-cosca.mjs +38 -37
- package/package.json +1 -1
package/dist/elrh-cosca.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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,
|
|
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=
|
|
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;
|
package/dist/elrh-cosca.mjs
CHANGED
|
@@ -1,76 +1,77 @@
|
|
|
1
1
|
import a from "path";
|
|
2
|
-
import { existsSync as d, copyFileSync as
|
|
3
|
-
import y from "
|
|
4
|
-
|
|
5
|
-
|
|
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((
|
|
10
|
-
o.question(e + " (y/N): ", (
|
|
11
|
-
o.close(),
|
|
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
|
|
16
|
-
if (
|
|
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
|
|
20
|
-
d(
|
|
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))),
|
|
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
|
|
27
|
-
if (
|
|
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
|
|
31
|
-
if (!d(
|
|
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
|
|
36
|
-
let
|
|
36
|
+
const s = m(r, "utf8");
|
|
37
|
+
let t;
|
|
37
38
|
try {
|
|
38
|
-
|
|
39
|
+
t = JSON.parse(s);
|
|
39
40
|
} catch {
|
|
40
41
|
console.error(`Could not parse '${e}' — skipping updates.`);
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
let
|
|
45
|
-
for (const [
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
53
|
-
if (
|
|
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
|
|
57
|
-
if (!d(
|
|
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
|
|
62
|
-
let
|
|
63
|
-
for (const
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
k as createFileFromTemplate,
|
|
74
|
+
f as promptUser,
|
|
75
|
+
C as updateJsonFile,
|
|
76
|
+
N as updateTextFile
|
|
76
77
|
};
|