@clerc/plugin-strict-flags 0.44.0 → 1.0.0-beta.10
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 +5 -4
- package/dist/index.js +18 -54
- package/package.json +6 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Plugin } from "@clerc/core";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare const strictFlagsPlugin: () => Plugin;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { strictFlagsPlugin };
|
package/dist/index.js
CHANGED
|
@@ -1,58 +1,22 @@
|
|
|
1
|
-
import { definePlugin } from
|
|
1
|
+
import { definePlugin } from "@clerc/core";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
function semanticArray(arr, { add, t }) {
|
|
12
|
-
add(locales$1);
|
|
13
|
-
if (arr.length <= 1) {
|
|
14
|
-
return arr[0];
|
|
15
|
-
}
|
|
16
|
-
return t("utils.and", arr.slice(0, -1).join(", "), arr[arr.length - 1]);
|
|
3
|
+
//#region ../utils/src/index.ts
|
|
4
|
+
function joinWithAnd(values) {
|
|
5
|
+
if (values.length === 0) return "";
|
|
6
|
+
if (values.length === 1) return values[0];
|
|
7
|
+
const last = values.pop();
|
|
8
|
+
return `${values.join(", ")} and ${last}`;
|
|
17
9
|
}
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"strictFlags.and": "%s \u548C %s"
|
|
29
|
-
}
|
|
30
|
-
};
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/index.ts
|
|
13
|
+
const strictFlagsPlugin = () => definePlugin({ setup: (cli) => {
|
|
14
|
+
cli.interceptor(async (ctx, next) => {
|
|
15
|
+
const keys = Object.keys(ctx.rawParsed.unknown);
|
|
16
|
+
if (!ctx.resolved || keys.length === 0) await next();
|
|
17
|
+
else throw keys.length > 1 ? /* @__PURE__ */ new Error(`Unexpected flags: ${joinWithAnd(keys)}`) : /* @__PURE__ */ new Error(`Unexpected flag: ${keys[0]}`);
|
|
18
|
+
});
|
|
19
|
+
} });
|
|
31
20
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const { add, t } = cli.i18n;
|
|
35
|
-
add(locales);
|
|
36
|
-
return cli.interceptor((ctx, next) => {
|
|
37
|
-
const keys = Object.keys(ctx.unknownFlags);
|
|
38
|
-
if (!ctx.resolved || keys.length === 0) {
|
|
39
|
-
next();
|
|
40
|
-
} else {
|
|
41
|
-
const error = keys.length > 1 ? new Error(
|
|
42
|
-
t(
|
|
43
|
-
"strictFlags.unexpectedMore",
|
|
44
|
-
semanticArray(keys, cli.i18n)
|
|
45
|
-
)
|
|
46
|
-
) : new Error(
|
|
47
|
-
t(
|
|
48
|
-
"strictFlags.unexpectedSingle",
|
|
49
|
-
semanticArray(keys, cli.i18n)
|
|
50
|
-
)
|
|
51
|
-
);
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
export { strictFlagsPlugin };
|
|
21
|
+
//#endregion
|
|
22
|
+
export { strictFlagsPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-strict-flags",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.10",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc plugin strict flags",
|
|
@@ -25,13 +25,10 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"exports": {
|
|
28
|
-
".":
|
|
29
|
-
"types": "./dist/index.d.ts",
|
|
30
|
-
"import": "./dist/index.js"
|
|
31
|
-
}
|
|
28
|
+
".": "./dist/index.js"
|
|
32
29
|
},
|
|
33
|
-
"main": "dist/index.js",
|
|
34
|
-
"module": "dist/index.js",
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"module": "./dist/index.js",
|
|
35
32
|
"types": "dist/index.d.ts",
|
|
36
33
|
"typesVersions": {
|
|
37
34
|
"*": {
|
|
@@ -48,14 +45,10 @@
|
|
|
48
45
|
"access": "public"
|
|
49
46
|
},
|
|
50
47
|
"devDependencies": {
|
|
51
|
-
"@clerc/utils": "0.
|
|
52
|
-
"@clerc/core": "0.
|
|
48
|
+
"@clerc/utils": "1.0.0-beta.10",
|
|
49
|
+
"@clerc/core": "1.0.0-beta.10"
|
|
53
50
|
},
|
|
54
51
|
"peerDependencies": {
|
|
55
52
|
"@clerc/core": "*"
|
|
56
|
-
},
|
|
57
|
-
"scripts": {
|
|
58
|
-
"build": "pkgroll",
|
|
59
|
-
"watch": "pkgroll --watch"
|
|
60
53
|
}
|
|
61
54
|
}
|