@reventlessdev/reventless-spec 3.0.0-alpha.143 → 3.0.0-alpha.144
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/CHANGELOG.md +13 -0
- package/package.json +2 -2
- package/run-certify-trait.mjs +2 -1
- package/run-generator.mjs +2 -1
- package/run-graft-trait.mjs +2 -1
- package/run-platform-generator.mjs +2 -1
- package/run-trait-manifest.mjs +2 -1
- package/src/CliArgs.res +209 -0
- package/src/CliArgs.res.mjs +325 -0
- package/src/generator/CertifyTrait.res +96 -93
- package/src/generator/CertifyTrait.res.mjs +92 -75
- package/src/generator/GraftTrait.res +147 -148
- package/src/generator/GraftTrait.res.mjs +131 -128
- package/src/generator/PlatformGenerator.res +50 -31
- package/src/generator/PlatformGenerator.res.mjs +107 -76
- package/src/generator/PluginGenerator.res +29 -29
- package/src/generator/PluginGenerator.res.mjs +87 -55
- package/src/generator/TraitManifestCli.res +69 -68
- package/src/generator/TraitManifestCli.res.mjs +67 -51
- package/src/lifecycle/CheckLifecycleModel.res +203 -189
- package/src/lifecycle/CheckLifecycleModel.res.mjs +146 -141
- package/src/types/PrepareAccounts.res +38 -57
- package/src/types/PrepareAccounts.res.mjs +28 -82
|
@@ -7,8 +7,10 @@ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
|
7
7
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
8
8
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
9
9
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
10
|
+
import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
|
|
10
11
|
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
11
12
|
import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
|
|
13
|
+
import * as CliArgs$Reventless from "../CliArgs.res.mjs";
|
|
12
14
|
import * as Nodechild_process from "node:child_process";
|
|
13
15
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
14
16
|
import * as ComponentKind$Reventless from "../components/ComponentKind.res.mjs";
|
|
@@ -20,25 +22,36 @@ let repoRoot = process.cwd();
|
|
|
20
22
|
|
|
21
23
|
let examplesDir = Nodepath.join(repoRoot, "examples");
|
|
22
24
|
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return
|
|
25
|
+
let usage = `Usage: check-lifecycle [--root <dir>]... [--update] [--reuse-sidecars] [--json]
|
|
26
|
+
|
|
27
|
+
--root <dir> an app whose plugins are checked together; repeatable.
|
|
28
|
+
Without one, every directory under ./examples
|
|
29
|
+
--update rewrite the goldens and the models instead of comparing
|
|
30
|
+
--reuse-sidecars read the scenario sidecars a prior build wrote instead of
|
|
31
|
+
building with REVENTLESS_EMIT_SIDECAR=1
|
|
32
|
+
--json report as one JSON document on stdout; writes and
|
|
33
|
+
compares nothing
|
|
34
|
+
|
|
35
|
+
Contradictions, drift and unreadable plugins exit 1.`;
|
|
36
|
+
|
|
37
|
+
function parseArgs(argv) {
|
|
38
|
+
return Stdlib_Result.map(Stdlib_Result.flatMap(CliArgs$Reventless.parse(undefined, [
|
|
39
|
+
"update",
|
|
40
|
+
"reuse-sidecars",
|
|
41
|
+
"json"
|
|
42
|
+
], ["root"], undefined, argv), CliArgs$Reventless.noPositionals), a => ({
|
|
43
|
+
update: CliArgs$Reventless.bool(a, "update"),
|
|
44
|
+
roots: CliArgs$Reventless.strings(a, "root"),
|
|
45
|
+
reuseSidecars: CliArgs$Reventless.bool(a, "reuse-sidecars"),
|
|
46
|
+
json: CliArgs$Reventless.bool(a, "json")
|
|
47
|
+
}));
|
|
37
48
|
}
|
|
38
49
|
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
let cli = {
|
|
51
|
+
bin: "check-lifecycle",
|
|
52
|
+
usage: usage,
|
|
53
|
+
parse: parseArgs
|
|
54
|
+
};
|
|
42
55
|
|
|
43
56
|
let noRow = "(none)";
|
|
44
57
|
|
|
@@ -685,40 +698,28 @@ function pluginDirsIn(exampleDir) {
|
|
|
685
698
|
});
|
|
686
699
|
}
|
|
687
700
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
roots = given.map(given => {
|
|
699
|
-
let dir = Nodepath.resolve(given);
|
|
700
|
-
return {
|
|
701
|
-
label: Nodepath.basename(dir),
|
|
702
|
-
dir: dir
|
|
703
|
-
};
|
|
704
|
-
});
|
|
705
|
-
} else {
|
|
706
|
-
let exit = 0;
|
|
701
|
+
function rootsOf(given) {
|
|
702
|
+
if (given.length !== 0) {
|
|
703
|
+
return given.map(given => {
|
|
704
|
+
let dir = Nodepath.resolve(given);
|
|
705
|
+
return {
|
|
706
|
+
label: Nodepath.basename(dir),
|
|
707
|
+
dir: dir
|
|
708
|
+
};
|
|
709
|
+
});
|
|
710
|
+
}
|
|
707
711
|
let entries;
|
|
708
712
|
try {
|
|
709
713
|
entries = Nodefs.readdirSync(examplesDir, {
|
|
710
714
|
withFileTypes: true
|
|
711
715
|
});
|
|
712
|
-
exit = 1;
|
|
713
716
|
} catch (exn) {
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
if (exit === 1) {
|
|
717
|
-
roots = entries.filter(e => e.isDirectory()).map(e => e.name).toSorted(Primitive_string.compare).map(name => ({
|
|
718
|
-
label: name,
|
|
719
|
-
dir: Nodepath.join(examplesDir, name)
|
|
720
|
-
}));
|
|
717
|
+
return [];
|
|
721
718
|
}
|
|
719
|
+
return entries.filter(e => e.isDirectory()).map(e => e.name).toSorted(Primitive_string.compare).map(name => ({
|
|
720
|
+
label: name,
|
|
721
|
+
dir: Nodepath.join(examplesDir, name)
|
|
722
|
+
}));
|
|
722
723
|
}
|
|
723
724
|
|
|
724
725
|
function kindOfPath(path) {
|
|
@@ -1115,7 +1116,7 @@ function modelPath(pluginDir) {
|
|
|
1115
1116
|
return Nodepath.join(pluginDir, "src", "LifecycleModel.res");
|
|
1116
1117
|
}
|
|
1117
1118
|
|
|
1118
|
-
function writeOrCompare(path, actual, label, drifted) {
|
|
1119
|
+
function writeOrCompare(update, path, actual, label, drifted) {
|
|
1119
1120
|
let existed = Nodefs.existsSync(path);
|
|
1120
1121
|
if (update || !existed) {
|
|
1121
1122
|
Nodefs.writeFileSync(path, actual, "utf8");
|
|
@@ -1132,113 +1133,117 @@ function writeOrCompare(path, actual, label, drifted) {
|
|
|
1132
1133
|
}
|
|
1133
1134
|
}
|
|
1134
1135
|
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
let
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
let
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
let
|
|
1169
|
-
if (
|
|
1170
|
-
let
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1136
|
+
function main() {
|
|
1137
|
+
return CliArgs$Reventless.run(cli, undefined, undefined, async param => {
|
|
1138
|
+
let json = param.json;
|
|
1139
|
+
let update = param.update;
|
|
1140
|
+
let roots = rootsOf(param.roots);
|
|
1141
|
+
let findings = [];
|
|
1142
|
+
let opaque = [];
|
|
1143
|
+
let outcomes = [];
|
|
1144
|
+
let failures = [];
|
|
1145
|
+
let drifted = [];
|
|
1146
|
+
let allDerived = [];
|
|
1147
|
+
let allPluginDirs = roots.flatMap(root => pluginDirsIn(root.dir));
|
|
1148
|
+
if (allPluginDirs.length === 0) {
|
|
1149
|
+
console.error(`no plugins found under ` + roots.map(r => r.dir).join(", ") + ` — a plugin is a directory with both src/Plugin.res and tests/`);
|
|
1150
|
+
process.exit(1);
|
|
1151
|
+
}
|
|
1152
|
+
let msg = param.reuseSidecars ? checkSidecars(allPluginDirs) : emitSidecars(allPluginDirs);
|
|
1153
|
+
if (msg.TAG !== "Ok") {
|
|
1154
|
+
console.error(msg._0);
|
|
1155
|
+
process.exit(1);
|
|
1156
|
+
}
|
|
1157
|
+
if (!hasCorpus(allPluginDirs)) {
|
|
1158
|
+
console.error(`no scenario sidecar exists under ` + roots.map(r => r.dir).join(", ") + ` after the build. Build that tree with REVENTLESS_EMIT_SIDECAR=1 and pass --reuse-sidecars.`);
|
|
1159
|
+
process.exit(1);
|
|
1160
|
+
}
|
|
1161
|
+
for (let i = 0, i_finish = roots.length; i < i_finish; ++i) {
|
|
1162
|
+
let root = roots[i];
|
|
1163
|
+
if (root !== undefined) {
|
|
1164
|
+
let example = root.label;
|
|
1165
|
+
let exampleDir = root.dir;
|
|
1166
|
+
let derived = [];
|
|
1167
|
+
let dirs = pluginDirsIn(exampleDir);
|
|
1168
|
+
for (let j = 0, j_finish = dirs.length; j < j_finish; ++j) {
|
|
1169
|
+
let pluginDir = dirs[j];
|
|
1170
|
+
if (pluginDir !== undefined) {
|
|
1171
|
+
let plugin = Nodepath.basename(pluginDir);
|
|
1172
|
+
let qualified = example + `/` + plugin;
|
|
1173
|
+
let commands = await runPlugin(qualified, pluginDir, findings, opaque, outcomes);
|
|
1174
|
+
if (commands.TAG === "Ok") {
|
|
1175
|
+
let commands$1 = commands._0;
|
|
1176
|
+
commands$1.forEach(c => {
|
|
1177
|
+
derived.push(c);
|
|
1178
|
+
allDerived.push([
|
|
1179
|
+
qualified,
|
|
1180
|
+
c
|
|
1181
|
+
]);
|
|
1182
|
+
});
|
|
1183
|
+
if (!json) {
|
|
1184
|
+
writeOrCompare(update, modelPath(pluginDir), modelSource(plugin, commands$1), example + `/` + plugin + `/src/LifecycleModel.res`, drifted);
|
|
1185
|
+
}
|
|
1186
|
+
} else {
|
|
1187
|
+
failures.push(example + `/` + plugin + `: ` + commands._0);
|
|
1180
1188
|
}
|
|
1181
|
-
} else {
|
|
1182
|
-
failures.push(example + `/` + plugin + `: ` + commands._0);
|
|
1183
1189
|
}
|
|
1184
1190
|
}
|
|
1191
|
+
if (dirs.length !== 0 && !json) {
|
|
1192
|
+
let dir = Nodepath.join(exampleDir, "schema");
|
|
1193
|
+
if (!Nodefs.existsSync(dir)) {
|
|
1194
|
+
Nodefs.mkdirSync(dir, {
|
|
1195
|
+
recursive: true
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
writeOrCompare(update, goldenPath(root), goldenJson(derived), example + `/schema/lifecycle-model.json`, drifted);
|
|
1199
|
+
console.log(`ok ` + example + ` — ` + derived.length.toString() + ` commands derived from scenarios`);
|
|
1200
|
+
}
|
|
1185
1201
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1202
|
+
}
|
|
1203
|
+
let of_ = severity => findings.filter(f => f.severity === severity);
|
|
1204
|
+
let contradicted = of_("contradicted");
|
|
1205
|
+
if (json) {
|
|
1206
|
+
console.log(reportJson(findings, opaque, allDerived, outcomes, failures));
|
|
1207
|
+
} else {
|
|
1208
|
+
[
|
|
1209
|
+
"contradicted",
|
|
1210
|
+
"unverified",
|
|
1211
|
+
"undeclared",
|
|
1212
|
+
"level",
|
|
1213
|
+
"ambiguous"
|
|
1214
|
+
].forEach(severity => {
|
|
1215
|
+
let group = of_(severity);
|
|
1216
|
+
if (group.length !== 0) {
|
|
1217
|
+
console.log(`\n` + severity + ` (` + group.length.toString() + `)`);
|
|
1218
|
+
group.forEach(f => {
|
|
1219
|
+
console.log(` ` + f.message);
|
|
1191
1220
|
});
|
|
1221
|
+
return;
|
|
1192
1222
|
}
|
|
1193
|
-
|
|
1194
|
-
console.log(`ok ` + example + ` — ` + derived.length.toString() + ` commands derived from scenarios`);
|
|
1195
|
-
}
|
|
1223
|
+
});
|
|
1196
1224
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
if (group.length !== 0) {
|
|
1212
|
-
console.log(`\n` + severity + ` (` + group.length.toString() + `)`);
|
|
1213
|
-
group.forEach(f => {
|
|
1214
|
-
console.log(` ` + f.message);
|
|
1215
|
-
});
|
|
1216
|
-
return;
|
|
1217
|
-
}
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
if (failures.length !== 0 && !json) {
|
|
1221
|
-
console.error(`\ncould not read:`);
|
|
1222
|
-
failures.forEach(f => {
|
|
1223
|
-
console.error(` ` + f);
|
|
1224
|
-
});
|
|
1225
|
-
}
|
|
1226
|
-
if (drifted.length !== 0) {
|
|
1227
|
-
console.error(`\n` + drifted.length.toString() + ` lifecycle artifact(s) changed. If the change is intended, re-run with --update and commit them alongside the change that moved them.`);
|
|
1228
|
-
}
|
|
1229
|
-
if (contradicted.length !== 0 || drifted.length !== 0 || failures.length !== 0) {
|
|
1230
|
-
process.exit(1);
|
|
1231
|
-
return;
|
|
1232
|
-
}
|
|
1225
|
+
if (failures.length !== 0 && !json) {
|
|
1226
|
+
console.error(`\ncould not read:`);
|
|
1227
|
+
failures.forEach(f => {
|
|
1228
|
+
console.error(` ` + f);
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
if (drifted.length !== 0) {
|
|
1232
|
+
console.error(`\n` + drifted.length.toString() + ` lifecycle artifact(s) changed. If the change is intended, re-run with --update and commit them alongside the change that moved them.`);
|
|
1233
|
+
}
|
|
1234
|
+
if (contradicted.length !== 0 || drifted.length !== 0 || failures.length !== 0) {
|
|
1235
|
+
process.exit(1);
|
|
1236
|
+
return;
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1233
1239
|
}
|
|
1234
1240
|
|
|
1235
1241
|
export {
|
|
1236
1242
|
repoRoot,
|
|
1237
1243
|
examplesDir,
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
json,
|
|
1244
|
+
usage,
|
|
1245
|
+
parseArgs,
|
|
1246
|
+
cli,
|
|
1242
1247
|
noRow,
|
|
1243
1248
|
asObj,
|
|
1244
1249
|
getStr,
|
|
@@ -1278,7 +1283,7 @@ export {
|
|
|
1278
1283
|
allUnverified,
|
|
1279
1284
|
compare,
|
|
1280
1285
|
pluginDirsIn,
|
|
1281
|
-
|
|
1286
|
+
rootsOf,
|
|
1282
1287
|
kindOfPath,
|
|
1283
1288
|
isViewPath,
|
|
1284
1289
|
isWritablePath,
|
|
@@ -30,29 +30,14 @@ type args = {
|
|
|
30
30
|
help: bool,
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
let parseArgs = (argv: array<string>): result<args, string> =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
while i.contents < count {
|
|
38
|
-
let flag = argv->Array.getUnsafe(i.contents)
|
|
39
|
-
let value = argv->Array.get(i.contents + 1)
|
|
40
|
-
switch (acc.contents, flag, value) {
|
|
41
|
-
| (Error(_), _, _) => i := count
|
|
42
|
-
| (Ok(a), "--file", Some(v)) =>
|
|
43
|
-
acc := Ok({...a, file: Some(v)})
|
|
44
|
-
i := i.contents + 2
|
|
45
|
-
| (Ok(a), "--help", _) | (Ok(a), "-h", _) =>
|
|
46
|
-
acc := Ok({...a, help: true})
|
|
47
|
-
i := i.contents + 1
|
|
48
|
-
| (Ok(_), "--file", None) => acc := Error(`${flag} needs a value`)
|
|
49
|
-
| (Ok(_), unknown, _) => acc := Error(`unknown argument "${unknown}"`)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
acc.contents
|
|
53
|
-
}
|
|
33
|
+
let parseArgs = (argv: array<string>): result<args, string> =>
|
|
34
|
+
CliArgs.parse(~strings=["file"], argv)
|
|
35
|
+
->Result.flatMap(CliArgs.noPositionals)
|
|
36
|
+
->Result.map(a => {file: a->CliArgs.string("file"), help: a->CliArgs.help})
|
|
54
37
|
|
|
55
38
|
let usage = `
|
|
39
|
+
Usage: prepare-accounts [--file <path>]
|
|
40
|
+
|
|
56
41
|
Make a platform's accounts manifest ready to use.
|
|
57
42
|
|
|
58
43
|
--file <path> The manifest. Defaults to .reventless/users.yaml relative to the
|
|
@@ -77,43 +62,39 @@ let castNote = (entries: array<AccountsManifest.entry>): string =>
|
|
|
77
62
|
)
|
|
78
63
|
->Array.join("\n")
|
|
79
64
|
|
|
80
|
-
let run = (): result<unit, string> =>
|
|
81
|
-
|
|
82
|
-
switch parseArgs(NodeProcess.argv->Array.slice(~start=2, ~end=NodeProcess.argv->Array.length)) {
|
|
65
|
+
let run = (args: args): result<unit, string> =>
|
|
66
|
+
switch AccountsManifest.locate(~given=?args.file, ()) {
|
|
83
67
|
| Error(_) as e => e
|
|
84
|
-
| Ok(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
->Array.length
|
|
104
|
-
->Int.toString} declared, ${generated->Int.toString} password(s) generated\n\n${castNote(
|
|
105
|
-
prepared->Array.map(p => p.entry),
|
|
106
|
-
)}`,
|
|
107
|
-
)
|
|
108
|
-
Ok()
|
|
109
|
-
}
|
|
68
|
+
| Ok(located) =>
|
|
69
|
+
let file = located->AccountsManifest.pathOf
|
|
70
|
+
switch located {
|
|
71
|
+
| SeededFrom(_, template) => Console.log(`manifest ${file} (new, copied from ${template})`)
|
|
72
|
+
| Declared(_) => Console.log(`manifest ${file}`)
|
|
73
|
+
}
|
|
74
|
+
switch AccountsManifest.prepare(~path=file) {
|
|
75
|
+
| Error(message) => Error(`${file}: ${message}`)
|
|
76
|
+
| Ok([]) => Error(`${file} declares no accounts`)
|
|
77
|
+
| Ok(prepared) =>
|
|
78
|
+
let generated = prepared->Array.filter(p => p.passwordGenerated)->Array.length
|
|
79
|
+
Console.log(
|
|
80
|
+
`accounts ${prepared
|
|
81
|
+
->Array.length
|
|
82
|
+
->Int.toString} declared, ${generated->Int.toString} password(s) generated\n\n${castNote(
|
|
83
|
+
prepared->Array.map(p => p.entry),
|
|
84
|
+
)}`,
|
|
85
|
+
)
|
|
86
|
+
Ok()
|
|
110
87
|
}
|
|
111
88
|
}
|
|
112
89
|
|
|
113
|
-
let
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
90
|
+
let cli: CliArgs.cli<args> = {bin: "prepare-accounts", usage, parse: parseArgs}
|
|
91
|
+
|
|
92
|
+
let main = () =>
|
|
93
|
+
CliArgs.run(cli, async args =>
|
|
94
|
+
switch run(args) {
|
|
95
|
+
| Ok() => ()
|
|
96
|
+
| Error(message) =>
|
|
97
|
+
Console.error(`prepare-accounts: ${message}`)
|
|
98
|
+
NodeProcess.exit(1)
|
|
99
|
+
}
|
|
100
|
+
)
|
|
@@ -1,70 +1,19 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
|
|
4
|
+
import * as CliArgs$Reventless from "../CliArgs.res.mjs";
|
|
3
5
|
import * as AccountsManifest$Reventless from "./AccountsManifest.res.mjs";
|
|
4
6
|
|
|
5
7
|
function parseArgs(argv) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
help: false
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
let i = 0;
|
|
14
|
-
let count = argv.length;
|
|
15
|
-
while (i < count) {
|
|
16
|
-
let flag = argv[i];
|
|
17
|
-
let value = argv[i + 1 | 0];
|
|
18
|
-
let match = acc;
|
|
19
|
-
if (match.TAG === "Ok") {
|
|
20
|
-
let a = match._0;
|
|
21
|
-
let exit = 0;
|
|
22
|
-
switch (flag) {
|
|
23
|
-
case "--file" :
|
|
24
|
-
if (value !== undefined) {
|
|
25
|
-
acc = {
|
|
26
|
-
TAG: "Ok",
|
|
27
|
-
_0: {
|
|
28
|
-
file: value,
|
|
29
|
-
help: a.help
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
i = i + 2 | 0;
|
|
33
|
-
} else {
|
|
34
|
-
acc = {
|
|
35
|
-
TAG: "Error",
|
|
36
|
-
_0: flag + ` needs a value`
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
break;
|
|
40
|
-
case "--help" :
|
|
41
|
-
case "-h" :
|
|
42
|
-
exit = 1;
|
|
43
|
-
break;
|
|
44
|
-
default:
|
|
45
|
-
acc = {
|
|
46
|
-
TAG: "Error",
|
|
47
|
-
_0: `unknown argument "` + flag + `"`
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (exit === 1) {
|
|
51
|
-
acc = {
|
|
52
|
-
TAG: "Ok",
|
|
53
|
-
_0: {
|
|
54
|
-
file: a.file,
|
|
55
|
-
help: true
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
i = i + 1 | 0;
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
i = count;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
return acc;
|
|
8
|
+
return Stdlib_Result.map(Stdlib_Result.flatMap(CliArgs$Reventless.parse(["file"], undefined, undefined, undefined, argv), CliArgs$Reventless.noPositionals), a => ({
|
|
9
|
+
file: CliArgs$Reventless.string(a, "file"),
|
|
10
|
+
help: CliArgs$Reventless.help(a)
|
|
11
|
+
}));
|
|
65
12
|
}
|
|
66
13
|
|
|
67
14
|
let usage = `
|
|
15
|
+
Usage: prepare-accounts [--file <path>]
|
|
16
|
+
|
|
68
17
|
Make a platform's accounts manifest ready to use.
|
|
69
18
|
|
|
70
19
|
--file <path> The manifest. Defaults to .reventless/users.yaml relative to the
|
|
@@ -83,24 +32,12 @@ function castNote(entries) {
|
|
|
83
32
|
)).join("\n");
|
|
84
33
|
}
|
|
85
34
|
|
|
86
|
-
function run() {
|
|
87
|
-
let e =
|
|
35
|
+
function run(args) {
|
|
36
|
+
let e = AccountsManifest$Reventless.locate(args.file, undefined);
|
|
88
37
|
if (e.TAG !== "Ok") {
|
|
89
38
|
return e;
|
|
90
39
|
}
|
|
91
|
-
let
|
|
92
|
-
if (args.help) {
|
|
93
|
-
console.log(usage);
|
|
94
|
-
return {
|
|
95
|
-
TAG: "Ok",
|
|
96
|
-
_0: undefined
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
let e$1 = AccountsManifest$Reventless.locate(args.file, undefined);
|
|
100
|
-
if (e$1.TAG !== "Ok") {
|
|
101
|
-
return e$1;
|
|
102
|
-
}
|
|
103
|
-
let located = e$1._0;
|
|
40
|
+
let located = e._0;
|
|
104
41
|
let file = AccountsManifest$Reventless.pathOf(located);
|
|
105
42
|
if (located.TAG === "Declared") {
|
|
106
43
|
console.log(`manifest ` + file);
|
|
@@ -129,13 +66,21 @@ function run() {
|
|
|
129
66
|
};
|
|
130
67
|
}
|
|
131
68
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
69
|
+
let cli = {
|
|
70
|
+
bin: "prepare-accounts",
|
|
71
|
+
usage: usage,
|
|
72
|
+
parse: parseArgs
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function main() {
|
|
76
|
+
return CliArgs$Reventless.run(cli, undefined, undefined, async args => {
|
|
77
|
+
let message = run(args);
|
|
78
|
+
if (message.TAG === "Ok") {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
console.error(`prepare-accounts: ` + message._0);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
});
|
|
139
84
|
}
|
|
140
85
|
|
|
141
86
|
export {
|
|
@@ -143,6 +88,7 @@ export {
|
|
|
143
88
|
usage,
|
|
144
89
|
castNote,
|
|
145
90
|
run,
|
|
91
|
+
cli,
|
|
146
92
|
main,
|
|
147
93
|
}
|
|
148
|
-
/*
|
|
94
|
+
/* CliArgs-Reventless Not a pure module */
|