elrh-cosca 0.1.4 → 0.1.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.
package/dist/elrh-cosca.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("node: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 a=require("node:path"),r=require("node:fs"),w=require("node:readline"),g=e=>e&&e.__esModule?e:{default:e},y=g(w);async function u(e){const t=y.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{t.question(e+" (y/N): ",s=>{t.close(),o(/^y(es)?$/i.test(s.trim()))})})}function h(e){const t=e.indexOf(":");if(t<=0||t===e.length-1)throw new Error(`Invalid input "${e}". Expected format is "package:relative/path/to/file".`);const o=e.slice(0,t).trim(),s=e.slice(t+1).replace(/^[/\\]+/,"");if(!o||o.endsWith("/")||o.includes(" "))throw new Error(`Invalid package name in templatePath: "${o}"`);return{pkg:o,file:s}}function $(e){const t=process.cwd();try{const o=a.join(t,"package.json"),s=r.readFileSync(o,"utf8");if(JSON.parse(s)?.name===e)return t}catch(o){console.error(o)}try{const o=a.join(t,"node_modules",...e.split("/")),s=a.join(o,"package.json");return console.log(s),r.access(s,r.constants.R_OK,i=>{if(i)throw new Error(`Cannot access "${s}"`)}),o}catch(o){console.error(o)}throw new Error(`Cannot find package "${e}" from ${process.cwd()}. Make sure it's installed or linked in this project.`)}async function m(e,t,o=!1){if(o||await u(`This will create '${t}' file. Continue?`)){const{pkg:i,file:d}=h(e),l=$(i),n=a.resolve(l,d),c=a.resolve(process.cwd(),t);r.existsSync(n)||(console.error(`Template file not found at ${n}`),process.exit(1)),r.existsSync(c)&&(o||await u(`File '${t}' already exists. Overwrite?`)||(console.log("Aborted."),process.exit(0))),r.copyFileSync(n,c),console.log(`New file '${t}' successfully created.`)}else console.log(`Creation of '${t}' skipped.`)}async function k(e,t,o,s=!1){if(s||await u(`This will update '${e}' file. Continue?`)){const d=a.resolve(process.cwd(),e);if(!r.existsSync(d)){console.warn(`No '${e}' found in project root — skipping updates.`);return}const l=r.readFileSync(d,"utf8");let n;try{n=JSON.parse(l)}catch{console.error(`Could not parse '${e}' — skipping updates.`);return}n[t]=n[t]||{};let c=!1;for(const[p,f]of Object.entries(o))n[t][p]!==f&&(n[t][p]=f,c=!0);c?(r.writeFileSync(d,JSON.stringify(n,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,o=!1){if(o||await u(`This will update '${e}' file. Continue?`)){const i=a.resolve(process.cwd(),e);if(!r.existsSync(i)){console.warn(`No '${e}' found in project root — skipping updates.`);return}const l=r.readFileSync(i,"utf8").split(/\r?\n/);let n=!1;for(const c of t)l.includes(c)||(l.push(c),n=!0);n?(r.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=m;exports.promptUser=u;exports.updateJsonFile=k;exports.updateTextFile=x;
|
package/dist/elrh-cosca.mjs
CHANGED
|
@@ -1,102 +1,107 @@
|
|
|
1
|
-
import { join as
|
|
2
|
-
import { readFileSync as
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const t = k.createInterface({
|
|
1
|
+
import { join as u, resolve as a } from "node:path";
|
|
2
|
+
import { readFileSync as w, access as $, constants as h, existsSync as d, copyFileSync as k, writeFileSync as m } from "node:fs";
|
|
3
|
+
import y from "node:readline";
|
|
4
|
+
async function p(e) {
|
|
5
|
+
const o = y.createInterface({
|
|
7
6
|
input: process.stdin,
|
|
8
7
|
output: process.stdout
|
|
9
8
|
});
|
|
10
|
-
return new Promise((
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
return new Promise((t) => {
|
|
10
|
+
o.question(e + " (y/N): ", (s) => {
|
|
11
|
+
o.close(), t(/^y(es)?$/i.test(s.trim()));
|
|
13
12
|
});
|
|
14
13
|
});
|
|
15
14
|
}
|
|
16
15
|
function P(e) {
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
16
|
+
const o = e.indexOf(":");
|
|
17
|
+
if (o <= 0 || o === e.length - 1)
|
|
19
18
|
throw new Error(
|
|
20
19
|
`Invalid input "${e}". Expected format is "package:relative/path/to/file".`
|
|
21
20
|
);
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
24
|
-
throw new Error(`Invalid package name in templatePath: "${
|
|
25
|
-
return { pkg:
|
|
21
|
+
const t = e.slice(0, o).trim(), s = e.slice(o + 1).replace(/^[/\\]+/, "");
|
|
22
|
+
if (!t || t.endsWith("/") || t.includes(" "))
|
|
23
|
+
throw new Error(`Invalid package name in templatePath: "${t}"`);
|
|
24
|
+
return { pkg: t, file: s };
|
|
26
25
|
}
|
|
27
26
|
function x(e) {
|
|
27
|
+
const o = process.cwd();
|
|
28
28
|
try {
|
|
29
|
-
const t =
|
|
30
|
-
if (JSON.parse(
|
|
31
|
-
return
|
|
32
|
-
} catch {
|
|
29
|
+
const t = u(o, "package.json"), s = w(t, "utf8");
|
|
30
|
+
if (JSON.parse(s)?.name === e)
|
|
31
|
+
return o;
|
|
32
|
+
} catch (t) {
|
|
33
|
+
console.error(t);
|
|
33
34
|
}
|
|
34
35
|
try {
|
|
35
|
-
const
|
|
36
|
-
return $(
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
const t = u(o, "node_modules", ...e.split("/")), s = u(t, "package.json");
|
|
37
|
+
return console.log(s), $(s, h.R_OK, (r) => {
|
|
38
|
+
if (r)
|
|
39
|
+
throw new Error(`Cannot access "${s}"`);
|
|
40
|
+
}), t;
|
|
41
|
+
} catch (t) {
|
|
42
|
+
console.error(t);
|
|
39
43
|
}
|
|
44
|
+
throw new Error(`Cannot find package "${e}" from ${process.cwd()}. Make sure it's installed or linked in this project.`);
|
|
40
45
|
}
|
|
41
|
-
async function
|
|
42
|
-
if (
|
|
43
|
-
`This will create '${
|
|
46
|
+
async function j(e, o, t = !1) {
|
|
47
|
+
if (t || await p(
|
|
48
|
+
`This will create '${o}' file. Continue?`
|
|
44
49
|
)) {
|
|
45
|
-
const { pkg:
|
|
46
|
-
|
|
47
|
-
`File '${
|
|
48
|
-
) || (console.log("Aborted."), process.exit(0))),
|
|
50
|
+
const { pkg: r, file: l } = P(e), i = x(r), n = a(i, l), c = a(process.cwd(), o);
|
|
51
|
+
d(n) || (console.error(`Template file not found at ${n}`), process.exit(1)), d(c) && (t || await p(
|
|
52
|
+
`File '${o}' already exists. Overwrite?`
|
|
53
|
+
) || (console.log("Aborted."), process.exit(0))), k(n, c), console.log(`New file '${o}' successfully created.`);
|
|
49
54
|
} else
|
|
50
|
-
console.log(`Creation of '${
|
|
55
|
+
console.log(`Creation of '${o}' skipped.`);
|
|
51
56
|
}
|
|
52
|
-
async function
|
|
53
|
-
if (
|
|
57
|
+
async function S(e, o, t, s = !1) {
|
|
58
|
+
if (s || await p(
|
|
54
59
|
`This will update '${e}' file. Continue?`
|
|
55
60
|
)) {
|
|
56
|
-
const
|
|
57
|
-
if (!
|
|
61
|
+
const l = a(process.cwd(), e);
|
|
62
|
+
if (!d(l)) {
|
|
58
63
|
console.warn(`No '${e}' found in project root — skipping updates.`);
|
|
59
64
|
return;
|
|
60
65
|
}
|
|
61
|
-
const
|
|
62
|
-
let
|
|
66
|
+
const i = w(l, "utf8");
|
|
67
|
+
let n;
|
|
63
68
|
try {
|
|
64
|
-
|
|
69
|
+
n = JSON.parse(i);
|
|
65
70
|
} catch {
|
|
66
71
|
console.error(`Could not parse '${e}' — skipping updates.`);
|
|
67
72
|
return;
|
|
68
73
|
}
|
|
69
|
-
|
|
70
|
-
let
|
|
71
|
-
for (const [f,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
n[o] = n[o] || {};
|
|
75
|
+
let c = !1;
|
|
76
|
+
for (const [f, g] of Object.entries(t))
|
|
77
|
+
n[o][f] !== g && (n[o][f] = g, c = !0);
|
|
78
|
+
c ? (m(l, JSON.stringify(n, null, 2) + `
|
|
74
79
|
`, "utf8"), console.log(`'${e}' file updated.`)) : console.log(`'${e}' file already up to date.`);
|
|
75
80
|
} else
|
|
76
81
|
console.log(`Updating '${e}' skipped.`);
|
|
77
82
|
}
|
|
78
|
-
async function
|
|
79
|
-
if (
|
|
83
|
+
async function U(e, o, t = !1) {
|
|
84
|
+
if (t || await p(
|
|
80
85
|
`This will update '${e}' file. Continue?`
|
|
81
86
|
)) {
|
|
82
|
-
const
|
|
83
|
-
if (!
|
|
87
|
+
const r = a(process.cwd(), e);
|
|
88
|
+
if (!d(r)) {
|
|
84
89
|
console.warn(`No '${e}' found in project root — skipping updates.`);
|
|
85
90
|
return;
|
|
86
91
|
}
|
|
87
|
-
const
|
|
88
|
-
let
|
|
89
|
-
for (const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
const i = w(r, "utf8").split(/\r?\n/);
|
|
93
|
+
let n = !1;
|
|
94
|
+
for (const c of o)
|
|
95
|
+
i.includes(c) || (i.push(c), n = !0);
|
|
96
|
+
n ? (m(r, i.join(`
|
|
92
97
|
`) + `
|
|
93
98
|
`, "utf8"), console.log(`'${e}' file updated.`)) : console.log(`'${e}' file already up to date.`);
|
|
94
99
|
} else
|
|
95
100
|
console.log(`Updating '${e}' skipped.`);
|
|
96
101
|
}
|
|
97
102
|
export {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
j as createFileFromTemplate,
|
|
104
|
+
p as promptUser,
|
|
105
|
+
S as updateJsonFile,
|
|
106
|
+
U as updateTextFile
|
|
102
107
|
};
|
|
@@ -8,6 +8,7 @@ export declare function parseTemplatePath(input: string): {
|
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Resolve a package's installed root directory *from the target app*.
|
|
11
|
+
* Package name can be scoped.
|
|
11
12
|
* Works with npm/yarn/pnpm, hoisting or not.
|
|
12
13
|
*/
|
|
13
14
|
export declare function resolvePackagePath(packageName: string): string;
|