@batijs/core 0.0.287 → 0.0.289
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/index.d.ts +102 -20
- package/dist/index.js +650 -600
- package/package.json +12 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { BatiSet } from '@batijs/features';
|
|
1
|
+
import { BatiSet, CategoryLabels, Flags } from '@batijs/features';
|
|
2
2
|
import * as yaml from 'yaml';
|
|
3
3
|
import { ParseOptions, DocumentOptions, SchemaOptions, Document } from 'yaml';
|
|
4
4
|
export { Document as YAMLDocument } from 'yaml';
|
|
5
|
+
import * as mdast from 'mdast';
|
|
6
|
+
import { Nodes, Parents, Root } from 'mdast';
|
|
7
|
+
import * as attributes_parser from 'attributes-parser';
|
|
5
8
|
import { ProxifiedModule } from 'magicast';
|
|
6
9
|
export { builders, generateCode, loadFile, parseModule } from 'magicast';
|
|
7
10
|
export { addVitePlugin, deepMergeObject } from 'magicast/helpers';
|
|
@@ -28,6 +31,9 @@ type TransformerProps = {
|
|
|
28
31
|
meta: VikeMeta;
|
|
29
32
|
};
|
|
30
33
|
type Transformer = (props: TransformerProps) => unknown;
|
|
34
|
+
interface StringTransformer {
|
|
35
|
+
finalize(): string;
|
|
36
|
+
}
|
|
31
37
|
|
|
32
38
|
declare function transformAndFormat(code: string, meta: VikeMeta, options: {
|
|
33
39
|
filepath: string;
|
|
@@ -40,6 +46,56 @@ declare function formatCode(code: string, options: {
|
|
|
40
46
|
filepath: string;
|
|
41
47
|
}): Promise<string>;
|
|
42
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Parse a comment marker.
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
declare function commentMarker(value: Nodes): {
|
|
54
|
+
name: string;
|
|
55
|
+
suffix: string;
|
|
56
|
+
attributes: string;
|
|
57
|
+
parameters: attributes_parser.Attributes;
|
|
58
|
+
node: mdast.Html;
|
|
59
|
+
} | undefined;
|
|
60
|
+
|
|
61
|
+
type MarkdownPosition = "before" | "after" | "replace";
|
|
62
|
+
type Sections = "document" | "intro" | "features" | "TOC";
|
|
63
|
+
type FilterHandler = (info: ReturnType<typeof commentMarker>) => boolean;
|
|
64
|
+
type FilterObject = {
|
|
65
|
+
section?: Sections;
|
|
66
|
+
category?: CategoryLabels;
|
|
67
|
+
flag?: Flags;
|
|
68
|
+
[key: string]: undefined | string | number | boolean;
|
|
69
|
+
};
|
|
70
|
+
type WrapperObject = FilterObject & {
|
|
71
|
+
name?: string;
|
|
72
|
+
};
|
|
73
|
+
type MarkdownOptions = {
|
|
74
|
+
filter?: FilterObject | FilterHandler;
|
|
75
|
+
position?: MarkdownPosition;
|
|
76
|
+
wrapper?: WrapperObject;
|
|
77
|
+
};
|
|
78
|
+
type classConfig = {
|
|
79
|
+
defaults?: MarkdownOptions;
|
|
80
|
+
};
|
|
81
|
+
type Info = {
|
|
82
|
+
parent: Parents;
|
|
83
|
+
start: number;
|
|
84
|
+
end: number;
|
|
85
|
+
};
|
|
86
|
+
type ZoneHandler = (start: Nodes, between: Nodes[], end: Nodes, info: Info) => Nodes[] | null | undefined | void;
|
|
87
|
+
|
|
88
|
+
declare function parseMarkdown(text: string, defaults?: MarkdownOptions): MarkdownV2;
|
|
89
|
+
declare class MarkdownV2 implements StringTransformer {
|
|
90
|
+
private tree;
|
|
91
|
+
private contents;
|
|
92
|
+
private config;
|
|
93
|
+
constructor(tree: Root, config?: classConfig);
|
|
94
|
+
addMarkdownFeature(markdown: string | ZoneHandler, flag: Flags): void;
|
|
95
|
+
addMarkdown(markdown: string | ZoneHandler, options?: MarkdownOptions): void;
|
|
96
|
+
finalize(): string;
|
|
97
|
+
}
|
|
98
|
+
|
|
43
99
|
declare function h1(text: string): string;
|
|
44
100
|
declare function h2(text: string): string;
|
|
45
101
|
declare function h3(text: string): string;
|
|
@@ -68,37 +124,63 @@ declare const markdown: {
|
|
|
68
124
|
italic: typeof italic;
|
|
69
125
|
};
|
|
70
126
|
|
|
71
|
-
declare function loadReadme({ readfile }: TransformerProps): Promise<Readme>;
|
|
72
|
-
declare function loadAsJson({ readfile, source, target }: TransformerProps): Promise<any>;
|
|
73
|
-
declare function loadAsMagicast<Exports extends object>({ readfile, source, target, }: TransformerProps): Promise<ProxifiedModule<Exports>>;
|
|
74
|
-
declare function loadRelativeFileAsMagicast<Exports extends object>(relativePath: string, meta: Pick<ImportMeta, "url">): Promise<ProxifiedModule<Exports>>;
|
|
75
|
-
declare function loadYaml({ readfile, source, target }: TransformerProps, options?: ParseOptions & DocumentOptions & SchemaOptions): Promise<Document.Parsed<yaml.Alias.Parsed, true> | Document.Parsed<yaml.Scalar.Parsed, true> | Document.Parsed<yaml.YAMLMap.Parsed<yaml.ParsedNode, yaml.ParsedNode | null>, true> | Document.Parsed<yaml.YAMLSeq.Parsed<yaml.ParsedNode>, true>>;
|
|
76
|
-
|
|
77
|
-
declare const keys: readonly ["dev", "build", "preview", "lint", "format", "deploy", "test"];
|
|
78
|
-
type Scripts = (typeof keys)[number];
|
|
79
|
-
type ValidScripts = Scripts | `${Scripts}:${string}`;
|
|
80
127
|
interface PackageJsonDeps {
|
|
81
128
|
dependencies?: Record<string, string>;
|
|
82
129
|
devDependencies?: Record<string, string>;
|
|
83
130
|
}
|
|
84
131
|
interface PackageJsonScripts {
|
|
85
|
-
scripts
|
|
132
|
+
scripts?: Record<string, string>;
|
|
86
133
|
}
|
|
87
134
|
interface PackageJsonScriptOption {
|
|
88
|
-
value
|
|
135
|
+
value: string;
|
|
89
136
|
/**
|
|
90
137
|
* Higher values have priority
|
|
91
138
|
*/
|
|
92
139
|
precedence: number;
|
|
93
140
|
warnIfReplaced?: boolean;
|
|
94
141
|
}
|
|
95
|
-
type PackageJsonScriptOptions =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
declare
|
|
142
|
+
type PackageJsonScriptOptions = Record<string, {
|
|
143
|
+
value?: string;
|
|
144
|
+
precedence: number;
|
|
145
|
+
warnIfReplaced?: boolean;
|
|
146
|
+
}>;
|
|
147
|
+
type AllDependencies<U extends PackageJsonDeps> = keyof U["dependencies"] | keyof U["devDependencies"];
|
|
148
|
+
declare class PackageJsonTransformer<U extends PackageJsonDeps> implements StringTransformer {
|
|
149
|
+
protected static previousScripts: PackageJsonScriptOptions;
|
|
150
|
+
protected static forcedDependencies: Set<string>;
|
|
151
|
+
protected static dependenciesScriptsRelation: Map<string | symbol | number, Set<string>>;
|
|
152
|
+
protected pendingAddedDependencies: string[];
|
|
153
|
+
protected pendingReplacedScripts: string[];
|
|
154
|
+
protected packageJson: PackageJsonScripts & PackageJsonDeps;
|
|
155
|
+
protected scopedPackageJson: U;
|
|
156
|
+
constructor(packageJson: PackageJsonScripts & PackageJsonDeps, scopedPackageJson: U);
|
|
157
|
+
setScript(name: string, args: PackageJsonScriptOption, condition?: boolean): this;
|
|
158
|
+
removeScript(name: string, condition?: boolean): this;
|
|
159
|
+
addDependencies(newDeps: AllDependencies<U>[], condition?: boolean): this;
|
|
160
|
+
addDependencies(newDeps: AllDependencies<U>[], onlyUsedBy?: string[], condition?: boolean): this;
|
|
161
|
+
addDevDependencies(newDeps: AllDependencies<U>[], condition?: boolean): this;
|
|
162
|
+
addDevDependencies(newDeps: AllDependencies<U>[], onlyUsedBy?: string[], condition?: boolean): this;
|
|
163
|
+
finalize(): string;
|
|
164
|
+
/**
|
|
165
|
+
* For tests purpose only
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
168
|
+
static clear(): void;
|
|
169
|
+
private _onlyUsedBy;
|
|
170
|
+
private _addDependencies;
|
|
171
|
+
/**
|
|
172
|
+
* Instead of removing a previously added dep, use `onlyUsedBy` parameter when adding a dependency
|
|
173
|
+
*/
|
|
174
|
+
private removeDependency;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
declare function loadReadme({ readfile }: TransformerProps): Promise<Readme>;
|
|
178
|
+
declare function loadMarkdown({ readfile }: TransformerProps): Promise<MarkdownV2>;
|
|
179
|
+
declare function loadAsJson({ readfile, source, target }: TransformerProps): Promise<any>;
|
|
180
|
+
declare function loadPackageJson<U extends PackageJsonDeps>({ readfile, source, target }: TransformerProps, scopedPackageJson: U): Promise<PackageJsonTransformer<U>>;
|
|
181
|
+
declare function loadAsMagicast<Exports extends object>({ readfile, source, target, }: TransformerProps): Promise<ProxifiedModule<Exports>>;
|
|
182
|
+
declare function loadRelativeFileAsMagicast<Exports extends object>(relativePath: string, meta: Pick<ImportMeta, "url">): Promise<ProxifiedModule<Exports>>;
|
|
183
|
+
declare function loadYaml({ readfile, source, target }: TransformerProps, options?: ParseOptions & DocumentOptions & SchemaOptions): Promise<Document.Parsed<yaml.Alias.Parsed, true> | Document.Parsed<yaml.Scalar.Parsed, true> | Document.Parsed<yaml.YAMLMap.Parsed<yaml.ParsedNode, yaml.ParsedNode | null>, true> | Document.Parsed<yaml.YAMLSeq.Parsed<yaml.ParsedNode>, true>>;
|
|
102
184
|
|
|
103
185
|
declare function appendToEnv(envContent: string | undefined | null, key: string, value: unknown, comment?: string): string;
|
|
104
186
|
|
|
@@ -114,4 +196,4 @@ declare function getVersion(): {
|
|
|
114
196
|
semver: string[];
|
|
115
197
|
};
|
|
116
198
|
|
|
117
|
-
export { type ContentGetter, type FileContext,
|
|
199
|
+
export { type ContentGetter, type FileContext, MarkdownV2, Readme, type StringTransformer, type Transformer, type TransformerProps, type VikeMeta, appendToEnv, formatCode, getArgs, getVersion, loadAsJson, loadAsMagicast, loadMarkdown, loadPackageJson, loadReadme, loadRelativeFileAsMagicast, loadYaml, markdown, packageManager, parseMarkdown, parseReadme, transformAndFormat, withIcon };
|