@backstage-community/plugin-scaffolder-backend-module-regex 2.7.1 → 2.9.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/CHANGELOG.md
CHANGED
|
@@ -1,41 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
4
|
-
var zod = require('zod');
|
|
5
4
|
var replace_example = require('./replace.example.cjs.js');
|
|
6
5
|
|
|
7
|
-
const schemaInput = zod.z.object({
|
|
8
|
-
regExps: zod.z.array(
|
|
9
|
-
zod.z.object({
|
|
10
|
-
pattern: zod.z.string().refine(
|
|
11
|
-
// You should not parse a regex (regular language) with a regex (regular language),
|
|
12
|
-
// you actually need a context free grammar to parse a regex (regular language).
|
|
13
|
-
// Hence, we are using a string comparison here.
|
|
14
|
-
(value) => !value.startsWith("/") && !value.endsWith("/"),
|
|
15
|
-
{
|
|
16
|
-
message: "The RegExp constructor cannot take a string pattern with a leading and trailing forward slash."
|
|
17
|
-
}
|
|
18
|
-
).describe(
|
|
19
|
-
"The regex pattern to match the value like in String.prototype.replace()"
|
|
20
|
-
),
|
|
21
|
-
flags: zod.z.array(
|
|
22
|
-
// Prefer array over set here because input values are normally defined in YAML which doesn't support Sets.
|
|
23
|
-
zod.z.enum(["g", "m", "i", "y", "u", "s", "d"], {
|
|
24
|
-
invalid_type_error: "Invalid flag, possible values are: g, m, i, y, u, s, d"
|
|
25
|
-
})
|
|
26
|
-
).optional().describe("The flags for the regex"),
|
|
27
|
-
replacement: zod.z.string().describe(
|
|
28
|
-
"The replacement value for the regex like in String.prototype.replace()"
|
|
29
|
-
),
|
|
30
|
-
values: zod.z.array(
|
|
31
|
-
zod.z.object({
|
|
32
|
-
key: zod.z.string().describe("The key to access the regex value"),
|
|
33
|
-
value: zod.z.string().describe("The input value of the regex")
|
|
34
|
-
})
|
|
35
|
-
)
|
|
36
|
-
})
|
|
37
|
-
)
|
|
38
|
-
});
|
|
39
6
|
const id = "regex:replace";
|
|
40
7
|
const createReplaceAction = () => {
|
|
41
8
|
return pluginScaffolderNode.createTemplateAction({
|
|
@@ -43,7 +10,38 @@ const createReplaceAction = () => {
|
|
|
43
10
|
description: "Replaces strings that match a regular expression pattern with a specified replacement string",
|
|
44
11
|
examples: replace_example.examples,
|
|
45
12
|
schema: {
|
|
46
|
-
input:
|
|
13
|
+
input: {
|
|
14
|
+
regExps: (z) => z.array(
|
|
15
|
+
z.object({
|
|
16
|
+
pattern: z.string().refine(
|
|
17
|
+
// You should not parse a regex (regular language) with a regex (regular language),
|
|
18
|
+
// you actually need a context free grammar to parse a regex (regular language).
|
|
19
|
+
// Hence, we are using a string comparison here.
|
|
20
|
+
(value) => !value.startsWith("/") && !value.endsWith("/"),
|
|
21
|
+
{
|
|
22
|
+
message: "The RegExp constructor cannot take a string pattern with a leading and trailing forward slash."
|
|
23
|
+
}
|
|
24
|
+
).describe(
|
|
25
|
+
"The regex pattern to match the value like in String.prototype.replace()"
|
|
26
|
+
),
|
|
27
|
+
flags: z.array(
|
|
28
|
+
// Prefer array over set here because input values are normally defined in YAML which doesn't support Sets.
|
|
29
|
+
z.enum(["g", "m", "i", "y", "u", "s", "d"], {
|
|
30
|
+
invalid_type_error: "Invalid flag, possible values are: g, m, i, y, u, s, d"
|
|
31
|
+
})
|
|
32
|
+
).optional().describe("The flags for the regex"),
|
|
33
|
+
replacement: z.string().describe(
|
|
34
|
+
"The replacement value for the regex like in String.prototype.replace()"
|
|
35
|
+
),
|
|
36
|
+
values: z.array(
|
|
37
|
+
z.object({
|
|
38
|
+
key: z.string().describe("The key to access the regex value"),
|
|
39
|
+
value: z.string().describe("The input value of the regex")
|
|
40
|
+
})
|
|
41
|
+
)
|
|
42
|
+
})
|
|
43
|
+
)
|
|
44
|
+
}
|
|
47
45
|
},
|
|
48
46
|
async handler(ctx) {
|
|
49
47
|
const input = ctx.input;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace.cjs.js","sources":["../../../src/actions/regex/replace.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\n\nimport {
|
|
1
|
+
{"version":3,"file":"replace.cjs.js","sources":["../../../src/actions/regex/replace.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\n\nimport { examples } from './replace.example';\n\nconst id = 'regex:replace';\n\n/**\n * @public\n */\nexport const createReplaceAction = () => {\n return createTemplateAction({\n id,\n description:\n 'Replaces strings that match a regular expression pattern with a specified replacement string',\n examples,\n schema: {\n input: {\n regExps: z =>\n z.array(\n z.object({\n pattern: z\n .string()\n .refine(\n // You should not parse a regex (regular language) with a regex (regular language),\n // you actually need a context free grammar to parse a regex (regular language).\n // Hence, we are using a string comparison here.\n value => !value.startsWith('/') && !value.endsWith('/'),\n {\n message:\n 'The RegExp constructor cannot take a string pattern with a leading and trailing forward slash.',\n },\n )\n .describe(\n 'The regex pattern to match the value like in String.prototype.replace()',\n ),\n flags: z\n .array(\n // Prefer array over set here because input values are normally defined in YAML which doesn't support Sets.\n z.enum(['g', 'm', 'i', 'y', 'u', 's', 'd'], {\n invalid_type_error:\n 'Invalid flag, possible values are: g, m, i, y, u, s, d',\n }),\n )\n .optional()\n .describe('The flags for the regex'),\n replacement: z\n .string()\n .describe(\n 'The replacement value for the regex like in String.prototype.replace()',\n ),\n values: z.array(\n z.object({\n key: z.string().describe('The key to access the regex value'),\n value: z.string().describe('The input value of the regex'),\n }),\n ),\n }),\n ),\n },\n },\n\n async handler(ctx) {\n const input = ctx.input;\n\n const values: Record<string, string> = {};\n\n for (const {\n pattern,\n flags: flagsInput,\n replacement,\n values: valuesInput,\n } of input.regExps) {\n // remove duplicates from the flags input array\n const flags = flagsInput\n ? Array.from(new Set(flagsInput)).join('')\n : '';\n const regex = new RegExp(pattern, flags);\n\n for (const { key, value } of valuesInput) {\n const match = value.replace(regex, replacement);\n\n if (values.hasOwnProperty(key)) {\n throw new Error(\n `The key '${key}' is used more than once in the input.`,\n );\n }\n\n values[key] = match;\n }\n }\n\n ctx.output('values', values);\n },\n });\n};\n"],"names":["createTemplateAction","examples"],"mappings":";;;;;AAmBA,MAAM,EAAK,GAAA,eAAA;AAKJ,MAAM,sBAAsB,MAAM;AACvC,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAA;AAAA,IACA,WACE,EAAA,8FAAA;AAAA,cACFC,wBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,OAAA,EAAS,OACP,CAAE,CAAA,KAAA;AAAA,UACA,EAAE,MAAO,CAAA;AAAA,YACP,OAAA,EAAS,CACN,CAAA,MAAA,EACA,CAAA,MAAA;AAAA;AAAA;AAAA;AAAA,cAIC,CAAA,KAAA,KAAS,CAAC,KAAM,CAAA,UAAA,CAAW,GAAG,CAAK,IAAA,CAAC,KAAM,CAAA,QAAA,CAAS,GAAG,CAAA;AAAA,cACtD;AAAA,gBACE,OACE,EAAA;AAAA;AACJ,aAED,CA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AQ,CAAA,KAAA,EAAO,WAAW,CAAA;AAE9C,UAAI,IAAA,MAAA,CAAO,cAAe,CAAA,GAAG,CAAG,EAAA;AAC9B,YAAA,MAAM,IAAI,KAAA;AAAA,cACR,YAAY,GAAG,CAAA,sCAAA;AAAA,aACjB;AAAA;AAGF,UAAA,MAAA,CAAO,GAAG,CAAI,GAAA,KAAA;AAAA;AAChB;AAGF,MAAI,GAAA,CAAA,MAAA,CAAO,UAAU,MAAM,CAAA;AAAA;AAC7B,GACD,CAAA;AACH;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,9 @@ declare const createReplaceAction: () => _backstage_plugin_scaffolder_node.Templ
|
|
|
14
14
|
replacement: string;
|
|
15
15
|
flags?: ("i" | "g" | "m" | "y" | "u" | "s" | "d")[] | undefined;
|
|
16
16
|
}[];
|
|
17
|
-
},
|
|
17
|
+
}, {
|
|
18
|
+
[x: string]: any;
|
|
19
|
+
}, "v2">;
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* @public
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage-community/plugin-scaffolder-backend-module-regex",
|
|
3
3
|
"description": "The regex custom actions",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.9.0",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -46,14 +46,13 @@
|
|
|
46
46
|
"prettier:fix": "prettier --ignore-unknown --write ."
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@backstage/backend-plugin-api": "^1.
|
|
50
|
-
"@backstage/plugin-scaffolder-node": "^0.
|
|
51
|
-
"yaml": "^2.3.3"
|
|
52
|
-
"zod": "^3.22.4"
|
|
49
|
+
"@backstage/backend-plugin-api": "^1.4.2",
|
|
50
|
+
"@backstage/plugin-scaffolder-node": "^0.11.0",
|
|
51
|
+
"yaml": "^2.3.3"
|
|
53
52
|
},
|
|
54
53
|
"devDependencies": {
|
|
55
|
-
"@backstage/cli": "^0.
|
|
56
|
-
"@backstage/plugin-scaffolder-node-test-utils": "^0.
|
|
54
|
+
"@backstage/cli": "^0.34.1",
|
|
55
|
+
"@backstage/plugin-scaffolder-node-test-utils": "^0.3.2"
|
|
57
56
|
},
|
|
58
57
|
"files": [
|
|
59
58
|
"dist",
|