1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const { compileFromFile } = require('json-schema-to-typescript');
|
15 | const { writeFileSync } = require('fs-extra');
|
16 | const fs = require('fs-extra');
|
17 |
|
18 | const options = {
|
19 | $refOptions: {
|
20 | dereference: {
|
21 | declareExternallyReferenced: false,
|
22 | circular: true,
|
23 | },
|
24 | resolve: {
|
25 | custom: {
|
26 | order: 1,
|
27 | canRead({ url }) {
|
28 | const basename = url.split('/').pop();
|
29 | return fs.existsSync(`./docs/${basename}.schema.json`);
|
30 | },
|
31 | read({ url }, callback) {
|
32 | const basename = url.split('/').pop();
|
33 | let schema = fs.readFileSync(`./docs/${basename}.schema.json`);
|
34 | if (url === 'https://ns.adobe.com/helix/pipeline/mdast') {
|
35 | schema = schema.toString().replace('"$ref": "https://ns.adobe.com/helix/pipeline/mdast"', '"type": "object"');
|
36 | }
|
37 | callback(null, schema);
|
38 | },
|
39 | },
|
40 | },
|
41 | },
|
42 | bannerComment: `/*
|
43 | * Copyright 2018 Adobe. All rights reserved.
|
44 | * This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
45 | * you may not use this file except in compliance with the License. You may obtain a copy
|
46 | * of the License at http://www.apache.org/licenses/LICENSE-2.0
|
47 | *
|
48 | * Unless required by applicable law or agreed to in writing, software distributed under
|
49 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
50 | * OF ANY KIND, either express or implied. See the License for the specific language
|
51 | * governing permissions and limitations under the License.
|
52 | */`,
|
53 | };
|
54 |
|
55 | compileFromFile('docs/context.schema.json', options).then((ts) => writeFileSync('src/context.d.ts', ts));
|
56 | compileFromFile('docs/action.schema.json', options).then((ts) => writeFileSync('src/action.d.ts', ts));
|