@plexus-ms/cli-template 0.0.0-stage → 0.130.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.
Files changed (55) hide show
  1. package/LICENSE.copier +25 -0
  2. package/dist/bin.d.ts +3 -0
  3. package/dist/bin.d.ts.map +1 -0
  4. package/dist/bin.js +6 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/cli.d.ts +12 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +412 -0
  9. package/dist/cli.js.map +1 -0
  10. package/dist/directory.d.ts +16 -0
  11. package/dist/directory.d.ts.map +1 -0
  12. package/dist/directory.js +240 -0
  13. package/dist/directory.js.map +1 -0
  14. package/dist/errors.d.ts +8 -0
  15. package/dist/errors.d.ts.map +1 -0
  16. package/dist/errors.js +15 -0
  17. package/dist/errors.js.map +1 -0
  18. package/dist/files.d.ts +17 -0
  19. package/dist/files.d.ts.map +1 -0
  20. package/dist/files.js +209 -0
  21. package/dist/files.js.map +1 -0
  22. package/dist/git-merge-file.d.ts +4 -0
  23. package/dist/git-merge-file.d.ts.map +1 -0
  24. package/dist/git-merge-file.js +95 -0
  25. package/dist/git-merge-file.js.map +1 -0
  26. package/dist/index.d.ts +5 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +15 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/jinja.d.ts +7 -0
  31. package/dist/jinja.d.ts.map +1 -0
  32. package/dist/jinja.js +36 -0
  33. package/dist/jinja.js.map +1 -0
  34. package/dist/manifest.d.ts +13 -0
  35. package/dist/manifest.d.ts.map +1 -0
  36. package/dist/manifest.js +209 -0
  37. package/dist/manifest.js.map +1 -0
  38. package/dist/merge.d.ts +4 -0
  39. package/dist/merge.d.ts.map +1 -0
  40. package/dist/merge.js +185 -0
  41. package/dist/merge.js.map +1 -0
  42. package/dist/questions.d.ts +14 -0
  43. package/dist/questions.d.ts.map +1 -0
  44. package/dist/questions.js +290 -0
  45. package/dist/questions.js.map +1 -0
  46. package/dist/render.d.ts +4 -0
  47. package/dist/render.d.ts.map +1 -0
  48. package/dist/render.js +245 -0
  49. package/dist/render.js.map +1 -0
  50. package/dist/types.d.ts +130 -0
  51. package/dist/types.d.ts.map +1 -0
  52. package/dist/types.js +80 -0
  53. package/dist/types.js.map +1 -0
  54. package/package.json +43 -3
  55. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-merge-file.js","sourceRoot":"","sources":["../src/git-merge-file.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,+EAA+E;AAC/E,8EAA8E;AAC9E,yEAAyE;AACzE,+BAA+B;AAC/B,EAAE;AACF,oFAAoF;AACpF,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,EAAE;AACF,oBAAoB;AACpB,qBAAqB;AACrB,YAAY;AACZ,2BAA2B;AAC3B,uBAAuB;AACvB,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,+EAA+E;AAC/E,gFAAgF;AAChF,6EAA6E;AAC7E,6EAA6E;AAC7E,sGAAsG;AACtG,+EAA+E;AAC/E,WAAW;AACX,EAAE;AACF,wEAAwE;AACxE,yEAAyE;AACzE,2EAA2E;AAC3E,+EAA+E;AAC/E,oHAAoH;AACpH,+EAA+E;AAC/E,0EAA0E;AAC1E,qBAAqB;AACrB,EAAE;AACF,gFAAgF;AAChF,0EAA0E;AAC1E,kBAAkB;AAClB,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAG1C,6EAA6E;AAC7E,MAAM,MAAM,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,YAAY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MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAClF,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/D,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/D,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG;gBAAE,OAAO,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;;gBAC5E,MAAM,CAAC,IAAI,KAAK,CAAC,4BAA4B,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;QACzG,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { gitMergeFile } from './git-merge-file.ts';
