@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.
- package/LICENSE.copier +25 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +6 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +412 -0
- package/dist/cli.js.map +1 -0
- package/dist/directory.d.ts +16 -0
- package/dist/directory.d.ts.map +1 -0
- package/dist/directory.js +240 -0
- package/dist/directory.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -0
- package/dist/files.d.ts +17 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +209 -0
- package/dist/files.js.map +1 -0
- package/dist/git-merge-file.d.ts +4 -0
- package/dist/git-merge-file.d.ts.map +1 -0
- package/dist/git-merge-file.js +95 -0
- package/dist/git-merge-file.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/jinja.d.ts +7 -0
- package/dist/jinja.d.ts.map +1 -0
- package/dist/jinja.js +36 -0
- package/dist/jinja.js.map +1 -0
- package/dist/manifest.d.ts +13 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +209 -0
- package/dist/manifest.js.map +1 -0
- package/dist/merge.d.ts +4 -0
- package/dist/merge.d.ts.map +1 -0
- package/dist/merge.js +185 -0
- package/dist/merge.js.map +1 -0
- package/dist/questions.d.ts +14 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +290 -0
- package/dist/questions.js.map +1 -0
- package/dist/render.d.ts +4 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +245 -0
- package/dist/render.js.map +1 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +80 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -3
- package/README.md +0 -3
package/LICENSE.copier
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Parts of this package's source and tests are ported from copier, https://github.com/copier-org/copier, at v9.19.1.
|
|
2
|
+
Each such file names its original in a comment and refers to this file.
|
|
3
|
+
Copier is distributed under the following licence.
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2011 Juan-Pablo Scaletti
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Entry point of `plx-template`: everything is in cli.ts, which is importable
|
|
3
|
+
// without a process; this file only turns its result into the exit code.
|
|
4
|
+
import { main } from "./cli.js";
|
|
5
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
6
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,8EAA8E;AAC9E,yEAAyE;AACzE,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The exit codes. */
|
|
2
|
+
export declare const EXIT: {
|
|
3
|
+
readonly ok: 0;
|
|
4
|
+
readonly failed: 1;
|
|
5
|
+
readonly usage: 2;
|
|
6
|
+
readonly input: 3;
|
|
7
|
+
};
|
|
8
|
+
/** Where `render` writes the policies of the render in `dir`: beside it, so that no file of the render is one it did not render. */
|
|
9
|
+
export declare const policiesOf: (dir: string) => string;
|
|
10
|
+
/** Runs the command `argv` names and returns its exit code. */
|
|
11
|
+
export declare function main(argv: readonly string[]): Promise<number>;
|
|
12
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAsIA,sBAAsB;AACtB,eAAO,MAAM,IAAI;;;;;CAAoD,CAAC;AA0FtE,oIAAoI;AACpI,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,MAA6C,CAAC;AA8KvF,+DAA+D;AAC/D,wBAAsB,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA0CnE"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
// plx-template, the command line around the core: the shell that reads
|
|
2
|
+
// directories and JSON, calls `render` or `merge`, and writes the results. It
|
|
3
|
+
// holds no decision of its own; every one is the core's (types.ts, render.ts,
|
|
4
|
+
// merge.ts). `plx-template --help` says how to call it; this says what it does.
|
|
5
|
+
//
|
|
6
|
+
// An update by hand, in three commands. A directory `project` was rendered
|
|
7
|
+
// from version 1 of the templates, and its owner has edited it since. Version
|
|
8
|
+
// 1 of the templates is in `v1/`, version 2 in `v2/`, and `answers.json`
|
|
9
|
+
// holds the answers the project was rendered with:
|
|
10
|
+
//
|
|
11
|
+
// plx-template render --answers answers.json old v1/basket v1/shelf
|
|
12
|
+
// plx-template render --answers answers.json new v2/basket v2/shelf
|
|
13
|
+
// plx-template merge old new project
|
|
14
|
+
//
|
|
15
|
+
// The first two write the two renders, `old` and `new`, which must not exist
|
|
16
|
+
// yet or be empty; the third changes `project` and prints what it did to each
|
|
17
|
+
// path. Look at `diff -r old new` to see what the template changed, and at the
|
|
18
|
+
// markers the third left (below) to see what is yours to decide. Nothing else
|
|
19
|
+
// is needed: no state is kept, no command is run, git is run only to merge the
|
|
20
|
+
// text of a file that both sides changed, `git merge-file`, and its results are
|
|
21
|
+
// the ones `git merge-file -p -L current -L "old render" -L "new render"` gives.
|
|
22
|
+
//
|
|
23
|
+
// What `render` does. It reads each template directory into a tree (its
|
|
24
|
+
// manifest `template.yml` and its `files/`, manifest.ts), reads the answers,
|
|
25
|
+
// gives both to the core, and, where the core reports no error, writes the
|
|
26
|
+
// rendered tree to the output directory, creating it where it is missing, and
|
|
27
|
+
// the policies file beside it. It refuses an output directory that is not
|
|
28
|
+
// empty, and a template or an answers file it cannot read, as errors in the
|
|
29
|
+
// inputs; it writes nothing at all when there is any. It runs no birth
|
|
30
|
+
// command: they are in the JSON, for the caller.
|
|
31
|
+
//
|
|
32
|
+
// How the policies travel from `render` to `merge`. `merge` needs the policy
|
|
33
|
+
// of every path of both renders (`merge` or `born-once`, types.ts). `render`
|
|
34
|
+
// writes them to `<output-dir>.plx-template.json` beside the rendered
|
|
35
|
+
// directory, `{ "version": 1, "files": { "<path>": { "template": ...,
|
|
36
|
+
// "policy": ... } } }`, the `files` of its own JSON; `merge` reads the file
|
|
37
|
+
// beside each of its two directories. It is beside the render and not in it so that the directory
|
|
38
|
+
// holds exactly the files the templates rendered: a file inside would be taken
|
|
39
|
+
// for one of them by `merge` and by a person comparing two renders with
|
|
40
|
+
// `diff -r`. A render moved or copied needs its policies file moved with it;
|
|
41
|
+
// `merge` fails with an input error, naming the file, where one is missing, is
|
|
42
|
+
// of a version it does not know (a later plx-template wrote it), or does not
|
|
43
|
+
// name exactly the paths its render directory holds, each with a policy of
|
|
44
|
+
// `merge` or `born-once`: a policy taken for granted could make `merge` delete
|
|
45
|
+
// a born-once file, which the engine never does. Output directory `old/` and
|
|
46
|
+
// `old` give the same file. Because the file lands beside the output
|
|
47
|
+
// directory, rendering into `.` or straight into a temporary directory leaves
|
|
48
|
+
// it in the parent, so render into a directory of its own; `render` overwrites
|
|
49
|
+
// a policies file that is already there.
|
|
50
|
+
//
|
|
51
|
+
// What `merge` reads of the target directory. Not all of it: for each path of
|
|
52
|
+
// either render, the entry at the path (a file with its bytes and mode, a
|
|
53
|
+
// symlink with its target), the first leaf below it where it is a directory,
|
|
54
|
+
// and each directory above it that is a symlink or a file, where the walk
|
|
55
|
+
// stops. That answers every rule of merge.ts, which looks at the path and at
|
|
56
|
+
// "entries below it" and at the directories the path lies in, and it leaves
|
|
57
|
+
// `.git`, `node_modules` and everything the templates do not name unread.
|
|
58
|
+
// Nothing is read through a symlink. That the partial read answers as a whole
|
|
59
|
+
// read would holds where the filesystem tells names apart exactly; on a
|
|
60
|
+
// case-insensitive or normalising one, the default on macOS, `lstat('A')`
|
|
61
|
+
// finds `a`, and the partial read reports what the writes will meet, which is
|
|
62
|
+
// the safer answer, and differs from a whole read.
|
|
63
|
+
//
|
|
64
|
+
// What `merge` refuses before it reads the target: an old and a new render that
|
|
65
|
+
// are one directory, a target that is one of the two renders, a symlink in a
|
|
66
|
+
// render, a directory argument that is a symlink (none is followed), and a
|
|
67
|
+
// policies file that is wrong. Each is an input error, and nothing is written.
|
|
68
|
+
//
|
|
69
|
+
// How `merge` writes. It applies the report of the core to the target:
|
|
70
|
+
// `added`, `clean` and `conflicted` paths are written where the merged entry
|
|
71
|
+
// differs from what is on disk, `deleted` ones are removed, `kept` ones are
|
|
72
|
+
// left alone, and a path the report does not name is never touched (directory.ts
|
|
73
|
+
// has the details). A conflict stays in the file between the markers
|
|
74
|
+
// `<<<<<<< current` and `>>>>>>> new render`, the user's lines first, so that
|
|
75
|
+
// it can be found with `grep -rn '^<<<<<<< current'`. Nothing is written
|
|
76
|
+
// through a symlink or deleted through one. An existing file keeps its
|
|
77
|
+
// permissions but for its executable bits, and is never given more than
|
|
78
|
+
// execute where it may already read: 0o600 becomes 0o700 and 0o644 becomes
|
|
79
|
+
// 0o755. A deletion that leaves a directory empty removes it, upward to the
|
|
80
|
+
// target and no further, as copier does, unless the new render holds it as an
|
|
81
|
+
// empty directory; `merge` itself never deletes a directory, and an empty
|
|
82
|
+
// directory that was there already stays. The merge of one file's text is
|
|
83
|
+
// gitMergeFile's, which does not merge a file that already holds a conflict of
|
|
84
|
+
// its own labels again: running `merge` a second time leaves such a file as it
|
|
85
|
+
// is, reported conflicted. A failure while applying, such as a file that cannot
|
|
86
|
+
// be written, stops the run with code 1 and a message on standard error that
|
|
87
|
+
// names the path and says that the paths before it in path order were already
|
|
88
|
+
// applied; the report is not printed then, since it would claim the rest.
|
|
89
|
+
//
|
|
90
|
+
// Standard output carries only JSON, messages for people go to standard error.
|
|
91
|
+
// render prints { answers, unused, files, birth, errors }: the core's result
|
|
92
|
+
// without the tree, `files` and `answers` by name. `files` maps each
|
|
93
|
+
// path, an empty directory too, to { template, policy }; `birth` lists
|
|
94
|
+
// { template, command } as the templates declare them. `errors` is
|
|
95
|
+
// empty on success.
|
|
96
|
+
// merge prints { report: [{ path, outcome }] } in path order, `outcome` one
|
|
97
|
+
// of clean, added, deleted, conflicted or kept (types.ts).
|
|
98
|
+
// an error in the inputs prints, for merge, { errors }, and for render its
|
|
99
|
+
// usual object with `errors` filled; each error is { message,
|
|
100
|
+
// template?, path?, question?, other? }, every one found is listed,
|
|
101
|
+
// and each is repeated on standard error with what it concerns.
|
|
102
|
+
//
|
|
103
|
+
// The exit codes (`EXIT`): 0 done, a merge that left conflicts too; 1 failed:
|
|
104
|
+
// something other than the inputs went wrong, a file that cannot be written or
|
|
105
|
+
// git that cannot be run, and then nothing is printed on standard output; 2 a
|
|
106
|
+
// usage error, with nothing on standard output either;
|
|
107
|
+
// 3 an error in the inputs: a missing answer, paths two templates write, a bad
|
|
108
|
+
// manifest, a directory or policies file that is missing, an output directory
|
|
109
|
+
// that is not empty.
|
|
110
|
+
//
|
|
111
|
+
// Answers arrive as JSON, a file or `-` for standard input, and are never
|
|
112
|
+
// asked for. The command is the only code of the package, with directory.ts and
|
|
113
|
+
// git-merge-file.ts, that touches the filesystem or runs a command
|
|
114
|
+
// (boundary.test.ts).
|
|
115
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
116
|
+
import { join, resolve } from 'node:path';
|
|
117
|
+
import { text as readAll } from 'node:stream/consumers';
|
|
118
|
+
import { parseArgs } from 'node:util';
|
|
119
|
+
import { applyChanges, readCurrent, readTree, requireDirectory, requireEmpty } from "./directory.js";
|
|
120
|
+
import { InputError, messageOf } from "./errors.js";
|
|
121
|
+
import { gitMergeFile, merge, render } from "./index.js";
|
|
122
|
+
import { DIRECTORY, MODE_TYPE, SYMLINK, } from "./types.js";
|
|
123
|
+
/** The exit codes. */
|
|
124
|
+
export const EXIT = { ok: 0, failed: 1, usage: 2, input: 3 };
|
|
125
|
+
const HELP = `plx-template: render templates into a directory, and merge a new render into a directory that has local edits.
|
|
126
|
+
|
|
127
|
+
Usage:
|
|
128
|
+
plx-template render [--answers <file|->] <output-dir> <template-dir>...
|
|
129
|
+
plx-template merge <old-dir> <new-dir> <target-dir>
|
|
130
|
+
plx-template <command> --help
|
|
131
|
+
|
|
132
|
+
render Renders the templates with the answers into <output-dir>, and writes the
|
|
133
|
+
policy of each path beside it.
|
|
134
|
+
merge Three-way merges what changed from <old-dir> to <new-dir>, two renders,
|
|
135
|
+
into <target-dir>, and prints what happened to each path.
|
|
136
|
+
|
|
137
|
+
Answers are JSON, from a file or from standard input. Standard output carries
|
|
138
|
+
only JSON; messages for people go to standard error.
|
|
139
|
+
The exit codes are:
|
|
140
|
+
0 done; a merge that left conflicts is done, its report says which
|
|
141
|
+
1 failed: the command could not read or write, or git is missing; nothing on
|
|
142
|
+
standard output
|
|
143
|
+
2 a usage error: an unknown command or option, a missing argument; nothing on
|
|
144
|
+
standard output
|
|
145
|
+
3 an error in the inputs, each listed in the JSON and on standard error
|
|
146
|
+
`;
|
|
147
|
+
const RENDER_HELP = `Usage: plx-template render [--answers <file|->] <output-dir> <template-dir>...
|
|
148
|
+
|
|
149
|
+
Renders the templates, which are rendered together as one, into <output-dir>.
|
|
150
|
+
<output-dir> must be empty or missing, and is created. Beside it, in
|
|
151
|
+
<output-dir>.plx-template.json, the command writes the owner and policy of each
|
|
152
|
+
path, which \`merge\` reads; nothing is written when the render has errors.
|
|
153
|
+
Render into a directory of its own: the policies file lands beside it, in the
|
|
154
|
+
parent of \`.\` or of a temporary directory, and an existing one is overwritten.
|
|
155
|
+
|
|
156
|
+
--answers <file|-> A JSON object of answers, from a file or, with -, from
|
|
157
|
+
standard input. Without it there are none: the command
|
|
158
|
+
never asks.
|
|
159
|
+
|
|
160
|
+
Standard output is one JSON object:
|
|
161
|
+
answers the resolved answers, defaults of new questions included
|
|
162
|
+
unused the names of given answers no template owns or reads
|
|
163
|
+
files each rendered path with its template and policy
|
|
164
|
+
birth the birth commands the templates declare, never run: { template, command }
|
|
165
|
+
errors every error: { message, template?, path?, question?, other? }
|
|
166
|
+
|
|
167
|
+
Exit codes: 0 rendered; 1 failed; 2 usage error (1 and 2 print nothing on
|
|
168
|
+
standard output); 3 errors in the inputs, which are listed under errors and on
|
|
169
|
+
standard error, with nothing written.
|
|
170
|
+
`;
|
|
171
|
+
const MERGE_HELP = `Usage: plx-template merge <old-dir> <new-dir> <target-dir>
|
|
172
|
+
|
|
173
|
+
Takes two renders, <old-dir> and <new-dir>, as \`render\` wrote them with their
|
|
174
|
+
<dir>.plx-template.json files beside them, and merges what the template changed
|
|
175
|
+
into <target-dir>, which is edited in place. A conflict stays in the file as
|
|
176
|
+
markers; a file the template removed and the user edited is kept.
|
|
177
|
+
|
|
178
|
+
Standard output is one JSON object:
|
|
179
|
+
report one entry per path touched: { path, outcome }, in path order, the
|
|
180
|
+
outcome one of clean, added, deleted, conflicted or kept
|
|
181
|
+
errors instead of report, where the inputs are wrong: { message, path? }
|
|
182
|
+
|
|
183
|
+
Exit codes: 0 merged, also when conflicts are left; 1 failed; 2 usage error (1 and
|
|
184
|
+
2 print nothing on standard output); 3 errors in the inputs, such as a missing policies file, listed under errors
|
|
185
|
+
and on standard error, with nothing written.
|
|
186
|
+
`;
|
|
187
|
+
class UsageError extends Error {
|
|
188
|
+
}
|
|
189
|
+
const POLICIES = ['merge', 'born-once'];
|
|
190
|
+
/** Runs steps that may fail with an input error, keeping each failure, so that a command reports them all. */
|
|
191
|
+
function collector() {
|
|
192
|
+
const problems = [];
|
|
193
|
+
const attempt = async (step) => {
|
|
194
|
+
try {
|
|
195
|
+
return await step();
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
if (!(error instanceof InputError))
|
|
199
|
+
throw error;
|
|
200
|
+
problems.push(error.path === undefined ? { message: error.message } : { message: error.message, path: error.path });
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
/** Whether `step` passed, for a step that gives nothing. */
|
|
204
|
+
const holds = async (step) => (await attempt(() => step().then(() => true))) === true;
|
|
205
|
+
return { problems, attempt, holds };
|
|
206
|
+
}
|
|
207
|
+
/** Where `render` writes the policies of the render in `dir`: beside it, so that no file of the render is one it did not render. */
|
|
208
|
+
export const policiesOf = (dir) => `${resolve(dir)}.plx-template.json`;
|
|
209
|
+
/** Writes `value` as JSON to standard output. */
|
|
210
|
+
function print(value) {
|
|
211
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
212
|
+
}
|
|
213
|
+
/** Prints each error to standard error, with what it concerns. */
|
|
214
|
+
function complain(errors) {
|
|
215
|
+
for (const e of errors) {
|
|
216
|
+
const about = [
|
|
217
|
+
e.template && `template ${e.template}`,
|
|
218
|
+
e.path && `path ${e.path}`,
|
|
219
|
+
e.question && `question ${e.question}`,
|
|
220
|
+
e.other && `other template ${e.other}`,
|
|
221
|
+
].filter(Boolean);
|
|
222
|
+
process.stderr.write(`plx-template: error: ${e.message}${about.length > 0 ? ` (${about.join(', ')})` : ''}\n`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/** The JSON of `path`, read by `read`; what goes wrong is an input error about `what`, with `hint` after a failed read. */
|
|
226
|
+
async function readJson(read, path, what, hint = '') {
|
|
227
|
+
let text;
|
|
228
|
+
try {
|
|
229
|
+
text = await read();
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
throw new InputError(`cannot read the ${what}: ${messageOf(error)}${hint}`, path);
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
return JSON.parse(text);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
throw new InputError(`the ${what} is no JSON: ${messageOf(error)}`, path);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/** The answers: a JSON object from `source`, a file or, for `-`, standard input; none without one. */
|
|
242
|
+
async function readAnswers(source) {
|
|
243
|
+
if (source === undefined)
|
|
244
|
+
return {};
|
|
245
|
+
const answers = await readJson(() => (source === '-' ? readAll(process.stdin) : readFile(source, 'utf8')), source, 'answers');
|
|
246
|
+
if (!isObject(answers))
|
|
247
|
+
throw new InputError('the answers are not a JSON object', source);
|
|
248
|
+
return answers;
|
|
249
|
+
}
|
|
250
|
+
/** The version of the policies file `render` writes and `merge` reads. */
|
|
251
|
+
const POLICIES_VERSION = 1;
|
|
252
|
+
/** The policies `render` wrote beside the render in `dir`, which holds `tree`; each way it can be wrong is an input error. */
|
|
253
|
+
async function readPolicies(dir, tree) {
|
|
254
|
+
const file = policiesOf(dir);
|
|
255
|
+
const fail = (what) => {
|
|
256
|
+
throw new InputError(`the policies file ${what}`, file);
|
|
257
|
+
};
|
|
258
|
+
const parsed = await readJson(() => readFile(file, 'utf8'), file, 'policies file', '; `render` writes one beside the render it writes');
|
|
259
|
+
if (!isObject(parsed))
|
|
260
|
+
return fail('is not a JSON object with a version and files');
|
|
261
|
+
if (parsed.version === undefined)
|
|
262
|
+
return fail('has no version');
|
|
263
|
+
if (parsed.version !== POLICIES_VERSION)
|
|
264
|
+
return fail(`is version ${String(parsed.version)}, and this plx-template reads version ${POLICIES_VERSION} only; was it written by a later plx-template?`);
|
|
265
|
+
if (!isObject(parsed.files))
|
|
266
|
+
return fail('has no files: a map of path to { template, policy }');
|
|
267
|
+
const files = Object.entries(parsed.files);
|
|
268
|
+
const bad = files.filter(([, v]) => !isObject(v) || !POLICIES.includes(v.policy)).map(([path]) => path);
|
|
269
|
+
if (bad.length > 0)
|
|
270
|
+
return fail(`gives no policy, merge or born-once, to ${bad.join(', ')}`);
|
|
271
|
+
const lacking = [...tree.keys()].filter((path) => !(path in parsed.files));
|
|
272
|
+
if (lacking.length > 0)
|
|
273
|
+
return fail(`lacks ${lacking.join(', ')}, which its render holds`);
|
|
274
|
+
const extra = files.map(([path]) => path).filter((path) => !tree.has(path));
|
|
275
|
+
if (extra.length > 0)
|
|
276
|
+
return fail(`names ${extra.join(', ')}, which its render does not hold`);
|
|
277
|
+
return new Map(files);
|
|
278
|
+
}
|
|
279
|
+
/** Whether `value` is a JSON object: not null, not a list. */
|
|
280
|
+
function isObject(value) {
|
|
281
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
282
|
+
}
|
|
283
|
+
/** The JSON a render prints: the core's result, but for its tree. */
|
|
284
|
+
function renderJson(result, errors) {
|
|
285
|
+
return {
|
|
286
|
+
answers: result?.answers ?? {},
|
|
287
|
+
unused: result?.unused ?? [],
|
|
288
|
+
files: Object.fromEntries(result?.files ?? []),
|
|
289
|
+
birth: result?.birth ?? [],
|
|
290
|
+
errors,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/** Prints `json` and each error, and says the inputs are wrong. */
|
|
294
|
+
function refuse(errors, json = { errors }) {
|
|
295
|
+
print(json);
|
|
296
|
+
complain(errors);
|
|
297
|
+
return EXIT.input;
|
|
298
|
+
}
|
|
299
|
+
/** A render directory as a tree with its policies; a symlink in it is an input error, for it is no render. */
|
|
300
|
+
async function readRender(dir, { problems, attempt }) {
|
|
301
|
+
const tree = await attempt(() => readTree(dir));
|
|
302
|
+
if (tree === undefined)
|
|
303
|
+
return undefined;
|
|
304
|
+
const links = [...tree].filter(([, e]) => (e.mode & MODE_TYPE) === SYMLINK).map(([path]) => join(dir, path));
|
|
305
|
+
for (const path of links)
|
|
306
|
+
problems.push({ message: 'is a symlink, and a render holds none', path });
|
|
307
|
+
if (links.length > 0)
|
|
308
|
+
return undefined;
|
|
309
|
+
const policies = await attempt(() => readPolicies(dir, tree));
|
|
310
|
+
return policies && { tree, policies };
|
|
311
|
+
}
|
|
312
|
+
async function mergeCommand(oldDir, newDir, target) {
|
|
313
|
+
const found = collector();
|
|
314
|
+
const { problems, attempt, holds } = found;
|
|
315
|
+
const [oldPath, newPath, targetPath] = [oldDir, newDir, target].map((dir) => resolve(dir));
|
|
316
|
+
if (oldPath === newPath)
|
|
317
|
+
problems.push({ message: 'the old and the new render are one directory', path: oldDir });
|
|
318
|
+
if (targetPath === oldPath || targetPath === newPath)
|
|
319
|
+
problems.push({ message: 'the target is one of the renders, which merge must not change', path: target });
|
|
320
|
+
const oldRender = await readRender(oldDir, found);
|
|
321
|
+
const newRender = await readRender(newDir, found);
|
|
322
|
+
const present = await holds(() => requireDirectory(target));
|
|
323
|
+
const current = present &&
|
|
324
|
+
oldRender &&
|
|
325
|
+
newRender &&
|
|
326
|
+
(await attempt(() => readCurrent(target, new Set([...oldRender.tree.keys(), ...newRender.tree.keys()]))));
|
|
327
|
+
if (!oldRender || !newRender || !current || problems.length > 0)
|
|
328
|
+
return refuse(problems);
|
|
329
|
+
const old = oldRender.tree;
|
|
330
|
+
const next = newRender.tree;
|
|
331
|
+
const oldPolicies = oldRender.policies;
|
|
332
|
+
const newPolicies = newRender.policies;
|
|
333
|
+
const { tree, report } = await merge({ old, new: next, current, files: { old: oldPolicies, new: newPolicies } }, gitMergeFile);
|
|
334
|
+
const changes = new Map();
|
|
335
|
+
for (const { path, outcome } of report) {
|
|
336
|
+
if (outcome === 'deleted')
|
|
337
|
+
changes.set(path, undefined);
|
|
338
|
+
else if (outcome !== 'kept' && tree.has(path))
|
|
339
|
+
changes.set(path, tree.get(path));
|
|
340
|
+
}
|
|
341
|
+
const directories = new Set([...next].filter(([, e]) => (e.mode & MODE_TYPE) === DIRECTORY).map(([path]) => path));
|
|
342
|
+
await applyChanges(target, changes, directories);
|
|
343
|
+
print({ report });
|
|
344
|
+
return EXIT.ok;
|
|
345
|
+
}
|
|
346
|
+
async function renderCommand(answersFile, out, templates) {
|
|
347
|
+
const { problems, attempt } = collector();
|
|
348
|
+
const answers = await attempt(() => readAnswers(answersFile));
|
|
349
|
+
const trees = [];
|
|
350
|
+
for (const dir of templates) {
|
|
351
|
+
const tree = await attempt(() => readTree(dir));
|
|
352
|
+
if (tree !== undefined)
|
|
353
|
+
trees.push(tree);
|
|
354
|
+
}
|
|
355
|
+
await attempt(() => requireEmpty(out));
|
|
356
|
+
const result = problems.length === 0 && answers !== undefined ? render(trees, answers) : undefined;
|
|
357
|
+
const errors = result === undefined ? problems : result.errors;
|
|
358
|
+
const json = renderJson(result, errors);
|
|
359
|
+
if (result === undefined || errors.length > 0)
|
|
360
|
+
return refuse(errors, json);
|
|
361
|
+
await applyChanges(out, result.tree);
|
|
362
|
+
await writeFile(policiesOf(out), `${JSON.stringify({ version: POLICIES_VERSION, files: json.files }, null, 2)}\n`);
|
|
363
|
+
print(json);
|
|
364
|
+
return EXIT.ok;
|
|
365
|
+
}
|
|
366
|
+
/** Runs the command `argv` names and returns its exit code. */
|
|
367
|
+
export async function main(argv) {
|
|
368
|
+
try {
|
|
369
|
+
const [command, ...rest] = argv;
|
|
370
|
+
if (command === undefined || command === '--help' || command === '-h') {
|
|
371
|
+
if (command === undefined)
|
|
372
|
+
throw new UsageError('no command');
|
|
373
|
+
process.stdout.write(HELP);
|
|
374
|
+
return EXIT.ok;
|
|
375
|
+
}
|
|
376
|
+
if (command === 'render' || command === 'merge') {
|
|
377
|
+
const { values, positionals } = parseArgs({
|
|
378
|
+
args: rest,
|
|
379
|
+
allowPositionals: true,
|
|
380
|
+
options: {
|
|
381
|
+
help: { type: 'boolean', short: 'h' },
|
|
382
|
+
...(command === 'render' ? { answers: { type: 'string' } } : {}),
|
|
383
|
+
},
|
|
384
|
+
});
|
|
385
|
+
if (values.help) {
|
|
386
|
+
process.stdout.write(command === 'render' ? RENDER_HELP : MERGE_HELP);
|
|
387
|
+
return EXIT.ok;
|
|
388
|
+
}
|
|
389
|
+
if (command === 'render') {
|
|
390
|
+
const [out, ...templates] = positionals;
|
|
391
|
+
if (out === undefined || templates.length === 0)
|
|
392
|
+
throw new UsageError('render takes an output directory and a template');
|
|
393
|
+
return await renderCommand(values.answers, out, templates);
|
|
394
|
+
}
|
|
395
|
+
const [oldDir, newDir, target, ...extra] = positionals;
|
|
396
|
+
if (oldDir === undefined || newDir === undefined || target === undefined || extra.length > 0)
|
|
397
|
+
throw new UsageError('merge takes three directories');
|
|
398
|
+
return await mergeCommand(oldDir, newDir, target);
|
|
399
|
+
}
|
|
400
|
+
throw new UsageError(`unknown command ${command}`);
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
const message = messageOf(error);
|
|
404
|
+
if (error instanceof UsageError || error.code?.startsWith('ERR_PARSE_ARGS')) {
|
|
405
|
+
process.stderr.write(`plx-template: ${message}\n(run with --help for usage)\n`);
|
|
406
|
+
return EXIT.usage;
|
|
407
|
+
}
|
|
408
|
+
process.stderr.write(`plx-template: ${message}\n`);
|
|
409
|
+
return EXIT.failed;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,8EAA8E;AAC9E,8EAA8E;AAC9E,gFAAgF;AAChF,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,mDAAmD;AACnD,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,uCAAuC;AACvC,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAC9E,+EAA+E;AAC/E,gFAAgF;AAChF,iFAAiF;AACjF,EAAE;AACF,wEAAwE;AACxE,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,0EAA0E;AAC1E,4EAA4E;AAC5E,uEAAuE;AACvE,iDAAiD;AACjD,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,sEAAsE;AACtE,sEAAsE;AACtE,4EAA4E;AAC5E,kGAAkG;AAClG,+EAA+E;AAC/E,wEAAwE;AACxE,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,2EAA2E;AAC3E,+EAA+E;AAC/E,6EAA6E;AAC7E,qEAAqE;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|
+
import { type Entry, type Tree } from './types.ts';
|
|
2
|
+
/** Whether `path` is a directory, an input error where it is not. */
|
|
3
|
+
export declare function requireDirectory(path: string): Promise<void>;
|
|
4
|
+
/** The tree of the directory `root`. */
|
|
5
|
+
export declare function readTree(root: string): Promise<Tree>;
|
|
6
|
+
/** The part of the directory `root` that `merge` looks at for `paths`, as the header says. */
|
|
7
|
+
export declare function readCurrent(root: string, paths: Iterable<string>): Promise<Tree>;
|
|
8
|
+
/**
|
|
9
|
+
* Makes `root` hold, at each path of `changes`, its entry, or nothing where it
|
|
10
|
+
* is `undefined`; the header says how. `keep` holds the paths of directories
|
|
11
|
+
* not to remove after a deletion.
|
|
12
|
+
*/
|
|
13
|
+
export declare function applyChanges(root: string, changes: ReadonlyMap<string, Entry | undefined>, keep?: ReadonlySet<string>): Promise<void>;
|
|
14
|
+
/** Whether `path` can take a render: missing, or a directory that holds nothing; an input error otherwise. */
|
|
15
|
+
export declare function requireEmpty(path: string): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":"AAmDA,OAAO,EAAa,KAAK,KAAK,EAA6C,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AA8BzG,qEAAqE;AACrE,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKlE;AAED,wCAAwC;AACxC,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK1D;AAiBD,8FAA8F;AAC9F,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBtF;AAqCD;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,GAAG,SAAS,CAAC,EAC/C,IAAI,GAAE,WAAW,CAAC,MAAM,CAAa,GACpC,OAAO,CAAC,IAAI,CAAC,CAUf;AA+BD,8GAA8G;AAC9G,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM9D"}
|