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