-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmerge-snippets.js
41 lines (37 loc) · 1.84 KB
/
merge-snippets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and
* Document License (2015-05-13) which is available at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document.
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/
const snippets = require("./schemas/snippets.json");
const tdSchema = require("./schemas/TD.schema.json");
const tmSchema = require("./schemas/TM.schema.json");
const pointer = require("jsonpointer");
const fs = require("fs");
buildSchema(tdSchema, snippets,"./schemas/TD.schema.json");
buildSchema(tmSchema, snippets,"./schemas/TM.schema.json");
fs.writeFileSync("./schemas/TD.schema.json", JSON.stringify(tdSchema, null, 4));
fs.writeFileSync("./schemas/TM.schema.json", JSON.stringify(tmSchema, null, 2));
function buildSchema(schema,snippets,file) {
const filteredSnippets = snippets.filter(snippet => !snippet.file || snippet.file === file);
for (const snippet of filteredSnippets) {
const element = pointer.get(schema, snippet.location);
if (!element) {
throw new Error(`${snippet.location} not found`);
}
const snippetClone = JSON.parse(JSON.stringify(snippet));
delete snippetClone.location;
delete snippetClone.file;
element["defaultSnippets"] = element["defaultSnippets"] || [];
element["defaultSnippets"].push(snippetClone);
}
}