@ttoss/cloudformation 0.9.4 → 0.9.6
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/esm/index.js +8 -59
- package/dist/{index.d.mts → index.d.cts} +2 -6
- package/dist/index.d.ts +2 -6
- package/dist/index.js +13 -60
- package/package.json +5 -5
- package/src/findAndReadCloudFormationTemplate.ts +6 -6
- package/src/index.ts +0 -5
- package/src/readObjectFile.ts +0 -45
package/dist/esm/index.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
var __require = /* @__PURE__ */(x => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
-
}) : x)(function (x) {
|
|
5
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
2
|
|
|
9
3
|
// src/findAndReadCloudFormationTemplate.ts
|
|
10
|
-
import * as
|
|
4
|
+
import * as fs2 from "fs";
|
|
11
5
|
import * as path2 from "path";
|
|
12
6
|
|
|
13
7
|
// src/readCloudFormationYamlTemplate.ts
|
|
@@ -167,77 +161,32 @@ var readCloudFormationYamlTemplate = ({
|
|
|
167
161
|
return parsed;
|
|
168
162
|
};
|
|
169
163
|
|
|
170
|
-
// src/readObjectFile.ts
|
|
171
|
-
import fs2 from "fs";
|
|
172
|
-
import yaml2 from "js-yaml";
|
|
173
|
-
var readYaml = ({
|
|
174
|
-
path: path3
|
|
175
|
-
}) => {
|
|
176
|
-
const template = fs2.readFileSync(path3, "utf8") || JSON.stringify({});
|
|
177
|
-
return yaml2.load(template);
|
|
178
|
-
};
|
|
179
|
-
var readObjectFile = ({
|
|
180
|
-
path: path3
|
|
181
|
-
}) => {
|
|
182
|
-
if (!fs2.existsSync(path3)) {
|
|
183
|
-
return {};
|
|
184
|
-
}
|
|
185
|
-
const extension = path3.split(".").pop();
|
|
186
|
-
if (extension === "ts") {
|
|
187
|
-
__require("ts-node").register({
|
|
188
|
-
compilerOptions: {
|
|
189
|
-
moduleResolution: "node",
|
|
190
|
-
module: "commonjs"
|
|
191
|
-
},
|
|
192
|
-
moduleTypes: {
|
|
193
|
-
"carlin.*": "cjs"
|
|
194
|
-
},
|
|
195
|
-
transpileOnly: true
|
|
196
|
-
});
|
|
197
|
-
const tsObj = __require(path3);
|
|
198
|
-
const obj = tsObj.default || tsObj;
|
|
199
|
-
return typeof obj === "function" ? obj() : obj;
|
|
200
|
-
}
|
|
201
|
-
if (extension === "js") {
|
|
202
|
-
const obj = __require(path3);
|
|
203
|
-
return typeof obj === "function" ? obj() : obj;
|
|
204
|
-
}
|
|
205
|
-
if (extension === "json") {
|
|
206
|
-
return __require(path3);
|
|
207
|
-
}
|
|
208
|
-
if (extension === "yml" || extension === "yaml") {
|
|
209
|
-
return readYaml({
|
|
210
|
-
path: path3
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
return {};
|
|
214
|
-
};
|
|
215
|
-
|
|
216
164
|
// src/findAndReadCloudFormationTemplate.ts
|
|
165
|
+
import { readConfigFile } from "@ttoss/read-config-file";
|
|
217
166
|
var defaultTemplatePaths = ["ts", "js", "yaml", "yml", "json"].map(extension => {
|
|
218
167
|
return `./src/cloudformation.${extension}`;
|
|
219
168
|
});
|
|
220
|
-
var findAndReadCloudFormationTemplate = ({
|
|
169
|
+
var findAndReadCloudFormationTemplate = async ({
|
|
221
170
|
templatePath: defaultTemplatePath
|
|
222
171
|
}) => {
|
|
223
172
|
const templatePath = defaultTemplatePath || defaultTemplatePaths.reduce((acc, cur) => {
|
|
224
173
|
if (acc) {
|
|
225
174
|
return acc;
|
|
226
175
|
}
|
|
227
|
-
return
|
|
176
|
+
return fs2.existsSync(path2.resolve(process.cwd(), cur)) ? cur : acc;
|
|
228
177
|
}, "");
|
|
229
178
|
if (!templatePath) {
|
|
230
179
|
throw new Error("Cannot find a CloudFormation template.");
|
|
231
180
|
}
|
|
232
181
|
const extension = templatePath?.split(".").pop();
|
|
233
|
-
const fullPath = path2.resolve(process.cwd(), templatePath);
|
|
234
182
|
if (["yaml", "yml"].includes(extension)) {
|
|
235
183
|
return readCloudFormationYamlTemplate({
|
|
236
184
|
templatePath
|
|
237
185
|
});
|
|
238
186
|
}
|
|
239
|
-
|
|
240
|
-
|
|
187
|
+
const configFilePath = path2.resolve(process.cwd(), templatePath);
|
|
188
|
+
return readConfigFile({
|
|
189
|
+
configFilePath
|
|
241
190
|
});
|
|
242
191
|
};
|
|
243
|
-
export { findAndReadCloudFormationTemplate
|
|
192
|
+
export { findAndReadCloudFormationTemplate };
|
|
@@ -78,10 +78,6 @@ type CloudFormationTemplate = {
|
|
|
78
78
|
|
|
79
79
|
declare const findAndReadCloudFormationTemplate: ({ templatePath: defaultTemplatePath, }: {
|
|
80
80
|
templatePath?: string;
|
|
81
|
-
}) => CloudFormationTemplate
|
|
81
|
+
}) => Promise<CloudFormationTemplate>;
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
path: string;
|
|
85
|
-
}) => any;
|
|
86
|
-
|
|
87
|
-
export { type CloudFormationTemplate, type IAMRoleResource, type Output, type Outputs, type Parameter, type Parameters, type Policy, type Resource, type Resources, findAndReadCloudFormationTemplate, readObjectFile as unstable_readObjectFile };
|
|
83
|
+
export { type CloudFormationTemplate, type IAMRoleResource, type Output, type Outputs, type Parameter, type Parameters, type Policy, type Resource, type Resources, findAndReadCloudFormationTemplate };
|
package/dist/index.d.ts
CHANGED
|
@@ -78,10 +78,6 @@ type CloudFormationTemplate = {
|
|
|
78
78
|
|
|
79
79
|
declare const findAndReadCloudFormationTemplate: ({ templatePath: defaultTemplatePath, }: {
|
|
80
80
|
templatePath?: string;
|
|
81
|
-
}) => CloudFormationTemplate
|
|
81
|
+
}) => Promise<CloudFormationTemplate>;
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
path: string;
|
|
85
|
-
}) => any;
|
|
86
|
-
|
|
87
|
-
export { type CloudFormationTemplate, type IAMRoleResource, type Output, type Outputs, type Parameter, type Parameters, type Policy, type Resource, type Resources, findAndReadCloudFormationTemplate, readObjectFile as unstable_readObjectFile };
|
|
83
|
+
export { type CloudFormationTemplate, type IAMRoleResource, type Output, type Outputs, type Parameter, type Parameters, type Policy, type Resource, type Resources, findAndReadCloudFormationTemplate };
|
package/dist/index.js
CHANGED
|
@@ -38,21 +38,20 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
|
38
38
|
// src/index.ts
|
|
39
39
|
var src_exports = {};
|
|
40
40
|
__export(src_exports, {
|
|
41
|
-
findAndReadCloudFormationTemplate: () => findAndReadCloudFormationTemplate
|
|
42
|
-
unstable_readObjectFile: () => readObjectFile
|
|
41
|
+
findAndReadCloudFormationTemplate: () => findAndReadCloudFormationTemplate
|
|
43
42
|
});
|
|
44
43
|
module.exports = __toCommonJS(src_exports);
|
|
45
44
|
|
|
46
45
|
// src/findAndReadCloudFormationTemplate.ts
|
|
47
|
-
var
|
|
48
|
-
var path2 = __toESM(require("path"));
|
|
46
|
+
var fs2 = __toESM(require("fs"), 1);
|
|
47
|
+
var path2 = __toESM(require("path"), 1);
|
|
49
48
|
|
|
50
49
|
// src/readCloudFormationYamlTemplate.ts
|
|
51
|
-
var fs = __toESM(require("fs"));
|
|
52
|
-
var path = __toESM(require("path"));
|
|
50
|
+
var fs = __toESM(require("fs"), 1);
|
|
51
|
+
var path = __toESM(require("path"), 1);
|
|
53
52
|
|
|
54
53
|
// src/cloudFormationYamlTemplate.ts
|
|
55
|
-
var import_js_yaml = __toESM(require("js-yaml"));
|
|
54
|
+
var import_js_yaml = __toESM(require("js-yaml"), 1);
|
|
56
55
|
var cloudFormationTypes = [{
|
|
57
56
|
tag: "!Equals",
|
|
58
57
|
options: {
|
|
@@ -204,81 +203,35 @@ var readCloudFormationYamlTemplate = ({
|
|
|
204
203
|
return parsed;
|
|
205
204
|
};
|
|
206
205
|
|
|
207
|
-
// src/readObjectFile.ts
|
|
208
|
-
var import_fs = __toESM(require("fs"));
|
|
209
|
-
var import_js_yaml2 = __toESM(require("js-yaml"));
|
|
210
|
-
var readYaml = ({
|
|
211
|
-
path: path3
|
|
212
|
-
}) => {
|
|
213
|
-
const template = import_fs.default.readFileSync(path3, "utf8") || JSON.stringify({});
|
|
214
|
-
return import_js_yaml2.default.load(template);
|
|
215
|
-
};
|
|
216
|
-
var readObjectFile = ({
|
|
217
|
-
path: path3
|
|
218
|
-
}) => {
|
|
219
|
-
if (!import_fs.default.existsSync(path3)) {
|
|
220
|
-
return {};
|
|
221
|
-
}
|
|
222
|
-
const extension = path3.split(".").pop();
|
|
223
|
-
if (extension === "ts") {
|
|
224
|
-
require("ts-node").register({
|
|
225
|
-
compilerOptions: {
|
|
226
|
-
moduleResolution: "node",
|
|
227
|
-
module: "commonjs"
|
|
228
|
-
},
|
|
229
|
-
moduleTypes: {
|
|
230
|
-
"carlin.*": "cjs"
|
|
231
|
-
},
|
|
232
|
-
transpileOnly: true
|
|
233
|
-
});
|
|
234
|
-
const tsObj = require(path3);
|
|
235
|
-
const obj = tsObj.default || tsObj;
|
|
236
|
-
return typeof obj === "function" ? obj() : obj;
|
|
237
|
-
}
|
|
238
|
-
if (extension === "js") {
|
|
239
|
-
const obj = require(path3);
|
|
240
|
-
return typeof obj === "function" ? obj() : obj;
|
|
241
|
-
}
|
|
242
|
-
if (extension === "json") {
|
|
243
|
-
return require(path3);
|
|
244
|
-
}
|
|
245
|
-
if (extension === "yml" || extension === "yaml") {
|
|
246
|
-
return readYaml({
|
|
247
|
-
path: path3
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
return {};
|
|
251
|
-
};
|
|
252
|
-
|
|
253
206
|
// src/findAndReadCloudFormationTemplate.ts
|
|
207
|
+
var import_read_config_file = require("@ttoss/read-config-file");
|
|
254
208
|
var defaultTemplatePaths = ["ts", "js", "yaml", "yml", "json"].map(extension => {
|
|
255
209
|
return `./src/cloudformation.${extension}`;
|
|
256
210
|
});
|
|
257
|
-
var findAndReadCloudFormationTemplate = ({
|
|
211
|
+
var findAndReadCloudFormationTemplate = async ({
|
|
258
212
|
templatePath: defaultTemplatePath
|
|
259
213
|
}) => {
|
|
260
214
|
const templatePath = defaultTemplatePath || defaultTemplatePaths.reduce((acc, cur) => {
|
|
261
215
|
if (acc) {
|
|
262
216
|
return acc;
|
|
263
217
|
}
|
|
264
|
-
return
|
|
218
|
+
return fs2.existsSync(path2.resolve(process.cwd(), cur)) ? cur : acc;
|
|
265
219
|
}, "");
|
|
266
220
|
if (!templatePath) {
|
|
267
221
|
throw new Error("Cannot find a CloudFormation template.");
|
|
268
222
|
}
|
|
269
223
|
const extension = templatePath?.split(".").pop();
|
|
270
|
-
const fullPath = path2.resolve(process.cwd(), templatePath);
|
|
271
224
|
if (["yaml", "yml"].includes(extension)) {
|
|
272
225
|
return readCloudFormationYamlTemplate({
|
|
273
226
|
templatePath
|
|
274
227
|
});
|
|
275
228
|
}
|
|
276
|
-
|
|
277
|
-
|
|
229
|
+
const configFilePath = path2.resolve(process.cwd(), templatePath);
|
|
230
|
+
return (0, import_read_config_file.readConfigFile)({
|
|
231
|
+
configFilePath
|
|
278
232
|
});
|
|
279
233
|
};
|
|
280
234
|
// Annotate the CommonJS export names for ESM import in node:
|
|
281
235
|
0 && (module.exports = {
|
|
282
|
-
findAndReadCloudFormationTemplate
|
|
283
|
-
unstable_readObjectFile
|
|
236
|
+
findAndReadCloudFormationTemplate
|
|
284
237
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/cloudformation",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"description": "CloudFormation utils.",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"url": "https://github.com/ttoss/ttoss.git",
|
|
12
12
|
"directory": "packages/cloudformation"
|
|
13
13
|
},
|
|
14
|
+
"type": "module",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"import": "./dist/esm/index.js",
|
|
17
|
-
"require": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
|
-
"
|
|
27
|
+
"@ttoss/read-config-file": "^1.0.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/jest": "^29.5.12",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"@types/node": "^20.12.7",
|
|
33
33
|
"jest": "^29.7.0",
|
|
34
34
|
"tsup": "^8.0.2",
|
|
35
|
-
"@ttoss/
|
|
36
|
-
"@ttoss/
|
|
35
|
+
"@ttoss/test-utils": "^2.1.6",
|
|
36
|
+
"@ttoss/config": "^1.32.3"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [],
|
|
39
39
|
"publishConfig": {
|
|
@@ -2,7 +2,7 @@ import * as fs from 'fs';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { CloudFormationTemplate } from './CloudFormationTemplate';
|
|
4
4
|
import { readCloudFormationYamlTemplate } from './readCloudFormationYamlTemplate';
|
|
5
|
-
import {
|
|
5
|
+
import { readConfigFile } from '@ttoss/read-config-file';
|
|
6
6
|
|
|
7
7
|
export const defaultTemplatePaths = ['ts', 'js', 'yaml', 'yml', 'json'].map(
|
|
8
8
|
(extension) => {
|
|
@@ -10,11 +10,11 @@ export const defaultTemplatePaths = ['ts', 'js', 'yaml', 'yml', 'json'].map(
|
|
|
10
10
|
}
|
|
11
11
|
);
|
|
12
12
|
|
|
13
|
-
export const findAndReadCloudFormationTemplate = ({
|
|
13
|
+
export const findAndReadCloudFormationTemplate = async ({
|
|
14
14
|
templatePath: defaultTemplatePath,
|
|
15
15
|
}: {
|
|
16
16
|
templatePath?: string;
|
|
17
|
-
}): CloudFormationTemplate => {
|
|
17
|
+
}): Promise<CloudFormationTemplate> => {
|
|
18
18
|
const templatePath =
|
|
19
19
|
defaultTemplatePath ||
|
|
20
20
|
defaultTemplatePaths
|
|
@@ -37,8 +37,6 @@ export const findAndReadCloudFormationTemplate = ({
|
|
|
37
37
|
|
|
38
38
|
const extension = templatePath?.split('.').pop() as string;
|
|
39
39
|
|
|
40
|
-
const fullPath = path.resolve(process.cwd(), templatePath);
|
|
41
|
-
|
|
42
40
|
/**
|
|
43
41
|
* We need to read Yaml first because CloudFormation specific tags aren't
|
|
44
42
|
* recognized when parsing a simple Yaml file. I.e., a possible error:
|
|
@@ -48,5 +46,7 @@ export const findAndReadCloudFormationTemplate = ({
|
|
|
48
46
|
return readCloudFormationYamlTemplate({ templatePath });
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
|
|
49
|
+
const configFilePath = path.resolve(process.cwd(), templatePath);
|
|
50
|
+
|
|
51
|
+
return readConfigFile({ configFilePath });
|
|
52
52
|
};
|
package/src/index.ts
CHANGED
package/src/readObjectFile.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import yaml from 'js-yaml';
|
|
4
|
-
|
|
5
|
-
export const readYaml = ({ path }: { path: string }) => {
|
|
6
|
-
const template = fs.readFileSync(path, 'utf8') || JSON.stringify({});
|
|
7
|
-
return yaml.load(template);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const readObjectFile = ({ path }: { path: string }) => {
|
|
11
|
-
if (!fs.existsSync(path)) {
|
|
12
|
-
return {};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const extension = path.split('.').pop();
|
|
16
|
-
|
|
17
|
-
if (extension === 'ts') {
|
|
18
|
-
require('ts-node').register({
|
|
19
|
-
compilerOptions: { moduleResolution: 'node', module: 'commonjs' },
|
|
20
|
-
moduleTypes: {
|
|
21
|
-
'carlin.*': 'cjs',
|
|
22
|
-
},
|
|
23
|
-
transpileOnly: true,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const tsObj = require(path);
|
|
27
|
-
const obj = tsObj.default || tsObj;
|
|
28
|
-
return typeof obj === 'function' ? obj() : obj;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (extension === 'js') {
|
|
32
|
-
const obj = require(path);
|
|
33
|
-
return typeof obj === 'function' ? obj() : obj;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (extension === 'json') {
|
|
37
|
-
return require(path);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (extension === 'yml' || extension === 'yaml') {
|
|
41
|
-
return readYaml({ path });
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return {};
|
|
45
|
-
};
|