@roadiehq/scaffolder-backend-module-utils 3.3.0 → 3.4.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.
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
4
|
+
var fg = require('fast-glob');
|
|
4
5
|
var fs = require('fs-extra');
|
|
5
6
|
var errors = require('@backstage/errors');
|
|
6
7
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
7
8
|
|
|
8
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
10
|
|
|
11
|
+
var fg__default = /*#__PURE__*/_interopDefaultCompat(fg);
|
|
10
12
|
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
11
13
|
|
|
12
14
|
function createReplaceInFileAction() {
|
|
@@ -29,7 +31,7 @@ function createReplaceInFileAction() {
|
|
|
29
31
|
properties: {
|
|
30
32
|
file: {
|
|
31
33
|
type: "string",
|
|
32
|
-
title: "The source location of the file to be used to run replace against"
|
|
34
|
+
title: "The source location of the file to be used to run replace against (supports wildcards)"
|
|
33
35
|
},
|
|
34
36
|
find: {
|
|
35
37
|
type: "string",
|
|
@@ -66,13 +68,19 @@ function createReplaceInFileAction() {
|
|
|
66
68
|
ctx.workspacePath,
|
|
67
69
|
file.file
|
|
68
70
|
);
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
const resolvedSourcePaths = await fg__default.default(sourceFilepath, {
|
|
72
|
+
cwd: ctx.workspacePath,
|
|
73
|
+
absolute: true
|
|
74
|
+
});
|
|
75
|
+
for (const filepath of resolvedSourcePaths) {
|
|
76
|
+
const content = fs__default.default.readFileSync(filepath).toString();
|
|
77
|
+
let find = file.find;
|
|
78
|
+
if (file.matchRegex) {
|
|
79
|
+
find = new RegExp(file.find, "g");
|
|
80
|
+
}
|
|
81
|
+
const replacedContent = content.replaceAll(find, file.replaceWith);
|
|
82
|
+
fs__default.default.writeFileSync(filepath, replacedContent);
|
|
73
83
|
}
|
|
74
|
-
const replacedContent = content.replaceAll(find, file.replaceWith);
|
|
75
|
-
fs__default.default.writeFileSync(sourceFilepath, replacedContent);
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replaceInFile.cjs.js","sources":["../../../src/actions/fs/replaceInFile.ts"],"sourcesContent":["/*\n * Copyright 2021 Larder Software Limited\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 { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport { InputError } from '@backstage/errors';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { TemplateAction } from '@backstage/plugin-scaffolder-node';\n\nexport function createReplaceInFileAction(): TemplateAction<{\n files: Array<{\n file: string;\n find: string;\n matchRegex: boolean;\n replaceWith: string;\n }>;\n}> {\n return createTemplateAction<{\n files: Array<{\n file: string;\n find: string;\n matchRegex: boolean;\n replaceWith: string;\n }>;\n }>({\n id: 'roadiehq:utils:fs:replace',\n description: 'Replaces content of a file with given values.',\n supportsDryRun: true,\n schema: {\n input: {\n required: ['files'],\n type: 'object',\n properties: {\n files: {\n title: 'Files',\n description: 'A list of files and replacements to be done',\n type: 'array',\n items: {\n type: 'object',\n required: [],\n properties: {\n file: {\n type: 'string',\n title:\n 'The source location of the file to be used to run replace against',\n },\n find: {\n type: 'string',\n title: 'A string to be replaced',\n },\n matchRegex: {\n type: 'bool',\n title: 'Use regex to match the find string',\n },\n replaceWith: {\n type: 'string',\n title: 'Text to be used to replace the found lines with',\n },\n },\n },\n },\n },\n },\n },\n async handler(ctx) {\n if (!Array.isArray(ctx.input?.files)) {\n throw new InputError('files must be an Array');\n }\n\n for (const file of ctx.input.files) {\n if (!file.file) {\n throw new InputError('Path to file needs to be defined');\n }\n if (!file.find || !file.replaceWith) {\n throw new InputError(\n 'each file must have a find and replaceWith property',\n );\n }\n\n const sourceFilepath = resolveSafeChildPath(\n ctx.workspacePath,\n file.file,\n );\n const content: string = fs.readFileSync(
|
|
1
|
+
{"version":3,"file":"replaceInFile.cjs.js","sources":["../../../src/actions/fs/replaceInFile.ts"],"sourcesContent":["/*\n * Copyright 2021 Larder Software Limited\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 { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport fg from 'fast-glob';\nimport fs from 'fs-extra';\nimport { InputError } from '@backstage/errors';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { TemplateAction } from '@backstage/plugin-scaffolder-node';\n\nexport function createReplaceInFileAction(): TemplateAction<{\n files: Array<{\n file: string;\n find: string;\n matchRegex: boolean;\n replaceWith: string;\n }>;\n}> {\n return createTemplateAction<{\n files: Array<{\n file: string;\n find: string;\n matchRegex: boolean;\n replaceWith: string;\n }>;\n }>({\n id: 'roadiehq:utils:fs:replace',\n description: 'Replaces content of a file with given values.',\n supportsDryRun: true,\n schema: {\n input: {\n required: ['files'],\n type: 'object',\n properties: {\n files: {\n title: 'Files',\n description: 'A list of files and replacements to be done',\n type: 'array',\n items: {\n type: 'object',\n required: [],\n properties: {\n file: {\n type: 'string',\n title:\n 'The source location of the file to be used to run replace against (supports wildcards)',\n },\n find: {\n type: 'string',\n title: 'A string to be replaced',\n },\n matchRegex: {\n type: 'bool',\n title: 'Use regex to match the find string',\n },\n replaceWith: {\n type: 'string',\n title: 'Text to be used to replace the found lines with',\n },\n },\n },\n },\n },\n },\n },\n async handler(ctx) {\n if (!Array.isArray(ctx.input?.files)) {\n throw new InputError('files must be an Array');\n }\n\n for (const file of ctx.input.files) {\n if (!file.file) {\n throw new InputError('Path to file needs to be defined');\n }\n if (!file.find || !file.replaceWith) {\n throw new InputError(\n 'each file must have a find and replaceWith property',\n );\n }\n\n const sourceFilepath = resolveSafeChildPath(\n ctx.workspacePath,\n file.file,\n );\n\n const resolvedSourcePaths = await fg(sourceFilepath, {\n cwd: ctx.workspacePath,\n absolute: true,\n });\n\n for (const filepath of resolvedSourcePaths) {\n const content: string = fs.readFileSync(filepath).toString();\n\n let find: string | RegExp = file.find;\n if (file.matchRegex) {\n find = new RegExp(file.find, 'g');\n }\n\n const replacedContent = content.replaceAll(find, file.replaceWith);\n\n fs.writeFileSync(filepath, replacedContent);\n }\n }\n },\n });\n}\n"],"names":["createTemplateAction","InputError","resolveSafeChildPath","fg","fs"],"mappings":";;;;;;;;;;;;;AAuBO,SAAS,yBAOb,GAAA;AACD,EAAA,OAAOA,yCAOJ,CAAA;AAAA,IACD,EAAI,EAAA,2BAAA;AAAA,IACJ,WAAa,EAAA,+CAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,QAAA,EAAU,CAAC,OAAO,CAAA;AAAA,QAClB,IAAM,EAAA,QAAA;AAAA,QACN,UAAY,EAAA;AAAA,UACV,KAAO,EAAA;AAAA,YACL,KAAO,EAAA,OAAA;AAAA,YACP,WAAa,EAAA,6CAAA;AAAA,YACb,IAAM,EAAA,OAAA;AAA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MAAW,YAAY,mBAAqB,EAAA;AAC1C,UAAA,MAAM,OAAkB,GAAAC,mBAAA,CAAG,YAAa,CAAA,QAAQ,EAAE,QAAS,EAAA;AAE3D,UAAA,IAAI,OAAwB,IAAK,CAAA,IAAA;AACjC,UAAA,IAAI,KAAK,UAAY,EAAA;AACnB,YAAA,IAAA,GAAO,IAAI,MAAA,CAAO,IAAK,CAAA,IAAA,EAAM,GAAG,CAAA;AAAA;AAGlC,UAAA,MAAM,eAAkB,GAAA,OAAA,CAAQ,UAAW,CAAA,IAAA,EAAM,KAAK,WAAW,CAAA;AAEjE,UAAGA,mBAAA,CAAA,aAAA,CAAc,UAAU,eAAe,CAAA;AAAA;AAC5C;AACF;AACF,GACD,CAAA;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roadiehq/scaffolder-backend-module-utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"main": "./dist/index.cjs.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -61,28 +61,25 @@
|
|
|
61
61
|
"@backstage/errors": "^1.2.5",
|
|
62
62
|
"@backstage/plugin-scaffolder-node": "^0.6.2",
|
|
63
63
|
"adm-zip": "^0.5.9",
|
|
64
|
-
"cross-fetch": "^3.1.4",
|
|
65
64
|
"detect-indent": "^6.1.0",
|
|
65
|
+
"fast-glob": "^3.3.3",
|
|
66
66
|
"fs-extra": "^10.0.0",
|
|
67
67
|
"jsonata": "^2.0.4",
|
|
68
68
|
"lodash": "^4.17.21",
|
|
69
|
-
"winston": "^3.2.1",
|
|
70
69
|
"yaml": "^2.6.1",
|
|
71
70
|
"yawn-yaml": "^2.3.0"
|
|
72
71
|
},
|
|
73
72
|
"devDependencies": {
|
|
74
73
|
"@backstage/backend-common": "^0.25.0",
|
|
75
|
-
"@backstage/backend-test-utils": "^1.1.0",
|
|
76
74
|
"@backstage/cli": "^0.29.2",
|
|
77
75
|
"@testing-library/jest-dom": "^6.4.2",
|
|
78
76
|
"@types/adm-zip": "^0.4.34",
|
|
79
77
|
"@types/fs-extra": "^9.0.13",
|
|
80
|
-
"@types/js-yaml": "^4.0.0",
|
|
81
78
|
"@types/mock-fs": "^4.13.1",
|
|
82
79
|
"mock-fs": "^5.1.2"
|
|
83
80
|
},
|
|
84
81
|
"files": [
|
|
85
82
|
"dist"
|
|
86
83
|
],
|
|
87
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "a8b3ad71ae4c3c1da2aeab2412f07ee5c3287152"
|
|
88
85
|
}
|