elrh-cosca 0.1.4 → 0.2.0
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/README.md +87 -6
- package/dist/elrh-cosca.mjs +16333 -68
- package/dist/types/lib/update-config-file.d.ts +13 -0
- package/dist/types/lib/update-json-file.d.ts +1 -1
- package/dist/types/main.d.ts +2 -1
- package/dist/types/utils/better-deep-merge.d.ts +1 -0
- package/dist/types/utils/resolve-package.d.ts +1 -0
- package/package.json +2 -1
- package/test/cosca-test.js +11 -2
- package/dist/elrh-cosca.cjs +0 -4
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Update the single object-literal config found in a file.
|
|
3
|
+
*
|
|
4
|
+
* The function:
|
|
5
|
+
* - Reads and edits the file as code (no execution).
|
|
6
|
+
* - Uses `defu(newConfig, existingConfig)` so `newConfig` takes precedence.
|
|
7
|
+
* - Applies the merged result back onto the AST to preserve TS/ESM structure.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} pathToFile - Path to file, relative to project root (process.cwd()).
|
|
10
|
+
* @param {object} newConfig - Config to merge in (takes precedence).
|
|
11
|
+
* @returns {Promise<void>}
|
|
12
|
+
*/
|
|
13
|
+
export declare function updateConfigFile(pathToFile: string, newConfig: Record<string | number | symbol, any>, force?: boolean): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function updateJsonFile(pathToFile: string, jsonKey: string, newValues: Record<string,
|
|
1
|
+
export declare function updateJsonFile(pathToFile: string, jsonKey: string, newValues: Record<string | number | symbol, any>, force?: boolean): Promise<void>;
|
package/dist/types/main.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createFileFromTemplate } from './lib/create-file-from-template';
|
|
2
2
|
import { promptUser } from './lib/prompt-user';
|
|
3
|
+
import { updateConfigFile } from './lib/update-config-file';
|
|
3
4
|
import { updateJsonFile } from './lib/update-json-file';
|
|
4
5
|
import { updateTextFile } from './lib/update-text-file';
|
|
5
|
-
export { createFileFromTemplate, promptUser, updateJsonFile, updateTextFile, };
|
|
6
|
+
export { createFileFromTemplate, promptUser, updateConfigFile, updateJsonFile, updateTextFile, };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function deepMergeObject(magicast: any, object: any): void;
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elrh-cosca",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^24.3.0",
|
|
24
|
+
"magicast": "^0.3.5",
|
|
24
25
|
"typescript": "^5.9.2",
|
|
25
26
|
"vite": "^7.1.3",
|
|
26
27
|
"vite-plugin-dts": "^4.5.4",
|
package/test/cosca-test.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// manual test script for COSCA functions
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
createFileFromTemplate, promptUser, updateConfigFile, updateJsonFile, updateTextFile
|
|
7
|
+
} from '../dist/elrh-cosca.mjs'
|
|
6
8
|
|
|
7
9
|
async function main() {
|
|
10
|
+
/*
|
|
8
11
|
console.log('Test promptUser')
|
|
9
12
|
const input = await promptUser('Is it today?')
|
|
10
13
|
console.log('User input:', input)
|
|
@@ -12,12 +15,18 @@ async function main() {
|
|
|
12
15
|
console.log('\nTest createFileFromTemplate')
|
|
13
16
|
await createFileFromTemplate('vite:README.md', 'test.file1')
|
|
14
17
|
await createFileFromTemplate('elrh-cosca:README.md', 'test.file2')
|
|
18
|
+
*/
|
|
15
19
|
|
|
20
|
+
console.log('\nTest updateConfigFile')
|
|
21
|
+
await updateConfigFile('test/cosca-test-config.ts', { compatibilityDate: '2025-08-26', extends: ['nuxt-iignis'], cosca: { exists: true, data: ['some', 'other'], raw: 'war' } })
|
|
22
|
+
|
|
23
|
+
/*
|
|
16
24
|
console.log('\nTest updateJsonFile')
|
|
17
25
|
await updateJsonFile('package.json', 'scripts', { 'cosca' : 'cosca' })
|
|
18
26
|
|
|
19
27
|
console.log('\nTest updateTextFile')
|
|
20
28
|
await updateTextFile('.gitignore', ['# COSCA'])
|
|
29
|
+
*/
|
|
21
30
|
}
|
|
22
31
|
|
|
23
32
|
main().catch((err) => {
|
package/dist/elrh-cosca.cjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("node:path"),n=require("node:fs"),w=require("node:readline"),g=require("node:module"),y=e=>e&&e.__esModule?e:{default:e},h=y(w);async function p(e){const t=h.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{t.question(e+" (y/N): ",r=>{t.close(),o(/^y(es)?$/i.test(r.trim()))})})}function m(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(),r=e.slice(t+1).replace(/^[/\\]+/,"");if(!o||o.endsWith("/")||o.includes(" "))throw new Error(`Invalid package name in templatePath: "${o}"`);return{pkg:o,file:r}}function $(e){try{const t=process.cwd(),o=a.join(t,"package.json"),r=n.readFileSync(o,"utf8");if(JSON.parse(r)?.name===e)return t}catch{}try{const o=g.createRequire(a.resolve(process.cwd(),"package.json")).resolve(`${e}/package.json`);return a.dirname(o)}catch{throw new Error(`Cannot find package "${e}" from ${process.cwd()}. Make sure it's installed or linked in this project.`)}}async function k(e,t,o=!1){if(o||await p(`This will create '${t}' file. Continue?`)){const{pkg:c,file:d}=m(e),l=$(c),s=a.resolve(l,d),i=a.resolve(process.cwd(),t);n.existsSync(s)||(console.error(`Template file not found at ${s}`),process.exit(1)),n.existsSync(i)&&(o||await p(`File '${t}' already exists. Overwrite?`)||(console.log("Aborted."),process.exit(0))),n.copyFileSync(s,i),console.log(`New file '${t}' successfully created.`)}else console.log(`Creation of '${t}' skipped.`)}async function x(e,t,o,r=!1){if(r||await p(`This will update '${e}' file. Continue?`)){const d=a.resolve(process.cwd(),e);if(!n.existsSync(d)){console.warn(`No '${e}' found in project root — skipping updates.`);return}const l=n.readFileSync(d,"utf8");let s;try{s=JSON.parse(l)}catch{console.error(`Could not parse '${e}' — skipping updates.`);return}s[t]=s[t]||{};let i=!1;for(const[u,f]of Object.entries(o))s[t][u]!==f&&(s[t][u]=f,i=!0);i?(n.writeFileSync(d,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 P(e,t,o=!1){if(o||await p(`This will update '${e}' file. Continue?`)){const c=a.resolve(process.cwd(),e);if(!n.existsSync(c)){console.warn(`No '${e}' found in project root — skipping updates.`);return}const l=n.readFileSync(c,"utf8").split(/\r?\n/);let s=!1;for(const i of t)l.includes(i)||(l.push(i),s=!0);s?(n.writeFileSync(c,l.join(`
|
|
3
|
-
`)+`
|
|
4
|
-
`,"utf8"),console.log(`'${e}' file updated.`)):console.log(`'${e}' file already up to date.`)}else console.log(`Updating '${e}' skipped.`)}exports.createFileFromTemplate=k;exports.promptUser=p;exports.updateJsonFile=x;exports.updateTextFile=P;
|