2
+ export { merge } from './merge.ts';
3
+ export { render } from './render.ts';
4
+ export { type Answers, type BirthCommand, DIRECTORY, type Entry, type FileSides, type Manifest, type MergedFile, type MergeEntry, type MergeFile, type MergeInput, type MergeResult, MODE_TYPE, type Origin, type Outcome, type Policies, type Policy, type Question, type QuestionType, REGULAR, type Read, type RenderError, type RenderResult, SYMLINK, type Tree, } from './types.ts';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,SAAS,EACT,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,SAAS,EACT,KAAK,MAAM,EACX,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,OAAO,EACP,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,OAAO,EACP,KAAK,IAAI,GACV,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ // @plexus-ms/cli-template: the engine of plx-template as a library, a generic
2
+ // alternative to copier for several templates in one directory. It knows
3
+ // templates, answers, rendering and three-way merging, and nothing of who
4
+ // calls it: it imports no Plexus package (boundary.test.ts) and keeps no state.
5
+ //
6
+ // The core is two functions over in-memory trees, whose types and their
7
+ // meaning are in types.ts: `render` and `merge`. It reads and writes no
8
+ // directory and runs no command (boundary.test.ts). `gitMergeFile`, the real
9
+ // merge of one file that the caller hands to `merge`, is the one function
10
+ // that does: it writes temporary files and runs git.
11
+ export { gitMergeFile } from "./git-merge-file.js";
12
+ export { merge } from "./merge.js";
13
+ export { render } from "./render.js";
14
+ export { DIRECTORY, MODE_TYPE, REGULAR, SYMLINK, } from "./types.js";
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yEAAyE;AACzE,0EAA0E;AAC1E,gFAAgF;AAChF,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,6EAA6E;AAC7E,0EAA0E;AAC1E,qDAAqD;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAGL,SAAS,EAST,SAAS,EAOT,OAAO,EAIP,OAAO,GAER,MAAM,YAAY,CAAC"}
@@ -0,0 +1,7 @@
1
+ /** The variables a template or expression sees, by name. */
2
+ export type Context = Record<string, unknown>;
3
+ /** The text a Jinja template source renders to in the context. */
4
+ export declare function renderString(source: string, context: Context): string;
5
+ /** The value of a Jinja expression in the context, as a JavaScript value: string, number, boolean, null, array or object. */
6
+ export declare function evaluate(expression: string, context: Context): unknown;
7
+ //# sourceMappingURL=jinja.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jinja.d.ts","sourceRoot":"","sources":["../src/jinja.ts"],"names":[],"mappings":"AAqBA,4DAA4D;AAC5D,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAO9C,kEAAkE;AAClE,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAErE;AAED,6HAA6H;AAC7H,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAItE"}
package/dist/jinja.js ADDED
@@ -0,0 +1,36 @@
1
+ // The adapter to the template engine library, minijinja-js: the one file that
2
+ // imports it, so that the library can be replaced here alone. It offers two
3
+ // functions, render a string and evaluate an expression to a native value,
4
+ // over one environment configured once.
5
+ //
6
+ // A file's trailing newlines are kept, as copier's Jinja environment keeps
7
+ // them, and nothing is escaped: templates render config files and source code,
8
+ // never HTML for a browser. The library escapes only by a template name's
9
+ // suffix, such as `.html`, and a string is rendered here without a name. Line
10
+ // endings are carried as they are; Python's Jinja would turn every CRLF into LF.
11
+ //
12
+ // A variable the context lacks is an error wherever it is used, except under
13
+ // `is defined` and the `default` filter: a typo in a template fails the render
14
+ // instead of writing an empty string, as copier's lenient Jinja would. An
15
+ // expression whose whole value is undefined fails as well, which the library
16
+ // lets through even in strict mode.
17
+ //
18
+ // Strings, lists and maps offer the Python methods Jinja templates call on them
19
+ // (`split`, `strip`, `startswith`, `items` and the like), as in Python's Jinja.
20
+ import { Environment } from 'minijinja-js';
21
+ const env = new Environment();
22
+ env.keepTrailingNewline = true;
23
+ env.undefinedBehavior = 'strict';
24
+ env.pycompat = true;
25
+ /** The text a Jinja template source renders to in the context. */
26
+ export function renderString(source, context) {
27
+ return env.renderStr(source, context);
28
+ }
29
+ /** The value of a Jinja expression in the context, as a JavaScript value: string, number, boolean, null, array or object. */
30
+ export function evaluate(expression, context) {
31
+ const value = env.evalExpr(expression, context);
32
+ if (value === undefined)
33
+ throw new Error(`undefined value: \`${expression}\``);
34
+ return value;
35
+ }
36
+ //# sourceMappingURL=jinja.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jinja.js","sourceRoot":"","sources":["../src/jinja.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,4EAA4E;AAC5E,2EAA2E;AAC3E,wCAAwC;AACxC,EAAE;AACF,2EAA2E;AAC3E,+EAA+E;AAC/E,0EAA0E;AAC1E,8EAA8E;AAC9E,iFAAiF;AACjF,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,0EAA0E;AAC1E,6EAA6E;AAC7E,oCAAoC;AACpC,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAK3C,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAC9B,GAAG,CAAC,mBAAmB,GAAG,IAAI,CAAC;AAC/B,GAAG,CAAC,iBAAiB,GAAG,QAAQ,CAAC;AACjC,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC;AAEpB,kEAAkE;AAClE,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,OAAgB;IAC3D,OAAO,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAED,6HAA6H;AAC7H,MAAM,UAAU,QAAQ,CAAC,UAAkB,EAAE,OAAgB;IAC3D,MAAM,KAAK,GAAY,GAAG,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACzD,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,UAAU,IAAI,CAAC,CAAC;IAC/E,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type Manifest, type RenderError, type Tree } from './types.ts';
2
+ /** A template read: its manifest, and its files by their path below `files/`. */
3
+ export interface Template {
4
+ readonly manifest: Manifest;
5
+ readonly files: Tree;
6
+ }
7
+ /** Where a template's tree holds its manifest. */
8
+ export declare const MANIFEST = "template.yml";
9
+ /** The directory of a template's tree that holds its files. */
10
+ export declare const FILES = "files/";
11
+ /** The template in `tree`, the `position`th of a render counted from 1; its problems go to `errors`. */
12
+ export declare function readTemplate(tree: Tree, position: number, errors: RenderError[]): Template | undefined;
13
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAuCA,OAAO,EACL,KAAK,QAAQ,EAOb,KAAK,WAAW,EAEhB,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAEpB,iFAAiF;AACjF,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;CACtB;AAED,kDAAkD;AAClD,eAAO,MAAM,QAAQ,iBAAiB,CAAC;AACvC,+DAA+D;AAC/D,eAAO,MAAM,KAAK,WAAW,CAAC;AAiB9B,wGAAwG;AACxG,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,GAAG,SAAS,CA0BtG"}
@@ -0,0 +1,209 @@
1
+ // The manifest reader: a template's tree split into its manifest, read from
2
+ // `template.yml`, and the files it renders, below `files/`. Any other entry of
3
+ // the tree, a note for the template's authors beside the manifest, is not part
4
+ // of the template and is ignored.
5
+ //
6
+ // The manifest is YAML, a map of five keys, of which only `name` is required:
7
+ //
8
+ // name: fruit-basket # lowercase letters, digits and hyphens, from a letter
9
+ // questions: # the answers this template owns, in the order they resolve
10
+ // fruit: # a variable name: a letter, then letters, digits and `_`
11
+ // type: str # str, int, float, bool, yaml or json; without it, the default's
12
+ // default: apple # without it, the answer is required; a string may hold Jinja
13
+ // help: The fruit inside # what an error about a missing answer says
14
+ // when: "{{ basket }}" # a boolean, or Jinja that renders one; false skips the question
15
+ // validator: "{% if fruit == 'stone' %}not a fruit{% endif %}" # output is the error
16
+ // choices: [apple, pear] # a list, a map of label to value, or Jinja that renders one
17
+ // ripe: # a question with no fields
18
+ // reads: # answers this template uses but another template owns
19
+ // colour: # required: an error when nothing supplies it
20
+ // size: {default: small} # optional: the default when nothing supplies it
21
+ // policies: # by source path below files/, as written there
22
+ // "notes.md.jinja": born-once # merge (every path not listed) or born-once
23
+ // birth: # commands for whoever creates a directory from the
24
+ // - [git, init] # template, each an argument vector; never run here
25
+ //
26
+ // What a question's fields mean when its answer is resolved is questions.ts's.
27
+ // The reader checks the shape: every key known, every value of its kind, every
28
+ // policy naming a file below `files/`, no read of a question the template owns
29
+ // itself. Names starting with `_` are left to the engine's own variables. Each
30
+ // problem is an error of the render naming `template.yml`, the template, and
31
+ // the question or read where there is one; the reader reports all of them, and
32
+ // a template with any is not rendered. Until its name is read, a template is
33
+ // named by its position in the list, `#1` for the first.
34
+ //
35
+ // Maps keep the order the manifest writes them in: questions resolve in it, and
36
+ // a map of choices is read into a `Map`, since a parsed object would move keys
37
+ // that look like integers to its front.
38
+ import { isNode, isMap as isYamlMap, parseDocument } from 'yaml';
39
+ import { messageOf } from "./errors.js";
40
+ import { MODE_TYPE, REGULAR, SYMLINK, } from "./types.js";
41
+ /** Where a template's tree holds its manifest. */
42
+ export const MANIFEST = 'template.yml';
43
+ /** The directory of a template's tree that holds its files. */
44
+ export const FILES = 'files/';
45
+ const KEYS = ['name', 'questions', 'reads', 'policies', 'birth'];
46
+ const FIELDS = ['type', 'default', 'help', 'when', 'validator', 'choices'];
47
+ const TYPES = ['str', 'int', 'float', 'bool', 'yaml', 'json'];
48
+ const POLICIES = ['merge', 'born-once'];
49
+ const NAME = /^[a-z][a-z0-9-]*$/;
50
+ const VARIABLE = /^[A-Za-z][A-Za-z0-9_]*$/;
51
+ const utf8 = new TextDecoder('utf-8', { fatal: true });
52
+ const isMap = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
53
+ /** The template in `tree`, the `position`th of a render counted from 1; its problems go to `errors`. */
54
+ export function readTemplate(tree, position, errors) {
55
+ let template = `#${position}`;
56
+ let failed = false;
57
+ const problem = (message, question, path = MANIFEST) => {
58
+ failed = true;
59
+ errors.push({ template, path, ...(question === undefined ? {} : { question }), message });
60
+ };
61
+ const parsed = parseManifest(tree, problem);
62
+ if (parsed === undefined)
63
+ return undefined;
64
+ const { data, doc } = parsed;
65
+ if (typeof data.name === 'string' && NAME.test(data.name))
66
+ template = data.name;
67
+ else
68
+ problem('the name is lowercase letters, digits and hyphens, starting with a letter');
69
+ for (const [path, { mode }] of tree) {
70
+ if ((mode & MODE_TYPE) === SYMLINK)
71
+ problem(`${path} is a symlink, and a template may not hold one`, undefined, path);
72
+ }
73
+ for (const key of Object.keys(data))
74
+ if (!KEYS.includes(key))
75
+ problem(`unknown key ${key}`);
76
+ const files = new Map([...tree].filter(([path]) => path.startsWith(FILES)).map(([path, entry]) => [path.slice(FILES.length), entry]));
77
+ const questions = readQuestions(data.questions, doc, problem);
78
+ const reads = readReads(data.reads, questions, problem);
79
+ const policies = readPolicies(data.policies, files, problem);
80
+ const birth = readBirth(data.birth, problem);
81
+ if (failed)
82
+ return undefined;
83
+ return { manifest: { name: template, questions, reads, policies, birth }, files };
84
+ }
85
+ function parseManifest(tree, problem) {
86
+ const entry = tree.get(MANIFEST);
87
+ if (entry === undefined) {
88
+ problem(`the template has no ${MANIFEST}`);
89
+ return undefined;
90
+ }
91
+ let doc;
92
+ let data;
93
+ try {
94
+ doc = parseDocument(utf8.decode(entry.bytes));
95
+ const [error] = doc.errors;
96
+ if (error !== undefined)
97
+ throw error;
98
+ data = doc.toJS();
99
+ }
100
+ catch (error) {
101
+ problem(`${MANIFEST} is no YAML: ${messageOf(error)}`);
102
+ return undefined;
103
+ }
104
+ if (!isMap(data)) {
105
+ problem(`${MANIFEST} is not a map`);
106
+ return undefined;
107
+ }
108
+ return { data, doc };
109
+ }
110
+ /** The map at `path` in `doc`, in the order the document writes it. */
111
+ function orderedMap(doc, path) {
112
+ const node = doc.getIn(path, true);
113
+ const js = (value) => (isNode(value) ? value.toJS(doc) : value);
114
+ return new Map(isYamlMap(node) ? node.items.map((pair) => [String(js(pair.key)), js(pair.value)]) : []);
115
+ }
116
+ /** The entries of an optional map section, or none when it is no map. */
117
+ function section(value, what, problem) {
118
+ if (value === undefined || value === null)
119
+ return [];
120
+ if (isMap(value))
121
+ return Object.entries(value);
122
+ problem(`${what} is a map`);
123
+ return [];
124
+ }
125
+ function variable(name, what, problem) {
126
+ if (VARIABLE.test(name))
127
+ return true;
128
+ problem(`a ${what}'s name is a letter, then letters, digits and underscores`, name);
129
+ return false;
130
+ }
131
+ function readQuestions(value, doc, problem) {
132
+ return section(value, 'questions', problem).flatMap(([name, fields]) => {
133
+ if (!variable(name, 'question', problem))
134
+ return [];
135
+ if (fields === null)
136
+ return [{ name }];
137
+ if (!isMap(fields)) {
138
+ problem('a question is a map of its fields', name);
139
+ return [];
140
+ }
141
+ let valid = true;
142
+ const check = (ok, message) => {
143
+ if (ok)
144
+ return;
145
+ valid = false;
146
+ problem(message, name);
147
+ };
148
+ for (const field of Object.keys(fields))
149
+ check(FIELDS.includes(field), `unknown field ${field}`);
150
+ const { type, help, when, validator, choices } = fields;
151
+ check(type === undefined || (typeof type === 'string' && TYPES.includes(type)), `type is one of ${TYPES.join(', ')}`);
152
+ check(help === undefined || typeof help === 'string', 'help is a string');
153
+ check(when === undefined || typeof when === 'boolean' || typeof when === 'string', 'when is a boolean or a string');
154
+ check(validator === undefined || typeof validator === 'string', 'validator is a string');
155
+ check(choices === undefined || typeof choices === 'string' || (typeof choices === 'object' && choices !== null), 'choices are a list, a map or a string');
156
+ if (!valid)
157
+ return [];
158
+ const ordered = isMap(choices) ? { choices: orderedMap(doc, ['questions', name, 'choices']) } : {};
159
+ return [{ name, ...fields, ...ordered }];
160
+ });
161
+ }
162
+ function readReads(value, questions, problem) {
163
+ return section(value, 'reads', problem).flatMap(([name, fields]) => {
164
+ if (!variable(name, 'read', problem))
165
+ return [];
166
+ if (questions.some((q) => q.name === name)) {
167
+ problem('a template does not read its own question', name);
168
+ return [];
169
+ }
170
+ if (fields === null)
171
+ return [{ name }];
172
+ if (!isMap(fields)) {
173
+ problem('a read is empty, or a map with a default', name);
174
+ return [];
175
+ }
176
+ const unknown = Object.keys(fields).filter((field) => field !== 'default');
177
+ for (const field of unknown)
178
+ problem(`unknown field ${field}; a read has only a default`, name);
179
+ return unknown.length > 0 ? [] : [{ name, ...fields }];
180
+ });
181
+ }
182
+ function readPolicies(value, files, problem) {
183
+ const policies = new Map();
184
+ for (const [path, policy] of section(value, 'policies', problem)) {
185
+ const entry = files.get(path);
186
+ if (entry === undefined || (entry.mode & MODE_TYPE) !== REGULAR)
187
+ problem(`policies name ${path}, which is no file below ${FILES}`);
188
+ else if (typeof policy !== 'string' || !POLICIES.includes(policy))
189
+ problem(`the policy of ${path} is ${POLICIES.join(' or ')}, not ${String(policy)}`);
190
+ else
191
+ policies.set(path, policy);
192
+ }
193
+ return policies;
194
+ }
195
+ function readBirth(value, problem) {
196
+ if (value === undefined || value === null)
197
+ return [];
198
+ if (!Array.isArray(value)) {
199
+ problem('birth is a list of commands');
200
+ return [];
201
+ }
202
+ return value.filter((command) => {
203
+ const ok = Array.isArray(command) && command.length > 0 && command.every((arg) => typeof arg === 'string');
204
+ if (!ok)
205
+ problem('each birth command is a list of strings, its first the program');
206
+ return ok;
207
+ });
208
+ }
209
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,kCAAkC;AAClC,EAAE;AACF,8EAA8E;AAC9E,EAAE;AACF,yFAAyF;AACzF,8FAA8F;AAC9F,4FAA4F;AAC5F,mGAAmG;AACnG,gGAAgG;AAChG,8EAA8E;AAC9E,mGAAmG;AACnG,6FAA6F;AAC7F,+FAA+F;AAC/F,8DAA8D;AAC9D,yFAAyF;AACzF,gFAAgF;AAChF,mFAAmF;AACnF,kFAAkF;AAClF,+EAA+E;AAC/E,sFAAsF;AACtF,sFAAsF;AACtF,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,+EAA+E;AAC/E,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,yDAAyD;AACzD,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,wCAAwC;AACxC,OAAO,EAAiB,MAAM,EAAE,KAAK,IAAI,SAAS,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAEL,SAAS,EAIT,OAAO,EAGP,OAAO,GAER,MAAM,YAAY,CAAC;AAQpB,kDAAkD;AAClD,MAAM,CAAC,M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Q,CAAC,QAAQ,CAAC,MAAM,CAAC;YAC/D,OAAO,CAAC,iBAAiB,IAAI,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;;YACjF,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,MAAgB,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,SAAS,CAAC,KAAc,EAAE,OAAgB;IACjD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IACrD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,6BAA6B,CAAC,CAAC;QACvC,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,EAAuB,EAAE;QACnD,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC;QAC3G,IAAI,CAAC,EAAE;YAAE,OAAO,CAAC,gEAAgE,CAAC,CAAC;QACnF,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type MergeFile, type MergeInput, type MergeResult } from './types.ts';
2
+ /** The current tree with the changes from the old render to the new one merged in, and a report per touched path. */
3
+ export declare function merge(input: MergeInput, mergeFile: MergeFile): Promise<MergeResult>;
4
+ //# sourceMappingURL=merge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../src/merge.ts"],"names":[],"mappings":"AAuEA,OAAO,EAOL,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,WAAW,EAMjB,MAAM,YAAY,CAAC;AAQpB,qHAAqH;AACrH,wBAAsB,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAUzF"}
package/dist/merge.js ADDED
@@ -0,0 +1,185 @@
1
+ // merge: three rendered trees into one, the current directory's with the
2
+ // template's changes applied (types.ts states the shapes). The two renders
3
+ // hold files and empty directories only, as `render` writes them; a symlink in
4
+ // either is not a render, and `merge` refuses it with an error.
5
+ //
6
+ // It looks at each path that either render holds, in path order, with its
7
+ // policy from the new render (from the old one where only the old has it),
8
+ // and the first rule that fits decides; "current" is what the current tree
9
+ // holds at the path, a directory where it holds entries below it:
10
+ //
11
+ // 1. current holds nothing there, the new render does, and the path is
12
+ // born-once or new to the template: written, `added`; but `kept` where a
13
+ // directory it lies in is a symlink in the current tree, and
14
+ // `conflicted` where one is a file
15
+ // 2. the old and the new render hold it alike: left alone
16
+ // 3. the template drops an empty directory: left alone; merge never deletes
17
+ // a directory
18
+ // 4. current is a symlink: `kept`, never written, deleted or written through
19
+ // 5. born-once, or current holds nothing: `kept`. A born-once path is never
20
+ // touched once it exists, whatever either side holds, nor deleted when
21
+ // the template drops it or its name no longer renders; a path the user
22
+ // deleted stays deleted, also where the template turns a file into a
23
+ // directory or back
24
+ // 6. current already holds what the new render does: a file is written,
25
+ // `clean`; a directory is left alone
26
+ // 7. a file on one side, a directory on another: current stays, `conflicted`
27
+ // 8. the new render lacks it: `deleted` where current is the old render's
28
+ // entry, else current stays, `conflicted`. A template that renames a file
29
+ // drops one path and adds another, so the user's edits to the old name
30
+ // survive this way
31
+ // 9. otherwise all three are files or absent, the new render and current
32
+ // both hold one, and the two changes are merged: the content and the
33
+ // executable bit apart
34
+ //
35
+ // Rule 1 is the only one that adds an empty directory; after rules 3, 6 and 7
36
+ // no directory is left, so `merge` reports a directory only as added or as
37
+ // conflicting with a file.
38
+ //
39
+ // Alike means the same type and bytes, and for a file the same executable bit,
40
+ // the one bit of a mode the engine carries (types.ts); a change of the bit
41
+ // alone is a change. Bytes are compared and carried as they are, line endings
42
+ // included.
43
+ //
44
+ // The content: where current is the old or the new render's, the new render's
45
+ // wins; where only the user changed it, current's stays; where all three differ
46
+ // it goes to the injected `MergeFile`, which says whether the result holds a
47
+ // conflict, its markers left in the file. An old render that lacks the path is
48
+ // an empty, non-executable file, so a path both sides add is merged against
49
+ // empty content. Where all three differ and one side is binary, current stays,
50
+ // `conflicted`, and `MergeFile` is not called. Binary is git's rule, since git
51
+ // merges the rest and fails on a binary file: a NUL byte among the first 8000.
52
+ //
53
+ // The executable bit is merged as the content is, but cannot conflict: where
54
+ // the template changed it the new render's wins, else current's stays. So a
55
+ // change of the bit on one side combines with a change of the content on the
56
+ // other. A written file takes a render's mode, 0o100644 or 0o100755 by the
57
+ // merged bit; where nothing changes the bit, that is the new render's.
58
+ //
59
+ // The report holds one entry, in path order, for each path the template
60
+ // changed, the old and the new render holding it differently, and for each
61
+ // path rule 1 writes; a path the template left alone is not reported, whatever
62
+ // the current tree holds there, and neither are the directories of rules 3
63
+ // and 6. A path that neither render holds is the user's: untouched and
64
+ // unreported. The tree no longer implies a directory whose files were all
65
+ // deleted; whether such a directory is removed is for whoever applies the tree.
66
+ //
67
+ // Two rules are ported from copier v9.19.1, copier/_main.py: comparing a file's
68
+ // mode by its executable bits (`_render_allowed`, here the owner's bit alone), and
69
+ // never deleting through a symlink (`_remove_old_files`); MIT-licensed, see
70
+ // LICENSE.copier. Copier's update algorithm is not: it replays a diff, this
71
+ // merges trees.
72
+ import { DIRECTORY, fileMode, isExecutable, MODE_TYPE, REGULAR, SYMLINK, } from "./types.js";
73
+ /** What the current tree holds at a path that has entries below it and none of its own. */
74
+ const HOLDS = { bytes: new Uint8Array(), mode: DIRECTORY };
75
+ /** The old side of a path the old render lacks. */
76
+ const EMPTY = { bytes: new Uint8Array(), mode: fileMode(false) };
77
+ /** The current tree with the changes from the old render to the new one merged in, and a report per touched path. */
78
+ export async function merge(input, mergeFile) {
79
+ const { old, new: next, current, files } = input;
80
+ const tree = new Map(current);
81
+ const report = [];
82
+ for (const path of [...new Set([...old.keys(), ...next.keys()])].sort()) {
83
+ const bornOnce = (next.has(path) ? files.new : files.old).get(path)?.policy === 'born-once';
84
+ const outcome = await mergePath(path, old.get(path), next.get(path), bornOnce, tree, mergeFile);
85
+ if (outcome !== undefined)
86
+ report.push({ path, outcome });
87
+ }
88
+ return { tree, report };
89
+ }
90
+ /** Merges the old and the new render's entry at `path` into `tree`, and says what happened; nothing when nothing did. */
91
+ async function mergePath(path, old, next, bornOnce, tree, mergeFile) {
92
+ if (kind(old) === SYMLINK || kind(next) === SYMLINK)
93
+ throw new Error(`merge: ${path} is a symlink in a render`);
94
+ const current = at(tree, path);
95
+ // The rules of the header, by number.
96
+ // 1
97
+ if (current === undefined && next !== undefined && (bornOnce || old === undefined)) {
98
+ const blocking = ancestors(path)
99
+ .map((a) => tree.get(a))
100
+ .find((entry) => entry !== undefined && kind(entry) !== DIRECTORY);
101
+ if (blocking !== undefined)
102
+ return kind(blocking) === SYMLINK ? 'kept' : 'conflicted';
103
+ tree.set(path, next);
104
+ return 'added';
105
+ }
106
+ if (same(old, next))
107
+ return undefined; // 2
108
+ if (kind(old) === DIRECTORY && next === undefined)
109
+ return undefined; // 3
110
+ if (kind(current) === SYMLINK)
111
+ return 'kept'; // 4
112
+ if (bornOnce || current === undefined)
113
+ return 'kept'; // 5
114
+ // 6
115
+ if (next !== undefined && same(current, next)) {
116
+ if (kind(next) === DIRECTORY)
117
+ return undefined;
118
+ tree.set(path, next);
119
+ return 'clean';
120
+ }
121
+ // 7: after rules 1 to 6, a side that is a directory has a file on another
122
+ if ([old, next, current].map(kind).includes(DIRECTORY))
123
+ return 'conflicted';
124
+ // 8
125
+ if (next === undefined) {
126
+ if (!same(current, old))
127
+ return 'conflicted';
128
+ tree.delete(path);
129
+ return 'deleted';
130
+ }
131
+ // 9
132
+ const base = old ?? EMPTY;
133
+ const merged = await mergeContent(path, base.bytes, next.bytes, current.bytes, mergeFile);
134
+ if (merged === undefined)
135
+ return 'conflicted';
136
+ const bit = isExecutable(base.mode) === isExecutable(next.mode) ? isExecutable(current.mode) : isExecutable(next.mode);
137
+ tree.set(path, { bytes: merged.bytes, mode: fileMode(bit) });
138
+ return merged.conflicted ? 'conflicted' : 'clean';
139
+ }
140
+ /** The three sides' content merged; nothing where all three differ and one is binary. */
141
+ async function mergeContent(path, old, next, current, mergeFile) {
142
+ if (equal(current, old) || equal(current, next))
143
+ return { bytes: next, conflicted: false };
144
+ if (equal(next, old))
145
+ return { bytes: current, conflicted: false };
146
+ if ([old, next, current].some(binary))
147
+ return undefined;
148
+ return mergeFile({ path, old, new: next, current });
149
+ }
150
+ /** The entry at `path` in `tree`; a directory where entries lie below it. */
151
+ function at(tree, path) {
152
+ const entry = tree.get(path);
153
+ if (entry !== undefined)
154
+ return entry;
155
+ const below = `${path}/`;
156
+ for (const p of tree.keys())
157
+ if (p.startsWith(below))
158
+ return HOLDS;
159
+ return undefined;
160
+ }
161
+ /** The paths of the directories `path` lies in, outermost first. */
162
+ function ancestors(path) {
163
+ const parts = path.split('/');
164
+ return parts.slice(1).map((_, i) => parts.slice(0, i + 1).join('/'));
165
+ }
166
+ /** An entry's type bits: REGULAR, DIRECTORY or SYMLINK. */
167
+ function kind(entry) {
168
+ return entry === undefined ? undefined : entry.mode & MODE_TYPE;
169
+ }
170
+ /** Whether git takes `bytes` as binary: a NUL byte among the first 8000, as its `buffer_is_binary` decides. */
171
+ function binary(bytes) {
172
+ return bytes.subarray(0, 8000).includes(0);
173
+ }
174
+ /** Whether two entries, either absent, are alike. */
175
+ function same(a, b) {
176
+ if (a === undefined || b === undefined)
177
+ return a === b;
178
+ if (kind(a) !== kind(b) || !equal(a.bytes, b.bytes))
179
+ return false;
180
+ return kind(a) !== REGULAR || isExecutable(a.mode) === isExecutable(b.mode);
181
+ }
182
+ function equal(a, b) {
183
+ return a.length === b.length && a.every((byte, i) => byte === b[i]);
184
+ }
185
+ //# sourceMappingURL=merge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge.js","sourceRoot":"","sources":["../src/merge.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,2EAA2E;AAC3E,+EAA+E;AAC/E,gEAAgE;AAChE,EAAE;AACF,0EAA0E;AAC1E,2EAA2E;AAC3E,2EAA2E;AAC3E,kEAAkE;AAClE,EAAE;AACF,yEAAyE;AACzE,8EAA8E;AAC9E,kEAAkE;AAClE,wCAAwC;AACxC,4DAA4D;AAC5D,8EAA8E;AAC9E,mBAAmB;AACnB,+EAA+E;AAC/E,8EAA8E;AAC9E,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,yBAAyB;AACzB,0EAA0E;AAC1E,0CAA0C;AAC1C,+EAA+E;AAC/E,4EAA4E;AAC5E,+EAA+E;AAC/E,4EAA4E;AAC5E,wBAAwB;AACxB,2EAA2E;AAC3E,0EAA0E;AAC1E,4BAA4B;AAC5B,EAAE;AACF,8EAA8E;AAC9E,2EAA2E;AAC3E,2BAA2B;AAC3B,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,8EAA8E;AAC9E,YAAY;AACZ,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,6EAA6E;AAC7E,+EAA+E;AAC/E,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,+EAA+E;AAC/E,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,uEAAuE;AACvE,EAAE;AACF,wEAAwE;AACxE,2EAA2E;AAC3E,+EAA+E;AAC/E,2EAA2E;AAC3E,uEAAuE;AACvE,0EAA0E;AAC1E,gFAAgF;AAChF,EAAE;AACF,gFAAgF;AAChF,mFAAmF;AACnF,4EAA4E;AAC5E,4EAA4E;AAC5E,gBAAgB;AAChB,OAAO,EACL,SAAS,EAET,QAAQ,EACR,YAAY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IACzC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type Context } from './jinja.ts';
2
+ import type { Answers, Manifest, RenderError } from './types.ts';
3
+ /** One template's questions, resolved. */
4
+ export interface Resolution {
5
+ /** The answers `render` reports: given or defaulted, without the questions `when` skipped. */
6
+ readonly answers: Answers;
7
+ /** What the questions add to the template's context: the answers, and the default of each skipped question that has one. */
8
+ readonly context: Context;
9
+ }
10
+ /** The questions `manifest` owns, resolved against `given` with `scope` in view; problems go to `errors`. */
11
+ export declare function resolveAnswers(manifest: Manifest, given: Answers, scope: Context, errors: RenderError[]): Resolution;
12
+ /** The names of the `given` answers that no question of the render's `manifests` owns and none of them reads. */
13
+ export declare function unusedAnswers(manifests: readonly Manifest[], given: Answers): string[];
14
+ //# sourceMappingURL=questions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questions.d.ts","sourceRoot":"","sources":["../src/questions.ts"],"names":[],"mappings":"AA6FA,OAAO,EAAE,KAAK,OAAO,EAAgB,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAA0B,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzF,0CAA0C;AAC1C,MAAM,WAAW,UAAU;IACzB,8FAA8F;IAC9F,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,4HAA4H;IAC5H,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAuJD,6GAA6G;AAC7G,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,UAAU,CAwBpH;AAED,iHAAiH;AACjH,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAGtF"}