@shrkcrft/presets 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/apply/preview-apply.d.ts +52 -0
- package/dist/apply/preview-apply.d.ts.map +1 -0
- package/dist/apply/preview-apply.js +85 -0
- package/dist/builtin/builtin-presets.d.ts +3 -0
- package/dist/builtin/builtin-presets.d.ts.map +1 -0
- package/dist/builtin/builtin-presets.js +520 -0
- package/dist/builtin/r26-presets.d.ts +31 -0
- package/dist/builtin/r26-presets.d.ts.map +1 -0
- package/dist/builtin/r26-presets.js +458 -0
- package/dist/builtin/r26-snippets.d.ts +39 -0
- package/dist/builtin/r26-snippets.d.ts.map +1 -0
- package/dist/builtin/r26-snippets.js +257 -0
- package/dist/builtin/r45-presets.d.ts +7 -0
- package/dist/builtin/r45-presets.d.ts.map +1 -0
- package/dist/builtin/r45-presets.js +186 -0
- package/dist/builtin/r47-presets.d.ts +5 -0
- package/dist/builtin/r47-presets.d.ts.map +1 -0
- package/dist/builtin/r47-presets.js +65 -0
- package/dist/builtin/shared-snippets.d.ts +17 -0
- package/dist/builtin/shared-snippets.d.ts.map +1 -0
- package/dist/builtin/shared-snippets.js +264 -0
- package/dist/define/define-preset.d.ts +4 -0
- package/dist/define/define-preset.d.ts.map +1 -0
- package/dist/define/define-preset.js +4 -0
- package/dist/emit/synthesize-files.d.ts +26 -0
- package/dist/emit/synthesize-files.d.ts.map +1 -0
- package/dist/emit/synthesize-files.js +172 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/model/preset.d.ts +83 -0
- package/dist/model/preset.d.ts.map +1 -0
- package/dist/model/preset.js +21 -0
- package/dist/registry/load-presets.d.ts +12 -0
- package/dist/registry/load-presets.d.ts.map +1 -0
- package/dist/registry/load-presets.js +33 -0
- package/dist/registry/preset-registry.d.ts +11 -0
- package/dist/registry/preset-registry.d.ts.map +1 -0
- package/dist/registry/preset-registry.js +22 -0
- package/dist/registry/recommend.d.ts +30 -0
- package/dist/registry/recommend.d.ts.map +1 -0
- package/dist/registry/recommend.js +59 -0
- package/dist/registry/resolve-preset.d.ts +75 -0
- package/dist/registry/resolve-preset.d.ts.map +1 -0
- package/dist/registry/resolve-preset.js +207 -0
- package/dist/registry/resolve-references.d.ts +49 -0
- package/dist/registry/resolve-references.d.ts.map +1 -0
- package/dist/registry/resolve-references.js +38 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SharkCraft contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @shrkcrft/presets
|
|
2
|
+
|
|
3
|
+
SharkCraft presets: reusable project setups (knowledge/rules/paths/templates/pipelines/docs) that can be applied to a target repo through the CLI.
|
|
4
|
+
|
|
5
|
+
Part of [SharkCraft](https://github.com/shrkcrft/sharkcraft) — a deterministic, local-first toolkit that gives AI coding agents durable project context. See the main repo for documentation, examples, and the `shrk` CLI.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @shrkcrft/presets
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
MIT — see [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { IPreset } from '../model/preset.js';
|
|
2
|
+
import { type ISynthesizedFile } from '../emit/synthesize-files.js';
|
|
3
|
+
import type { IResolvedPreset } from '../registry/resolve-preset.js';
|
|
4
|
+
export interface IPresetApplyPlanEntry {
|
|
5
|
+
/** Absolute target path inside the project. */
|
|
6
|
+
targetPath: string;
|
|
7
|
+
/** Path relative to project root. */
|
|
8
|
+
relPath: string;
|
|
9
|
+
status: 'create' | 'skip-existing' | 'overwrite-with-force' | 'merge-additive';
|
|
10
|
+
content: string;
|
|
11
|
+
kind: ISynthesizedFile['kind'];
|
|
12
|
+
}
|
|
13
|
+
export interface IPresetApplyPlan {
|
|
14
|
+
presetId: string;
|
|
15
|
+
sharkcraftDir: string;
|
|
16
|
+
entries: IPresetApplyPlanEntry[];
|
|
17
|
+
warnings: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface IPreviewOptions {
|
|
20
|
+
/** Absolute project root. */
|
|
21
|
+
projectRoot: string;
|
|
22
|
+
/** Force overwriting existing files. */
|
|
23
|
+
force?: boolean;
|
|
24
|
+
/** Append to existing files where possible (knowledge/rules/paths/templates/pipelines). */
|
|
25
|
+
merge?: boolean;
|
|
26
|
+
/** Override the sharkcraft directory name (default: "sharkcraft"). */
|
|
27
|
+
sharkcraftDirName?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Compute the plan for applying a preset against `projectRoot`. Pure I/O on
|
|
31
|
+
* read; never writes. Caller is responsible for executing the plan via
|
|
32
|
+
* {@link applyPlan} (or just printing it).
|
|
33
|
+
*/
|
|
34
|
+
export declare function previewPresetApplication(preset: IPreset, options: IPreviewOptions): IPresetApplyPlan;
|
|
35
|
+
/**
|
|
36
|
+
* Same as {@link previewPresetApplication} but operating on a flattened
|
|
37
|
+
* (composition-resolved) preset. Use this whenever composition matters —
|
|
38
|
+
* which is the common case once `composes: [...]` is in play.
|
|
39
|
+
*/
|
|
40
|
+
export declare function previewResolvedPresetApplication(resolved: IResolvedPreset, options: IPreviewOptions): IPresetApplyPlan;
|
|
41
|
+
/**
|
|
42
|
+
* Execute a plan. Writes files according to each entry's status. Returns the
|
|
43
|
+
* list of relPaths actually written.
|
|
44
|
+
*
|
|
45
|
+
* For `merge-additive`, we append the new content under a generated banner.
|
|
46
|
+
* No semantic re-parsing is performed — review the result.
|
|
47
|
+
*/
|
|
48
|
+
export declare function applyPresetPlan(plan: IPresetApplyPlan): {
|
|
49
|
+
written: string[];
|
|
50
|
+
skipped: string[];
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=preview-apply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-apply.d.ts","sourceRoot":"","sources":["../../src/apply/preview-apply.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,MAAM,WAAW,qBAAqB;IACpC,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,QAAQ,GAAG,eAAe,GAAG,sBAAsB,GAAG,gBAAgB,CAAC;IAC/E,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,qBAAqB,EAAE,CAAC;IACjC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2FAA2F;IAC3F,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sEAAsE;IACtE,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAUD;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,eAAe,GACvB,gBAAgB,CAElB;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,eAAe,GACvB,gBAAgB,CAMlB;AAwCD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG;IACvD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAoBA"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import * as nodePath from 'node:path';
|
|
3
|
+
import { synthesizePresetFiles, synthesizeResolvedPresetFiles, } from "../emit/synthesize-files.js";
|
|
4
|
+
const MERGABLE_KINDS = new Set([
|
|
5
|
+
'knowledge',
|
|
6
|
+
'rules',
|
|
7
|
+
'paths',
|
|
8
|
+
'templates',
|
|
9
|
+
'pipelines',
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* Compute the plan for applying a preset against `projectRoot`. Pure I/O on
|
|
13
|
+
* read; never writes. Caller is responsible for executing the plan via
|
|
14
|
+
* {@link applyPlan} (or just printing it).
|
|
15
|
+
*/
|
|
16
|
+
export function previewPresetApplication(preset, options) {
|
|
17
|
+
return previewFromSynthesized(preset.id, synthesizePresetFiles(preset), options);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Same as {@link previewPresetApplication} but operating on a flattened
|
|
21
|
+
* (composition-resolved) preset. Use this whenever composition matters —
|
|
22
|
+
* which is the common case once `composes: [...]` is in play.
|
|
23
|
+
*/
|
|
24
|
+
export function previewResolvedPresetApplication(resolved, options) {
|
|
25
|
+
return previewFromSynthesized(resolved.rootId, synthesizeResolvedPresetFiles(resolved), options);
|
|
26
|
+
}
|
|
27
|
+
function previewFromSynthesized(presetId, synthesized, options) {
|
|
28
|
+
const sharkcraftDir = nodePath.join(options.projectRoot, options.sharkcraftDirName ?? 'sharkcraft');
|
|
29
|
+
const entries = [];
|
|
30
|
+
const warnings = [];
|
|
31
|
+
for (const file of synthesized) {
|
|
32
|
+
const targetPath = nodePath.join(sharkcraftDir, file.path);
|
|
33
|
+
const relPath = nodePath.relative(options.projectRoot, targetPath);
|
|
34
|
+
let status = 'create';
|
|
35
|
+
if (existsSync(targetPath)) {
|
|
36
|
+
if (options.force) {
|
|
37
|
+
status = 'overwrite-with-force';
|
|
38
|
+
}
|
|
39
|
+
else if (options.merge && MERGABLE_KINDS.has(file.kind)) {
|
|
40
|
+
status = 'merge-additive';
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
status = 'skip-existing';
|
|
44
|
+
warnings.push(`exists, skipping: ${relPath} (use --force or --merge)`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
entries.push({
|
|
48
|
+
targetPath,
|
|
49
|
+
relPath,
|
|
50
|
+
status,
|
|
51
|
+
content: file.content,
|
|
52
|
+
kind: file.kind,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return { presetId, sharkcraftDir, entries, warnings };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Execute a plan. Writes files according to each entry's status. Returns the
|
|
59
|
+
* list of relPaths actually written.
|
|
60
|
+
*
|
|
61
|
+
* For `merge-additive`, we append the new content under a generated banner.
|
|
62
|
+
* No semantic re-parsing is performed — review the result.
|
|
63
|
+
*/
|
|
64
|
+
export function applyPresetPlan(plan) {
|
|
65
|
+
const written = [];
|
|
66
|
+
const skipped = [];
|
|
67
|
+
for (const entry of plan.entries) {
|
|
68
|
+
if (entry.status === 'skip-existing') {
|
|
69
|
+
skipped.push(entry.relPath);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const dir = nodePath.dirname(entry.targetPath);
|
|
73
|
+
mkdirSync(dir, { recursive: true });
|
|
74
|
+
if (entry.status === 'merge-additive' && existsSync(entry.targetPath)) {
|
|
75
|
+
const previous = readFileSync(entry.targetPath, 'utf8');
|
|
76
|
+
const banner = `\n\n// --- merged from preset ${plan.presetId} ---\n`;
|
|
77
|
+
writeFileSync(entry.targetPath, previous + banner + entry.content, 'utf8');
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
writeFileSync(entry.targetPath, entry.content, 'utf8');
|
|
81
|
+
}
|
|
82
|
+
written.push(entry.relPath);
|
|
83
|
+
}
|
|
84
|
+
return { written, skipped };
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtin-presets.d.ts","sourceRoot":"","sources":["../../src/builtin/builtin-presets.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AA6iBlD,eAAO,MAAM,eAAe,EAAE,SAAS,OAAO,EA0B5C,CAAC"}
|