@backstage-community/plugin-scaffolder-backend-module-regex 2.7.0 → 2.7.1

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,5 +1,11 @@
1
1
  ### Dependencies
2
2
 
3
+ ## 2.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - d73ba40: Adding regex:replace examples
8
+
3
9
  ## 2.7.0
4
10
 
5
11
  ### Minor Changes
@@ -1,12 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
4
- var yaml = require('yaml');
5
4
  var zod = require('zod');
6
-
7
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
8
-
9
- var yaml__default = /*#__PURE__*/_interopDefaultCompat(yaml);
5
+ var replace_example = require('./replace.example.cjs.js');
10
6
 
11
7
  const schemaInput = zod.z.object({
12
8
  regExps: zod.z.array(
@@ -40,114 +36,12 @@ const schemaInput = zod.z.object({
40
36
  })
41
37
  )
42
38
  });
43
- const exampleValue = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?";
44
39
  const id = "regex:replace";
45
- const examples = [
46
- {
47
- description: "Create a regex to capture the first word of a string",
48
- example: yaml__default.default.stringify({
49
- steps: [
50
- {
51
- id: "regexValues",
52
- action: id,
53
- name: "Regex Values",
54
- input: {
55
- regExps: [
56
- {
57
- pattern: "^(\\S+).*$",
58
- replacement: "$1",
59
- values: [
60
- { key: "eg1", value: "Hello world!" },
61
- { key: "eg2", value: "Test world!" }
62
- ]
63
- }
64
- ]
65
- }
66
- }
67
- ]
68
- })
69
- },
70
- {
71
- description: "Create a regex to replace a word in a string",
72
- example: yaml__default.default.stringify({
73
- steps: [
74
- {
75
- id: "regexValues",
76
- action: id,
77
- name: "Regex Values",
78
- input: {
79
- regExps: [
80
- {
81
- pattern: "dog",
82
- replacement: "monkey",
83
- values: [
84
- {
85
- key: "eg1",
86
- value: exampleValue
87
- }
88
- ]
89
- },
90
- {
91
- pattern: "Dog",
92
- replacement: "ferret",
93
- flags: ["i"],
94
- values: [
95
- {
96
- key: "eg2",
97
- value: exampleValue
98
- }
99
- ]
100
- }
101
- ]
102
- }
103
- }
104
- ]
105
- })
106
- },
107
- {
108
- description: "Create a regex to replace a word globally in a string",
109
- example: yaml__default.default.stringify({
110
- steps: [
111
- {
112
- id: "regexValues",
113
- action: id,
114
- name: "Regex Values",
115
- input: {
116
- regExps: [
117
- {
118
- pattern: "dog",
119
- replacement: "monkey",
120
- flags: ["g"],
121
- values: [
122
- {
123
- key: "eg1",
124
- value: exampleValue
125
- }
126
- ]
127
- },
128
- {
129
- pattern: "Dog",
130
- replacement: "ferret",
131
- flags: ["gi"],
132
- values: [
133
- {
134
- key: "eg2",
135
- value: exampleValue
136
- }
137
- ]
138
- }
139
- ]
140
- }
141
- }
142
- ]
143
- })
144
- }
145
- ];
146
40
  const createReplaceAction = () => {
147
41
  return pluginScaffolderNode.createTemplateAction({
148
42
  id,
149
43
  description: "Replaces strings that match a regular expression pattern with a specified replacement string",
150
- examples,
44
+ examples: replace_example.examples,
151
45
  schema: {
152
46
  input: schemaInput
153
47
  },
@@ -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 yaml from 'yaml';\nimport { z } from 'zod';\n\nconst schemaInput = z.object({\n regExps: 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\nconst exampleValue =\n 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';\n\nconst id = 'regex:replace';\n\nconst examples = [\n {\n description: 'Create a regex to capture the first word of a string',\n example: yaml.stringify({\n steps: [\n {\n id: 'regexValues',\n action: id,\n name: 'Regex Values',\n input: {\n regExps: [\n {\n pattern: '^(\\\\S+).*$',\n replacement: '$1',\n values: [\n { key: 'eg1', value: 'Hello world!' },\n { key: 'eg2', value: 'Test world!' },\n ],\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description: 'Create a regex to replace a word in a string',\n example: yaml.stringify({\n steps: [\n {\n id: 'regexValues',\n action: id,\n name: 'Regex Values',\n input: {\n regExps: [\n {\n pattern: 'dog',\n replacement: 'monkey',\n values: [\n {\n key: 'eg1',\n value: exampleValue,\n },\n ],\n },\n {\n pattern: 'Dog',\n replacement: 'ferret',\n flags: ['i'],\n values: [\n {\n key: 'eg2',\n value: exampleValue,\n },\n ],\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description: 'Create a regex to replace a word globally in a string',\n example: yaml.stringify({\n steps: [\n {\n id: 'regexValues',\n action: id,\n name: 'Regex Values',\n input: {\n regExps: [\n {\n pattern: 'dog',\n replacement: 'monkey',\n flags: ['g'],\n values: [\n {\n key: 'eg1',\n value: exampleValue,\n },\n ],\n },\n {\n pattern: 'Dog',\n replacement: 'ferret',\n flags: ['gi'],\n values: [\n {\n key: 'eg2',\n value: exampleValue,\n },\n ],\n },\n ],\n },\n },\n ],\n }),\n },\n];\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: schemaInput,\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":["z","yaml","createTemplateAction"],"mappings":";;;;;;;;;;AAoBA,MAAM,WAAA,GAAcA,MAAE,MAAO,CAAA;AAAA,EAC3B,SAASA,KAAE,CAAA,KAAA;AAAA,IACTA,MAAE,MAAO,CAAA;AAAA,MACP,OAAA,EAASA,KACN,CAAA,MAAA,EACA,CAAA,MAAA;AAAA;AAAA;AAAA;AAAA,QAIC,CAAA,KAAA,KAAS,CAAC,KAAM,CAAA,UAAA,CAAW,GAAG,CAAK,IAAA,CAAC,KAAM,CAAA,QAAA,CAAS,GAAG,CAAA;AAAA,QACtD;AAAA,UACE,OACE,EAAA;AAAA;AACJ,OAED,CAAA,QAAA;AAAA,QACC;AAAA,OACF;AAAA,MACF,OAAOA,KACJ,CAAA,KAAA;AAAA;AAAA,QAECA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B,GACD,CAAA;AACH;;;;"}
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 { z } from 'zod';\n\nimport { examples } from './replace.example';\n\nconst schemaInput = z.object({\n regExps: 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\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: schemaInput,\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":["z","createTemplateAction","examples"],"mappings":";;;;;;AAqBA,MAAM,WAAA,GAAcA,MAAE,MAAO,CAAA;AAAA,EAC3B,SAASA,KAAE,CAAA,KAAA;AAAA,IACTA,MAAE,MAAO,CAAA;AAAA,MACP,OAAA,EAASA,KACN,CAAA,MAAA,EACA,CAAA,MAAA;AAAA;AAAA;AAAA;AAAA,QAIC,CAAA,KAAA,KAAS,CAAC,KAAM,CAAA,UAAA,CAAW,GAAG,CAAK,IAAA,CAAC,KAAM,CAAA,QAAA,CAAS,GAAG,CAAA;AAAA,QACtD;AAAA,UACE,OACE,EAAA;AAAA;AACJ,OAED,CAAA,QAAA;AAAA,QACC;AAAA,OACF;AAAA,MACF,OAAOA,KACJ,CAAA,KAAA;AAAA;AAAA,QAECA,KAAA,CAAE,IAAK,CAAA,CAAC,GAAK,EAAA,GAAA,EAAK,KAAK,GAAK,EAAA,GAAA,EAAK,GAAK,EAAA,GAAG,CAAG,EAAA;AAAA,UAC1C,kBACE,EAAA;AAAA,SACH;AAAA,OAEF,CAAA,QAAA,EACA,CAAA,QAAA,CAAS,yBAAyB,CAAA;AAAA,MACrC,WAAA,EAAaA,KACV,CAAA,MAAA,EACA,CAAA,QAAA;AAAA,QACC;AAAA,OACF;AAAA,MACF,QAAQA,KAAE,CAAA,KAAA;AAAA,QACRA,MAAE,MAAO,CAAA;AAAA,UACP,GAAK,EAAAA,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,mCAAmC,CAAA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AAA;AAC7B,GACD,CAAA;AACH;;;;"}
@@ -0,0 +1,114 @@
1
+ 'use strict';
2
+
3
+ var yaml = require('yaml');
4
+
5
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
6
+
7
+ var yaml__default = /*#__PURE__*/_interopDefaultCompat(yaml);
8
+
9
+ const exampleValue = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?";
10
+ const id = "regex:replace";
11
+ const examples = [
12
+ {
13
+ description: "Create a regex to capture the first word of a string",
14
+ example: yaml__default.default.stringify({
15
+ steps: [
16
+ {
17
+ id: "regexValues",
18
+ action: id,
19
+ name: "Regex Values",
20
+ input: {
21
+ regExps: [
22
+ {
23
+ pattern: "^(\\S+).*$",
24
+ replacement: "$1",
25
+ values: [
26
+ { key: "eg1", value: "Hello world!" },
27
+ { key: "eg2", value: "Test world!" }
28
+ ]
29
+ }
30
+ ]
31
+ }
32
+ }
33
+ ]
34
+ })
35
+ },
36
+ {
37
+ description: "Create a regex to replace a word in a string",
38
+ example: yaml__default.default.stringify({
39
+ steps: [
40
+ {
41
+ id: "regexValues",
42
+ action: id,
43
+ name: "Regex Values",
44
+ input: {
45
+ regExps: [
46
+ {
47
+ pattern: "dog",
48
+ replacement: "monkey",
49
+ values: [
50
+ {
51
+ key: "eg1",
52
+ value: exampleValue
53
+ }
54
+ ]
55
+ },
56
+ {
57
+ pattern: "Dog",
58
+ replacement: "ferret",
59
+ flags: ["i"],
60
+ values: [
61
+ {
62
+ key: "eg2",
63
+ value: exampleValue
64
+ }
65
+ ]
66
+ }
67
+ ]
68
+ }
69
+ }
70
+ ]
71
+ })
72
+ },
73
+ {
74
+ description: "Create a regex to replace a word globally in a string",
75
+ example: yaml__default.default.stringify({
76
+ steps: [
77
+ {
78
+ id: "regexValues",
79
+ action: id,
80
+ name: "Regex Values",
81
+ input: {
82
+ regExps: [
83
+ {
84
+ pattern: "dog",
85
+ replacement: "monkey",
86
+ flags: ["g"],
87
+ values: [
88
+ {
89
+ key: "eg1",
90
+ value: exampleValue
91
+ }
92
+ ]
93
+ },
94
+ {
95
+ pattern: "Dog",
96
+ replacement: "ferret",
97
+ flags: ["gi"],
98
+ values: [
99
+ {
100
+ key: "eg2",
101
+ value: exampleValue
102
+ }
103
+ ]
104
+ }
105
+ ]
106
+ }
107
+ }
108
+ ]
109
+ })
110
+ }
111
+ ];
112
+
113
+ exports.examples = examples;
114
+ //# sourceMappingURL=replace.example.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replace.example.cjs.js","sources":["../../../src/actions/regex/replace.example.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\n\nimport { TemplateExample } from '@backstage/plugin-scaffolder-node';\n\nimport yaml from 'yaml';\n\nconst exampleValue =\n 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';\n\nconst id = 'regex:replace';\n\nexport const examples: TemplateExample[] = [\n {\n description: 'Create a regex to capture the first word of a string',\n example: yaml.stringify({\n steps: [\n {\n id: 'regexValues',\n action: id,\n name: 'Regex Values',\n input: {\n regExps: [\n {\n pattern: '^(\\\\S+).*$',\n replacement: '$1',\n values: [\n { key: 'eg1', value: 'Hello world!' },\n { key: 'eg2', value: 'Test world!' },\n ],\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description: 'Create a regex to replace a word in a string',\n example: yaml.stringify({\n steps: [\n {\n id: 'regexValues',\n action: id,\n name: 'Regex Values',\n input: {\n regExps: [\n {\n pattern: 'dog',\n replacement: 'monkey',\n values: [\n {\n key: 'eg1',\n value: exampleValue,\n },\n ],\n },\n {\n pattern: 'Dog',\n replacement: 'ferret',\n flags: ['i'],\n values: [\n {\n key: 'eg2',\n value: exampleValue,\n },\n ],\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description: 'Create a regex to replace a word globally in a string',\n example: yaml.stringify({\n steps: [\n {\n id: 'regexValues',\n action: id,\n name: 'Regex Values',\n input: {\n regExps: [\n {\n pattern: 'dog',\n replacement: 'monkey',\n flags: ['g'],\n values: [\n {\n key: 'eg1',\n value: exampleValue,\n },\n ],\n },\n {\n pattern: 'Dog',\n replacement: 'ferret',\n flags: ['gi'],\n values: [\n {\n key: 'eg2',\n value: exampleValue,\n },\n ],\n },\n ],\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAoBA,MAAM,YACJ,GAAA,sFAAA;AAEF,MAAM,EAAK,GAAA,eAAA;AAEJ,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WAAa,EAAA,sDAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,aAAA;AAAA,UACJ,MAAQ,EAAA,EAAA;AAAA,UACR,IAAM,EAAA,cAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA;AAAA,cACP;AAAA,gBACE,OAAS,EAAA,YAAA;AAAA,gBACT,WAAa,EAAA,IAAA;AAAA,gBACb,MAAQ,EAAA;AAAA,kBACN,EAAE,GAAA,EAAK,KAAO,EAAA,KAAA,EAAO,cAAe,EAAA;AAAA,kBACpC,EAAE,GAAA,EAAK,KAAO,EAAA,KAAA,EAAO,aAAc;AAAA;AACrC;AACF;AACF;AACF;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAa,EAAA,8CAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,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EAAA;AAAA;AACT;AACF;AACF;AACF;AACF;AACF;AACF,KACD;AAAA;AAEL;;;;"}
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ declare const createReplaceAction: () => _backstage_plugin_scaffolder_node.Templ
12
12
  }[];
13
13
  pattern: string;
14
14
  replacement: string;
15
- flags?: ("g" | "m" | "i" | "y" | "u" | "s" | "d")[] | undefined;
15
+ flags?: ("i" | "g" | "m" | "y" | "u" | "s" | "d")[] | undefined;
16
16
  }[];
17
17
  }, any, "v1">;
18
18
 
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.7.0",
4
+ "version": "2.7.1",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "Apache-2.0",