@ama-openapi/core 0.0.0-placeholder.9 → 13.5.0-prerelease.13
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/LICENSE +26 -0
- package/README.md +65 -0
- package/package.json +84 -16
- package/schemas/manifest.schema.json +4 -46
- package/schemas/transform.schema.json +45 -0
- package/src/constants.d.mts +1 -0
- package/src/constants.d.mts.map +1 -1
- package/src/constants.mjs +1 -0
- package/src/constants.mjs.map +1 -1
- package/src/context.d.mts +1 -1
- package/src/core/file-system/parse-file.d.mts +2 -2
- package/src/core/file-system/parse-file.mjs +2 -2
- package/src/core/file-system/relative-path.d.mts +6 -0
- package/src/core/file-system/relative-path.d.mts.map +1 -0
- package/src/core/file-system/relative-path.mjs +9 -0
- package/src/core/file-system/relative-path.mjs.map +1 -0
- package/src/core/file-system/write-model.d.mts.map +1 -1
- package/src/core/file-system/write-model.mjs +6 -1
- package/src/core/file-system/write-model.mjs.map +1 -1
- package/src/core/manifest/extract-dependency-models.d.mts +1 -3
- package/src/core/manifest/extract-dependency-models.d.mts.map +1 -1
- package/src/core/manifest/extract-dependency-models.mjs +45 -26
- package/src/core/manifest/extract-dependency-models.mjs.map +1 -1
- package/src/core/manifest/manifest.d.mts +3 -4
- package/src/core/manifest/manifest.d.mts.map +1 -1
- package/src/core/manifest/manifest.mjs +9 -10
- package/src/core/manifest/manifest.mjs.map +1 -1
- package/src/core/process.d.mts.map +1 -1
- package/src/core/process.mjs.map +1 -1
- package/src/core/serialization.mjs +1 -1
- package/src/core/serialization.mjs.map +1 -1
- package/src/core/transforms/add-annotation.d.mts +2 -1
- package/src/core/transforms/add-annotation.d.mts.map +1 -1
- package/src/core/transforms/add-annotation.mjs.map +1 -1
- package/src/core/transforms/apply-mask.d.mts +2 -1
- package/src/core/transforms/apply-mask.d.mts.map +1 -1
- package/src/core/transforms/apply-mask.mjs +23 -13
- package/src/core/transforms/apply-mask.mjs.map +1 -1
- package/src/core/transforms/rename.d.mts +4 -1
- package/src/core/transforms/rename.d.mts.map +1 -1
- package/src/core/transforms/rename.mjs +2 -2
- package/src/core/transforms/rename.mjs.map +1 -1
- package/src/core/transforms/to-reference.d.mts +4 -1
- package/src/core/transforms/to-reference.d.mts.map +1 -1
- package/src/core/transforms/to-reference.mjs +3 -1
- package/src/core/transforms/to-reference.mjs.map +1 -1
- package/src/core/transforms/transform.d.mts +4 -5
- package/src/core/transforms/transform.d.mts.map +1 -1
- package/src/core/transforms/transform.mjs +1 -8
- package/src/core/transforms/transform.mjs.map +1 -1
- package/src/core/transforms/update-references.d.mts +2 -1
- package/src/core/transforms/update-references.d.mts.map +1 -1
- package/src/core/transforms/update-references.mjs +1 -1
- package/src/core/transforms/update-references.mjs.map +1 -1
- package/src/logger.d.mts +8 -0
- package/src/logger.d.mts.map +1 -1
- package/src/logger.mjs +28 -1
- package/src/logger.mjs.map +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright Amadeus SAS
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
4
|
+
are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
7
|
+
list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
|
11
|
+
other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
14
|
+
may be used to endorse or promote products derived from this software without
|
|
15
|
+
specific prior written permission.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
21
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
22
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
23
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
24
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @ama-openapi/core Documentation
|
|
2
|
+
|
|
3
|
+
This package provides a **dependency management system for OpenAPI specifications** in JavaScript/TypeScript projects, enabling modular and reusable OpenAPI definitions.
|
|
4
|
+
|
|
5
|
+
## Core Concept
|
|
6
|
+
|
|
7
|
+
The system leverages **NPM's package resolution mechanism** to manage OpenAPI specification dependencies, allowing you to:
|
|
8
|
+
|
|
9
|
+
- Install OpenAPI specs as NPM packages
|
|
10
|
+
- Reference external models in your specifications
|
|
11
|
+
- Apply transformations to imported models
|
|
12
|
+
- Handle complex versioning and conflict resolution
|
|
13
|
+
|
|
14
|
+
> [!NOTE]
|
|
15
|
+
> Get complete information regarding the concept in the [Dependency Resolution Concept documentation](https://github.com/AmadeusITGroup/otter/tree/main/docs/openapi/DEPENDENCY_RESOLUTION_CONCEPT.md).
|
|
16
|
+
|
|
17
|
+
## Key Workflow
|
|
18
|
+
|
|
19
|
+
1. **Install Dependencies**: Add OpenAPI packages via `npm install @my/dep-spec` or create a new project thanks to the [project initializer](https://npmjs.com/package/@ama-openapi/create).
|
|
20
|
+
2. **Configure Manifest**: Define which models to extract in `openapi.manifest.json` (or other) that can be defined following [manifest documentation](https://github.com/AmadeusITGroup/otter/tree/main/docs/openapi/MANIFEST_CONFIGURATION.md)
|
|
21
|
+
3. **Extract Models**: Run the command `ama-openapi install` from [@ama-openapi/cli](https://npmjs.com/package/@ama-openapi/cli) to extract models into `models_external/` directory
|
|
22
|
+
4. **Reference Models**: Use [extracted models](https://github.com/AmadeusITGroup/otter/tree/main/docs/openapi/EXTRACTED_MODEL_DETAILS.md) in your specification files
|
|
23
|
+
5. **Bundle**: Use `redocly bundle` to create the final specification
|
|
24
|
+
|
|
25
|
+
## Transformation Features
|
|
26
|
+
|
|
27
|
+
Models can be transformed during extraction:
|
|
28
|
+
|
|
29
|
+
- **rename**: Rename model files (e.g., `"myPrefix_$1"`)
|
|
30
|
+
- **titleRename**: Rename model titles
|
|
31
|
+
- **mask**: Filter/override/add properties using Stoplight mask syntax
|
|
32
|
+
|
|
33
|
+
> [!NOTE]
|
|
34
|
+
> Get complete documentation regarding the transformation features in [Transform documentation](https://github.com/AmadeusITGroup/otter/tree/main/docs/openapi/TRANSFORM.md)
|
|
35
|
+
|
|
36
|
+
## Model Extraction Types
|
|
37
|
+
|
|
38
|
+
According to if a mask is applied or not on the referred models, the extraction process will:
|
|
39
|
+
|
|
40
|
+
- generates a simple redirect file with `$ref` pointing to `node_modules`
|
|
41
|
+
- generates modified model with applied transformations and annotations (`x-internal-*` fields)
|
|
42
|
+
|
|
43
|
+
A description of the extracted models is available on [extracted models documentation](https://github.com/AmadeusITGroup/otter/tree/main/docs/openapi/DEPENDENCY_RESOLUTION_CONCEPT.md).
|
|
44
|
+
|
|
45
|
+
## Shareable Specifications
|
|
46
|
+
|
|
47
|
+
To create a shareable specification:
|
|
48
|
+
|
|
49
|
+
1. Create valid `package.json` with `name`, `version`, and `exports` field
|
|
50
|
+
2. List external dependencies in `dependencies`
|
|
51
|
+
3. Extract external models during `postinstall` lifecycle
|
|
52
|
+
4. Publish to NPM registry
|
|
53
|
+
|
|
54
|
+
> [!NOTE]
|
|
55
|
+
> Complete documentation is available on [dedicated shaerable specification section](https://github.com/AmadeusITGroup/otter/tree/main/docs/openapi/SHAREABLE_SPECIFICATION.md).
|
|
56
|
+
|
|
57
|
+
## Integration
|
|
58
|
+
|
|
59
|
+
This package works in the **Ama OpenApi ecosystem** including:
|
|
60
|
+
|
|
61
|
+
- [@ama-openapi/cli](https://npmjs.com/package/@ama-openapi/cli) - Manual dependency installation
|
|
62
|
+
- [@ama-openapi/redocly-plugin](https://npmjs.com/package/@ama-openapi/redocly-plugin) - Redocly CLI integration
|
|
63
|
+
- [@ama-openapi/create](https://npmjs.com/package/@ama-openapi/create) - Project scaffolding
|
|
64
|
+
|
|
65
|
+
The package **@ama-openapi/core** exposed divers items to facilitate a manual setup in the [technical documentation](https://github.com/AmadeusITGroup/otter/tree/main/docs/openapi/TECHNICAL_INFORMATION.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ama-openapi/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.5.0-prerelease.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"ajv": "~8.17.1",
|
|
43
|
-
"js-yaml": "^4.1.
|
|
43
|
+
"js-yaml": "^4.1.1",
|
|
44
44
|
"semver": "^7.5.2",
|
|
45
45
|
"tslib": "^2.6.2"
|
|
46
46
|
},
|
|
@@ -56,33 +56,33 @@
|
|
|
56
56
|
"@babel/core": "~7.28.0",
|
|
57
57
|
"@babel/preset-env": "~7.28.0",
|
|
58
58
|
"@babel/preset-typescript": "~7.28.0",
|
|
59
|
-
"@compodoc/compodoc": "^1.1.
|
|
59
|
+
"@compodoc/compodoc": "^1.1.32",
|
|
60
60
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
|
|
61
61
|
"@nx/eslint": "~21.6.0",
|
|
62
62
|
"@nx/eslint-plugin": "~21.6.0",
|
|
63
63
|
"@nx/jest": "~21.6.0",
|
|
64
64
|
"@nx/js": "~21.6.0",
|
|
65
|
-
"@o3r/build-helpers": "
|
|
66
|
-
"@o3r/eslint-plugin": "
|
|
67
|
-
"@o3r/telemetry": "
|
|
68
|
-
"@o3r/test-helpers": "
|
|
69
|
-
"@stylistic/eslint-plugin": "~5.
|
|
65
|
+
"@o3r/build-helpers": "~13.5.0-prerelease.13",
|
|
66
|
+
"@o3r/eslint-plugin": "~13.5.0-prerelease.13",
|
|
67
|
+
"@o3r/telemetry": "~13.5.0-prerelease.13",
|
|
68
|
+
"@o3r/test-helpers": "~13.5.0-prerelease.13",
|
|
69
|
+
"@stylistic/eslint-plugin": "~5.6.0",
|
|
70
70
|
"@types/jest": "~29.5.2",
|
|
71
71
|
"@types/js-yaml": "^4.0.5",
|
|
72
72
|
"@types/minimist": "^1.2.2",
|
|
73
73
|
"@types/node": "~22.18.0",
|
|
74
74
|
"@types/semver": "^7.3.13",
|
|
75
|
-
"@typescript-eslint/parser": "~8.
|
|
76
|
-
"angular-eslint": "~20.
|
|
75
|
+
"@typescript-eslint/parser": "~8.47.0",
|
|
76
|
+
"angular-eslint": "~20.6.0",
|
|
77
77
|
"babel-jest": "^29.7.0",
|
|
78
78
|
"babel-plugin-transform-import-meta": "^2.0.0",
|
|
79
79
|
"cpy-cli": "^6.0.0",
|
|
80
|
-
"eslint": "~9.
|
|
80
|
+
"eslint": "~9.39.0",
|
|
81
81
|
"eslint-import-resolver-node": "~0.3.9",
|
|
82
82
|
"eslint-import-resolver-typescript": "~4.4.0",
|
|
83
83
|
"eslint-plugin-import": "~2.32.0",
|
|
84
84
|
"eslint-plugin-import-newlines": "~1.4.0",
|
|
85
|
-
"eslint-plugin-jest": "~29.
|
|
85
|
+
"eslint-plugin-jest": "~29.1.0",
|
|
86
86
|
"eslint-plugin-jsdoc": "~54.7.0",
|
|
87
87
|
"eslint-plugin-prefer-arrow": "~1.2.3",
|
|
88
88
|
"eslint-plugin-unicorn": "~60.0.0",
|
|
@@ -94,13 +94,81 @@
|
|
|
94
94
|
"jest-util": "~29.7.0",
|
|
95
95
|
"jsonc-eslint-parser": "~2.4.0",
|
|
96
96
|
"nx": "~21.6.0",
|
|
97
|
-
"pid-from-port": "^1.1.3",
|
|
98
97
|
"ts-jest": "~29.4.0",
|
|
99
98
|
"type-fest": "^4.30.1",
|
|
100
99
|
"typescript": "~5.9.2",
|
|
101
|
-
"typescript-eslint": "~8.
|
|
100
|
+
"typescript-eslint": "~8.47.0"
|
|
102
101
|
},
|
|
103
102
|
"engines": {
|
|
104
103
|
"node": "^20.19.0 || ^22.17.0 || ^24.0.0"
|
|
105
|
-
}
|
|
106
|
-
|
|
104
|
+
},
|
|
105
|
+
"contributors": [
|
|
106
|
+
{
|
|
107
|
+
"name": "Yannick Adam",
|
|
108
|
+
"url": "https://github.com/yannickadam",
|
|
109
|
+
"email": "yannickadam@users.noreply.github.com"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"name": "Kilian Panot",
|
|
113
|
+
"url": "https://github.com/kpanot",
|
|
114
|
+
"email": "kpanot@users.noreply.github.com"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"name": "Jeremy Bourgeois",
|
|
118
|
+
"url": "https://github.com/jbourgeois-1A",
|
|
119
|
+
"email": "jbourgeois-1A@users.noreply.github.com"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"name": "Pierre Henri Ginoux",
|
|
123
|
+
"url": "https://github.com/pginoux-1A",
|
|
124
|
+
"email": "pginoux-1A@users.noreply.github.com"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"name": "Mircea Vasile Rednic",
|
|
128
|
+
"url": "https://github.com/mrednic-1A",
|
|
129
|
+
"email": "mrednic-1A@users.noreply.github.com"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"name": "Stephane Dalle",
|
|
133
|
+
"url": "https://github.com/sdalle-1A",
|
|
134
|
+
"email": "sdalle-1A@users.noreply.github.com"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"name": "Nicolas Hoffmann",
|
|
138
|
+
"url": "https://github.com/nhoffmann-1A",
|
|
139
|
+
"email": "nhoffmann-1A@users.noreply.github.com"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"name": "Victor Scaiceanu",
|
|
143
|
+
"url": "https://github.com/vscaiceanu-1a",
|
|
144
|
+
"email": "vscaiceanu-1A@users.noreply.github.com"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"name": "Florian Paul",
|
|
148
|
+
"url": "https://github.com/fpaul-1A",
|
|
149
|
+
"email": "fpaul-1A@users.noreply.github.com"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"name": "Corinne Paulve",
|
|
153
|
+
"url": "https://github.com/cpaulve-1A",
|
|
154
|
+
"email": "cpaulve-1A@users.noreply.github.com"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"name": "Matthieu Crouzet",
|
|
158
|
+
"url": "https://github.com/matthieu-crouzet",
|
|
159
|
+
"email": "matthieu-crouzet@users.noreply.github.com"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"name": "Salome Do",
|
|
163
|
+
"url": "https://github.com/sdo-1A",
|
|
164
|
+
"email": "sdo-1A@users.noreply.github.com"
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
"bugs": "https://github.com/AmadeusITGroup/otter/issues",
|
|
168
|
+
"repository": {
|
|
169
|
+
"type": "git",
|
|
170
|
+
"url": "git+https://github.com/AmadeusITGroup/otter.git"
|
|
171
|
+
},
|
|
172
|
+
"license": "BSD-3-Clause",
|
|
173
|
+
"homepage": "https://amadeusitgroup.github.io/otter/"
|
|
174
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
3
|
"title": "OpenApi specification package manifest",
|
|
4
|
+
"$id": "@ama-openapi/core/schemas/manifest.schema.json",
|
|
4
5
|
"type": "object",
|
|
5
6
|
"properties": {
|
|
6
7
|
"models": {
|
|
@@ -19,39 +20,7 @@
|
|
|
19
20
|
"transform": {
|
|
20
21
|
"oneOf": [
|
|
21
22
|
{
|
|
22
|
-
"
|
|
23
|
-
"examples": [
|
|
24
|
-
{
|
|
25
|
-
"mask": { "data": true },
|
|
26
|
-
"fileRename": "MyPrefix_$1"
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
"properties": {
|
|
30
|
-
"mask": {
|
|
31
|
-
"type": "object",
|
|
32
|
-
"description": "Mask to apply"
|
|
33
|
-
},
|
|
34
|
-
"titleRename": {
|
|
35
|
-
"type": "string",
|
|
36
|
-
"description": "Rename the model title. The keyword `$1` can be used to refer to original name (ex: a prefix would be `myPrefix_$1`)",
|
|
37
|
-
"examples": [
|
|
38
|
-
"myPrefix_$1",
|
|
39
|
-
"myModel"
|
|
40
|
-
]
|
|
41
|
-
},
|
|
42
|
-
"fileRename": {
|
|
43
|
-
"type": "string",
|
|
44
|
-
"description": "Rename the outputted file. The keyword `$1` can be used to refer to original name (ex: a prefix would be `my-prefix-$1`)",
|
|
45
|
-
"examples": [
|
|
46
|
-
"my-prefix-$1",
|
|
47
|
-
"myModel.v1.yaml"
|
|
48
|
-
]
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
"additionalProperties": false,
|
|
52
|
-
"required": [
|
|
53
|
-
"fileRename"
|
|
54
|
-
]
|
|
23
|
+
"$ref": "./transform.schema.json"
|
|
55
24
|
},
|
|
56
25
|
{
|
|
57
26
|
"type": "string",
|
|
@@ -67,7 +36,7 @@
|
|
|
67
36
|
"path": "models/ExampleModel.v1.yaml",
|
|
68
37
|
"transform": {
|
|
69
38
|
"mask": { "properties": { "field": true } },
|
|
70
|
-
"
|
|
39
|
+
"rename": "MyPrefix_$1"
|
|
71
40
|
}
|
|
72
41
|
}
|
|
73
42
|
],
|
|
@@ -90,18 +59,7 @@
|
|
|
90
59
|
"description": "Path to the specific model to include as is. The path is relative to the artifact root (e.g., 'models/ExampleModel.v1.yaml')"
|
|
91
60
|
},
|
|
92
61
|
"transform": {
|
|
93
|
-
"
|
|
94
|
-
{
|
|
95
|
-
"$ref": "#/definitions/transform"
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
"type": "array",
|
|
99
|
-
"description": "List of transforms to apply in sequence. Each transform will result to a new model being created in the output.",
|
|
100
|
-
"items": {
|
|
101
|
-
"$ref": "#/definitions/transform"
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
]
|
|
62
|
+
"$ref": "#/definitions/transform"
|
|
105
63
|
}
|
|
106
64
|
},
|
|
107
65
|
"required": [
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "@ama-openapi/core/schemas/transform.schema.json",
|
|
4
|
+
"title": "OpenApi mask definition",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"examples": [
|
|
7
|
+
{
|
|
8
|
+
"mask": {
|
|
9
|
+
"data": true
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"rename": "MyPrefix_$1"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"mask": {
|
|
17
|
+
"data": true
|
|
18
|
+
},
|
|
19
|
+
"rename": "MyPrefix_$1"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"properties": {
|
|
23
|
+
"mask": {
|
|
24
|
+
"type": "object",
|
|
25
|
+
"description": "Mask to apply"
|
|
26
|
+
},
|
|
27
|
+
"titleRename": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "Rename the model title. The keyword `$1` can be used to refer to original name (ex: a prefix would be `myPrefix_$1`)",
|
|
30
|
+
"examples": [
|
|
31
|
+
"myPrefix_$1",
|
|
32
|
+
"myModel"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"rename": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "Rename the outputted file. The keyword `$1` can be used to refer to the original name (ex: a prefix would be `my-prefix-$1`)",
|
|
38
|
+
"examples": [
|
|
39
|
+
"my-prefix-$1",
|
|
40
|
+
"myModel.v1.yaml"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"additionalProperties": false
|
|
45
|
+
}
|
package/src/constants.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Directory containing the extracted module */
|
|
2
2
|
export declare const OUTPUT_DIRECTORY = "models_external";
|
|
3
|
+
/** Directory containing masked model when the mask is applied to referenced models */
|
|
3
4
|
export declare const SUB_MASK_DIRECTORY = "sub-masks";
|
|
4
5
|
/** Default manifest filenames to look for */
|
|
5
6
|
export declare const DEFAULT_MANIFEST_FILENAMES: readonly ["ama-openapi.manifest.json", "ama-openapi.manifest.yaml", "ama-openapi.manifest.yml", "openapi.manifest.json", "openapi.manifest.yaml", "openapi.manifest.yml", "package.json"];
|
package/src/constants.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../src/constants.mts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,eAAO,MAAM,gBAAgB,oBAAoB,CAAC;AAElD,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAE9C,6CAA6C;AAC7C,eAAO,MAAM,0BAA0B,2LAQ7B,CAAC;AAIX,oCAAoC;AACpC,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AACvD,qCAAqC;AACrC,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AACzD,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AACvD,+CAA+C;AAC/C,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AACzD,iDAAiD;AACjD,eAAO,MAAM,0BAA0B,mCAAmC,CAAC;AAC3E,gDAAgD;AAChD,eAAO,MAAM,0BAA0B,mCAAmC,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../src/constants.mts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,eAAO,MAAM,gBAAgB,oBAAoB,CAAC;AAElD,sFAAsF;AACtF,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAE9C,6CAA6C;AAC7C,eAAO,MAAM,0BAA0B,2LAQ7B,CAAC;AAIX,oCAAoC;AACpC,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AACvD,qCAAqC;AACrC,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AACzD,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AACvD,+CAA+C;AAC/C,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AACzD,iDAAiD;AACjD,eAAO,MAAM,0BAA0B,mCAAmC,CAAC;AAC3E,gDAAgD;AAChD,eAAO,MAAM,0BAA0B,mCAAmC,CAAC"}
|
package/src/constants.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Directory containing the extracted module */
|
|
2
2
|
export const OUTPUT_DIRECTORY = 'models_external';
|
|
3
|
+
/** Directory containing masked model when the mask is applied to referenced models */
|
|
3
4
|
export const SUB_MASK_DIRECTORY = 'sub-masks';
|
|
4
5
|
/** Default manifest filenames to look for */
|
|
5
6
|
export const DEFAULT_MANIFEST_FILENAMES = [
|
package/src/constants.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../src/constants.mts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAElD,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAE9C,6CAA6C;AAC7C,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,2BAA2B;IAC3B,2BAA2B;IAC3B,0BAA0B;IAC1B,uBAAuB;IACvB,uBAAuB;IACvB,sBAAsB;IACtB,cAAc;CACN,CAAC;AAEX,2BAA2B;AAE3B,oCAAoC;AACpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD,qCAAqC;AACrC,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AACzD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD,+CAA+C;AAC/C,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AACzD,iDAAiD;AACjD,MAAM,CAAC,MAAM,0BAA0B,GAAG,gCAAgC,CAAC;AAC3E,gDAAgD;AAChD,MAAM,CAAC,MAAM,0BAA0B,GAAG,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../src/constants.mts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAElD,sFAAsF;AACtF,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAE9C,6CAA6C;AAC7C,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,2BAA2B;IAC3B,2BAA2B;IAC3B,0BAA0B;IAC1B,uBAAuB;IACvB,uBAAuB;IACvB,sBAAsB;IACtB,cAAc;CACN,CAAC;AAEX,2BAA2B;AAE3B,oCAAoC;AACpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD,qCAAqC;AACrC,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AACzD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD,+CAA+C;AAC/C,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AACzD,iDAAiD;AACjD,MAAM,CAAC,MAAM,0BAA0B,GAAG,gCAAgC,CAAC;AAC3E,gDAAgD;AAChD,MAAM,CAAC,MAAM,0BAA0B,GAAG,gCAAgC,CAAC"}
|
package/src/context.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Parse a file content based on its extension
|
|
3
3
|
* @param filePath
|
|
4
4
|
*/
|
|
5
5
|
export declare const isJsonFile: (filePath: string) => boolean;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Parse a file content based on its extension
|
|
8
8
|
* @param filePath
|
|
9
9
|
*/
|
|
10
10
|
export declare const parseFile: <S>(filePath: string) => Promise<S>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { promises as fs, } from 'node:fs';
|
|
2
2
|
import { load, } from 'js-yaml';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Parse a file content based on its extension
|
|
5
5
|
* @param filePath
|
|
6
6
|
*/
|
|
7
7
|
export const isJsonFile = (filePath) => {
|
|
8
8
|
return filePath.toLowerCase().endsWith('.json');
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Parse a file content based on its extension
|
|
12
12
|
* @param filePath
|
|
13
13
|
*/
|
|
14
14
|
export const parseFile = async (filePath) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relative-path.d.mts","sourceRoot":"","sources":["../../../../src/core/file-system/relative-path.mts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OAE7C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relative-path.mjs","sourceRoot":"","sources":["../../../../src/core/file-system/relative-path.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GACX,MAAM,iBAAiB,CAAC;AAEzB;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAY,EAAW,EAAE;IACtD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-model.d.mts","sourceRoot":"","sources":["../../../../src/core/file-system/write-model.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"write-model.d.mts","sourceRoot":"","sources":["../../../../src/core/file-system/write-model.mts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,OAAO,EACR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,wBAAwB,EACzB,MAAM,2CAA2C,CAAC;AAEnD;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAU,gBAAgB,wBAAwB,EAAE,SAAS,OAAO,kBAiB9F,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { promises as fs, } from 'node:fs';
|
|
1
|
+
import { existsSync, promises as fs, } from 'node:fs';
|
|
2
|
+
import { EOL, } from 'node:os';
|
|
2
3
|
import { dirname, } from 'node:path';
|
|
3
4
|
/**
|
|
4
5
|
* Write the model file in the dependencies folder.
|
|
@@ -16,6 +17,10 @@ export const writeModelFile = async (retrievedModel, context) => {
|
|
|
16
17
|
catch {
|
|
17
18
|
logger?.debug?.(`Directory ${directory} may already exist, continuing...`);
|
|
18
19
|
}
|
|
20
|
+
if (existsSync(outputFilePath)) {
|
|
21
|
+
logger?.warn(`The file ${outputFilePath} already exist and will be replaced.`
|
|
22
|
+
+ `${EOL}This may be due to a previous model extraction, please verify or apply a "rename" value to the associated Transform.`);
|
|
23
|
+
}
|
|
19
24
|
await fs.writeFile(outputFilePath, content, { encoding: 'utf8' });
|
|
20
25
|
};
|
|
21
26
|
//# sourceMappingURL=write-model.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-model.mjs","sourceRoot":"","sources":["../../../../src/core/file-system/write-model.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,EAAE,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,OAAO,GACR,MAAM,WAAW,CAAC;AAQnB;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,cAAwC,EAAE,OAAgB,EAAE,EAAE;IACjG,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC;IACnD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1C,IAAI,CAAC;QACH,MAAM,EAAE,KAAK,EAAE,CAAC,wCAAwC,SAAS,EAAE,CAAC,CAAC;QACrE,MAAM,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,EAAE,KAAK,EAAE,CAAC,aAAa,SAAS,mCAAmC,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,EAAE,CAAC,SAAS,CAAC,cAAc,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;AACpE,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"write-model.mjs","sourceRoot":"","sources":["../../../../src/core/file-system/write-model.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,QAAQ,IAAI,EAAE,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,GAAG,GACJ,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,OAAO,GACR,MAAM,WAAW,CAAC;AAQnB;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,cAAwC,EAAE,OAAgB,EAAE,EAAE;IACjG,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC;IACnD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1C,IAAI,CAAC;QACH,MAAM,EAAE,KAAK,EAAE,CAAC,wCAAwC,SAAS,EAAE,CAAC,CAAC;QACrE,MAAM,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,EAAE,KAAK,EAAE,CAAC,aAAa,SAAS,mCAAmC,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QAC/B,MAAM,EAAE,IAAI,CAAC,YAAY,cAAc,sCAAsC;cACzE,GAAG,GAAG,sHAAsH,CAAC,CAAC;IACpI,CAAC;IAED,MAAM,EAAE,CAAC,SAAS,CAAC,cAAc,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;AACpE,CAAC,CAAC"}
|
|
@@ -13,9 +13,7 @@ export interface RetrievedDependencyModel {
|
|
|
13
13
|
/** Content of the model file */
|
|
14
14
|
content: string;
|
|
15
15
|
/** Model definition from the manifest */
|
|
16
|
-
model: Model &
|
|
17
|
-
path: string;
|
|
18
|
-
};
|
|
16
|
+
model: Model & Required<Pick<Model, 'path'>>;
|
|
19
17
|
/** Indicates if the input model file is a JSON file */
|
|
20
18
|
isInputJson: boolean;
|
|
21
19
|
/** Indicates if the output model file is a JSON file */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-dependency-models.d.mts","sourceRoot":"","sources":["../../../../src/core/manifest/extract-dependency-models.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extract-dependency-models.d.mts","sourceRoot":"","sources":["../../../../src/core/manifest/extract-dependency-models.mts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,OAAO,EACR,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,KAAK,EACV,QAAQ,EACR,KAAK,EACL,SAAS,EACV,MAAM,gBAAgB,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,2BAA2B;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7C,uDAAuD;IACvD,WAAW,EAAE,OAAO,CAAC;IACrB,wDAAwD;IACxD,YAAY,EAAE,OAAO,CAAC;IACtB,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB;IACpB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAgGD;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,GACxC,cAAc,MAAM,EACpB,OAAO,KAAK,EACZ,kBAAkB,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,EAChD,SAAS,OAAO,EAChB,wBAAkC,KAAG,OAAO,CAAC,wBAAwB,CA8BtE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAAI,UAAU,QAAQ,EAAE,SAAS,OAAO,wCAU3E,CAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { promises as fs, } from 'node:fs';
|
|
2
2
|
import { createRequire, } from 'node:module';
|
|
3
3
|
import { basename, dirname, extname, join, resolve, } from 'node:path';
|
|
4
|
-
import { load, } from 'js-yaml';
|
|
5
4
|
import { OUTPUT_DIRECTORY, } from '../../constants.mjs';
|
|
6
|
-
import { isJsonFile, } from '../file-system/parse-file.mjs';
|
|
5
|
+
import { isJsonFile, parseFile, } from '../file-system/parse-file.mjs';
|
|
7
6
|
/**
|
|
8
7
|
* Sanitize the package path to be used in file system
|
|
9
8
|
* @param artifactName
|
|
@@ -13,6 +12,23 @@ const sanitizePackagePath = (artifactName) => {
|
|
|
13
12
|
.replace('/', '-')
|
|
14
13
|
.replace(/^@/, '');
|
|
15
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Get the path to the file containing the model
|
|
17
|
+
* @param modelPath
|
|
18
|
+
*/
|
|
19
|
+
const getFilePathFromModelPath = (modelPath) => {
|
|
20
|
+
return modelPath.replace(/#[\\/].+$/, '');
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Get the file name resulting of a model path
|
|
24
|
+
* @param modelPath
|
|
25
|
+
*/
|
|
26
|
+
const getOutFilePathFromModelPath = (modelPath) => {
|
|
27
|
+
const match = modelPath.match(/^(.*)#[\\/](.+)?$/);
|
|
28
|
+
return match
|
|
29
|
+
? join(dirname(match[1]), match[2] + extname(match[1]))
|
|
30
|
+
: modelPath;
|
|
31
|
+
};
|
|
16
32
|
/**
|
|
17
33
|
* Retrieve the transform object from the manifest
|
|
18
34
|
* @param cwd
|
|
@@ -21,13 +37,22 @@ const sanitizePackagePath = (artifactName) => {
|
|
|
21
37
|
const retrieveTransform = async (cwd, transform) => {
|
|
22
38
|
if (typeof transform === 'string') {
|
|
23
39
|
const transformPath = resolve(cwd, transform);
|
|
24
|
-
|
|
25
|
-
return extname(transformPath).toLowerCase() === '.json'
|
|
26
|
-
? JSON.parse(fileContent)
|
|
27
|
-
: load(fileContent);
|
|
40
|
+
return parseFile(transformPath);
|
|
28
41
|
}
|
|
29
42
|
return transform;
|
|
30
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* Get information for artifactory manifest file
|
|
46
|
+
* @param require
|
|
47
|
+
* @param artifactName
|
|
48
|
+
*/
|
|
49
|
+
const getArtifactInfo = async (require, artifactName) => {
|
|
50
|
+
const artifactPackageJson = require.resolve(`${artifactName}/package.json`);
|
|
51
|
+
const artifactBasePath = dirname(artifactPackageJson);
|
|
52
|
+
const packageJsonContent = await fs.readFile(artifactPackageJson, { encoding: 'utf8' });
|
|
53
|
+
const version = JSON.parse(packageJsonContent).version || 'latest';
|
|
54
|
+
return { artifactBasePath, version };
|
|
55
|
+
};
|
|
31
56
|
/**
|
|
32
57
|
* Extract dependency model given simple model definition (as string or boolean)
|
|
33
58
|
* @param cwd
|
|
@@ -39,14 +64,13 @@ const retrieveTransform = async (cwd, transform) => {
|
|
|
39
64
|
const extractDependencyModelsSimple = async (cwd, artifactName, modelName, logger, outputDirectory = OUTPUT_DIRECTORY) => {
|
|
40
65
|
logger?.debug?.(`extracting model ${modelName} from ${outputDirectory}`);
|
|
41
66
|
const require = createRequire(resolve(cwd, 'package.json'));
|
|
42
|
-
const
|
|
43
|
-
const artifactBasePath = dirname(artifactPackageJson);
|
|
67
|
+
const { artifactBasePath, version } = await getArtifactInfo(require, artifactName);
|
|
44
68
|
const modelPath = typeof modelName === 'string' ? join(artifactBasePath, modelName) : require.resolve(artifactName);
|
|
45
|
-
const
|
|
46
|
-
const content = await fs.readFile(modelPath, { encoding: 'utf8' });
|
|
69
|
+
const content = await fs.readFile(getFilePathFromModelPath(modelPath), { encoding: 'utf8' });
|
|
47
70
|
const path = typeof modelName === 'string' ? modelName : artifactName;
|
|
48
71
|
const model = { path };
|
|
49
|
-
const
|
|
72
|
+
const fileNameOutput = getOutFilePathFromModelPath(model.path);
|
|
73
|
+
const outputFilePath = resolve(cwd, outputDirectory, sanitizePackagePath(artifactName), fileNameOutput);
|
|
50
74
|
return {
|
|
51
75
|
outputFilePath,
|
|
52
76
|
artifactBasePath,
|
|
@@ -73,15 +97,15 @@ export const extractDependencyModelsObject = async (artifactName, model, transfo
|
|
|
73
97
|
const { cwd, logger } = context;
|
|
74
98
|
const require = createRequire(resolve(cwd, 'package.json'));
|
|
75
99
|
const transform = await transformPromise;
|
|
76
|
-
const
|
|
77
|
-
const artifactBasePath = dirname(artifactPackageJson);
|
|
100
|
+
const { artifactBasePath, version } = await getArtifactInfo(require, artifactName);
|
|
78
101
|
const modelPath = model.path ? join(artifactBasePath, model.path) : require.resolve(artifactName);
|
|
79
|
-
const
|
|
80
|
-
const content = await fs.readFile(modelPath, { encoding: 'utf8' });
|
|
102
|
+
const content = await fs.readFile(getFilePathFromModelPath(modelPath), { encoding: 'utf8' });
|
|
81
103
|
logger?.debug?.(`extracting model ${modelPath} from ${outputDirectory}`);
|
|
82
104
|
const path = model.path || require.resolve(artifactName).split(artifactName)[1];
|
|
83
|
-
const
|
|
84
|
-
const fileNameOutput =
|
|
105
|
+
const fileName = getFilePathFromModelPath(path);
|
|
106
|
+
const fileNameOutput = transform?.rename
|
|
107
|
+
? fileName.replace(new RegExp(`(${basename(fileName).replaceAll('.', '\\.')})$`), transform.rename)
|
|
108
|
+
: getOutFilePathFromModelPath(path);
|
|
85
109
|
const outputFilePath = resolve(cwd, outputDirectory, sanitizePackagePath(artifactName), fileNameOutput);
|
|
86
110
|
return {
|
|
87
111
|
transform,
|
|
@@ -108,14 +132,9 @@ export const extractDependencyModels = (manifest, context) => {
|
|
|
108
132
|
const { logger, cwd } = context;
|
|
109
133
|
logger?.info(`${Object.keys(manifest.models).length} dependencies models found in the manifest`);
|
|
110
134
|
logger?.debug?.('Extracting information from the manifest configuration: ', manifest);
|
|
111
|
-
return Object.entries(manifest.models).flatMap(([dependencyName, modelDefinition]) =>
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
? [extractDependencyModelsSimple(cwd, dependencyName, model, logger)]
|
|
116
|
-
: (Array.isArray(model.transform)
|
|
117
|
-
? (model.transform.length > 0 ? model.transform : [undefined]).map((transform) => extractDependencyModelsObject(dependencyName, model, retrieveTransform(cwd, transform), context))
|
|
118
|
-
: [extractDependencyModelsObject(dependencyName, model, retrieveTransform(cwd, model.transform), context)]));
|
|
119
|
-
});
|
|
135
|
+
return Object.entries(manifest.models).flatMap(([dependencyName, modelDefinition]) => (Array.isArray(modelDefinition) ? modelDefinition : [modelDefinition])
|
|
136
|
+
.map((model) => (typeof model === 'string' || typeof model === 'boolean')
|
|
137
|
+
? extractDependencyModelsSimple(cwd, dependencyName, model, logger)
|
|
138
|
+
: extractDependencyModelsObject(dependencyName, model, retrieveTransform(cwd, model.transform), context)));
|
|
120
139
|
};
|
|
121
140
|
//# sourceMappingURL=extract-dependency-models.mjs.map
|