elrh-cosca 0.1.5 → 0.2.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/README.md +111 -6
- package/dist/elrh-cosca.mjs +16343 -75
- package/dist/types/_private/deep-merge-object.d.ts +1 -0
- package/dist/types/functions/update-config-file.d.ts +13 -0
- package/dist/types/functions/update-json-file.d.ts +1 -0
- package/dist/types/main.d.ts +8 -5
- package/dist/types/utils/parse-qualified-path.d.ts +8 -0
- package/dist/types/utils/resolve-package-path.d.ts +6 -0
- package/package.json +2 -3
- package/test/cosca-test.js +10 -5
- package/dist/elrh-cosca.cjs +0 -4
- package/dist/types/lib/update-json-file.d.ts +0 -1
- package/dist/types/utils/resolve-package.d.ts +0 -14
- package/dist/types/utils/resolve-path.d.ts +0 -12
- /package/dist/types/{lib → functions}/create-file-from-template.d.ts +0 -0
- /package/dist/types/{lib → functions}/update-text-file.d.ts +0 -0
- /package/dist/types/{lib → terminal}/prompt-user.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function deepMergeObject(magicast: any, object: any): void;
|
|
@@ -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>;
|
|
@@ -0,0 +1 @@
|
|
|
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,8 @@
|
|
|
1
|
-
import { createFileFromTemplate } from './
|
|
2
|
-
import {
|
|
3
|
-
import { updateJsonFile } from './
|
|
4
|
-
import { updateTextFile } from './
|
|
5
|
-
|
|
1
|
+
import { createFileFromTemplate } from './functions/create-file-from-template';
|
|
2
|
+
import { updateConfigFile } from './functions/update-config-file';
|
|
3
|
+
import { updateJsonFile } from './functions/update-json-file';
|
|
4
|
+
import { updateTextFile } from './functions/update-text-file';
|
|
5
|
+
import { promptUser } from './terminal/prompt-user';
|
|
6
|
+
import { parseQualifiedPath } from './utils/parse-qualified-path';
|
|
7
|
+
import { resolvePackagePath } from './utils/resolve-package-path';
|
|
8
|
+
export { createFileFromTemplate, updateConfigFile, updateJsonFile, updateTextFile, promptUser, parseQualifiedPath, resolvePackagePath, };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expects path to file in `"package:relative/path/to/file"` format and splits it into `{ pkg, file }`.
|
|
3
|
+
* The package name can be scoped (e.g. `@scope/package`). Throws error on invalid input.
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseQualifiedPath(path: string): {
|
|
6
|
+
pkg: string;
|
|
7
|
+
file: string;
|
|
8
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elrh-cosca",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -12,15 +12,14 @@
|
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./dist/types/index.d.ts",
|
|
14
14
|
"import": "./dist/elrh-cosca.mjs",
|
|
15
|
-
"require": "./dist/elrh-cosca.cjs",
|
|
16
15
|
"default": "./dist/elrh-cosca.mjs"
|
|
17
16
|
}
|
|
18
17
|
},
|
|
19
|
-
"main": "./dist/elrh-cosca.cjs",
|
|
20
18
|
"module": "./dist/elrh-cosca.mjs",
|
|
21
19
|
"types": "./dist/types/index.d.ts",
|
|
22
20
|
"devDependencies": {
|
|
23
21
|
"@types/node": "^24.3.0",
|
|
22
|
+
"magicast": "^0.3.5",
|
|
24
23
|
"typescript": "^5.9.2",
|
|
25
24
|
"vite": "^7.1.3",
|
|
26
25
|
"vite-plugin-dts": "^4.5.4",
|
package/test/cosca-test.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
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() {
|
|
8
10
|
console.log('Test promptUser')
|
|
@@ -10,14 +12,17 @@ async function main() {
|
|
|
10
12
|
console.log('User input:', input)
|
|
11
13
|
|
|
12
14
|
console.log('\nTest createFileFromTemplate')
|
|
13
|
-
await createFileFromTemplate('
|
|
14
|
-
await createFileFromTemplate('elrh-cosca:
|
|
15
|
+
await createFileFromTemplate('vitest:README.md', 'test/snapshots/test.file1')
|
|
16
|
+
await createFileFromTemplate('elrh-cosca:test/fixtures/text-file.txt', 'test/snapshots/test.file2')
|
|
17
|
+
|
|
18
|
+
console.log('\nTest updateConfigFile')
|
|
19
|
+
await updateConfigFile('test/fixtures/config-file-default.ts', { compatibilityDate: '2025-08-26', extends: ['nuxt-iignis'], cosca: { exists: true, data: ['some', 'other'], raw: 'war' } })
|
|
15
20
|
|
|
16
21
|
console.log('\nTest updateJsonFile')
|
|
17
|
-
await updateJsonFile('
|
|
22
|
+
await updateJsonFile('test/fixtures/json-file.json', 'scripts', { 'cosca' : 'cosca' })
|
|
18
23
|
|
|
19
24
|
console.log('\nTest updateTextFile')
|
|
20
|
-
await updateTextFile('.
|
|
25
|
+
await updateTextFile('test/fixtures/text-file.txt', ['# COSCA'])
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
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"),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
|
-
`)+`
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function updateJsonFile(pathToFile: string, jsonKey: string, newValues: Record<string, string>, force?: boolean): Promise<void>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Expects path to file template in `"package:relative/path/to/file"` format and splits it into `{ pkg, file }`.
|
|
3
|
-
* Throws error on invalid input.
|
|
4
|
-
*/
|
|
5
|
-
export declare function parseTemplatePath(input: string): {
|
|
6
|
-
pkg: string;
|
|
7
|
-
file: string;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Resolve a package's installed root directory *from the target app*.
|
|
11
|
-
* Package name can be scoped.
|
|
12
|
-
* Works with npm/yarn/pnpm, hoisting or not.
|
|
13
|
-
*/
|
|
14
|
-
export declare function resolvePackagePath(packageName: string): string;
|
|
@@ -1,12 +0,0 @@
|
|
|
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;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|