@microtronics/studio-cli 0.3.5 → 0.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.
- package/CHANGELOG.md +23 -0
- package/dist/studio-cli.d.ts +1267 -0
- package/out/api.d.ts.map +1 -1
- package/out/api.js +11 -1
- package/out/dde/coreDefinitions.d.ts.map +1 -0
- package/out/dde/coreDefinitions.js +533 -0
- package/out/dde/dde.d.ts.map +1 -0
- package/out/dde/dde.js +178 -0
- package/out/dde/dynamic-dde.schema.json +835 -0
- package/out/dde/fileGenerators/xml.d.ts.map +1 -0
- package/out/dde/fileGenerators/xml.js +205 -0
- package/out/dde/yamlDdePreCompiler.d.ts.map +1 -0
- package/out/dde/yamlDdePreCompiler.js +900 -0
- package/out/defaultFiles.d.ts.map +1 -0
- package/out/defaultFiles.js +84 -0
- package/out/dependencies.d.ts.map +1 -1
- package/out/dependencies.js +41 -6
- package/out/diagnostics.d.ts.map +1 -0
- package/out/diagnostics.js +10 -0
- package/out/helper.d.ts.map +1 -0
- package/out/helper.js +22 -0
- package/out/main.js +13 -0
- package/out/manifest.d.ts.map +1 -1
- package/out/manifest.js +7 -0
- package/package.json +69 -63
package/out/dde/dde.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DDE = exports.DDE_PATH = void 0;
|
|
7
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
8
|
+
const FS_1 = require("../FS");
|
|
9
|
+
const dependencies_1 = require("../dependencies");
|
|
10
|
+
const manifest_1 = require("../manifest");
|
|
11
|
+
const ajv_1 = __importDefault(require("ajv"));
|
|
12
|
+
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
13
|
+
const dynamic_dde_schema_json_1 = __importDefault(require("./dynamic-dde.schema.json"));
|
|
14
|
+
const yaml_1 = require("yaml");
|
|
15
|
+
const yamlDdePreCompiler_1 = require("./yamlDdePreCompiler");
|
|
16
|
+
const xml_1 = require("./fileGenerators/xml");
|
|
17
|
+
const defaultFiles_1 = require("../defaultFiles");
|
|
18
|
+
exports.DDE_PATH = defaultFiles_1.DefaultFiles.filePaths.dde.path;
|
|
19
|
+
// create file cache.
|
|
20
|
+
// yaml & json
|
|
21
|
+
// ...
|
|
22
|
+
var DDE;
|
|
23
|
+
(function (DDE) {
|
|
24
|
+
/**
|
|
25
|
+
* The json schema to validate the dde structure
|
|
26
|
+
*/
|
|
27
|
+
DDE.DDE_SCHEMA = dynamic_dde_schema_json_1.default;
|
|
28
|
+
async function readYamlFile(filePath, fs) {
|
|
29
|
+
const yamlBin = await fs.readFile(filePath);
|
|
30
|
+
return (0, FS_1.convertBlobToString)(yamlBin);
|
|
31
|
+
}
|
|
32
|
+
DDE.readYamlFile = readYamlFile;
|
|
33
|
+
/**
|
|
34
|
+
* Validate all dde files if they are valid based on the json schema
|
|
35
|
+
* @param cwd
|
|
36
|
+
* @param fs
|
|
37
|
+
* @param fileName
|
|
38
|
+
*/
|
|
39
|
+
async function validate(cwd, fs, fileName = defaultFiles_1.DefaultFiles.fileNames.mainDDE) {
|
|
40
|
+
const manifest = await manifest_1.Manifest.read(cwd, fs);
|
|
41
|
+
const allLibraryFiles = await getDependencies(cwd, fs, manifest);
|
|
42
|
+
for (const libraryFile of allLibraryFiles) {
|
|
43
|
+
await validateJsonSchema(libraryFile.path, libraryFile.yaml);
|
|
44
|
+
}
|
|
45
|
+
// read project dde
|
|
46
|
+
const mainDdePath = vscode_uri_1.Utils.joinPath(cwd, exports.DDE_PATH, fileName);
|
|
47
|
+
const mainDdeYaml = await readYamlFile(mainDdePath, fs);
|
|
48
|
+
await validateJsonSchema(mainDdePath, mainDdeYaml);
|
|
49
|
+
return {
|
|
50
|
+
manifest,
|
|
51
|
+
libraryFiles: allLibraryFiles,
|
|
52
|
+
main: {
|
|
53
|
+
path: mainDdePath,
|
|
54
|
+
yaml: mainDdeYaml
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
DDE.validate = validate;
|
|
59
|
+
/**
|
|
60
|
+
* Run dde compiler in the given studio directory
|
|
61
|
+
* @param cwd
|
|
62
|
+
* @param fs
|
|
63
|
+
* @param fileName
|
|
64
|
+
*/
|
|
65
|
+
async function compileDDE(cwd, fs, fileName = defaultFiles_1.DefaultFiles.fileNames.mainDDE) {
|
|
66
|
+
const validated = await validate(cwd, fs, fileName);
|
|
67
|
+
const historyJson = await getHistoryJson(cwd, fs);
|
|
68
|
+
const preCompiler = new yamlDdePreCompiler_1.YamlPreCompiler.PreCompiler(validated.manifest, validated.libraryFiles, historyJson);
|
|
69
|
+
const libraryDiagnostics = preCompiler.parseLibraries();
|
|
70
|
+
const librariesHaveError = libraryDiagnostics.find(diagnostics => diagnostics.level === 'error');
|
|
71
|
+
if (librariesHaveError) {
|
|
72
|
+
return { ddeJSON: null, diagnostics: libraryDiagnostics };
|
|
73
|
+
}
|
|
74
|
+
const { ddeJSON, diagnostics } = preCompiler.parseMainDDE(validated.main.path, validated.main.yaml);
|
|
75
|
+
return { ddeJSON, diagnostics };
|
|
76
|
+
}
|
|
77
|
+
DDE.compileDDE = compileDDE;
|
|
78
|
+
const ajv = new ajv_1.default({
|
|
79
|
+
strict: false,
|
|
80
|
+
allErrors: true,
|
|
81
|
+
verbose: true
|
|
82
|
+
});
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
(0, ajv_formats_1.default)(ajv);
|
|
85
|
+
const validateDynamicDde = ajv.compile(DDE.DDE_SCHEMA);
|
|
86
|
+
/**
|
|
87
|
+
* Validate a given dde file against the dynamic dde schema
|
|
88
|
+
* @param ddeFilePath
|
|
89
|
+
* @param yaml
|
|
90
|
+
*/
|
|
91
|
+
async function validateJsonSchema(ddeFilePath, yaml) {
|
|
92
|
+
const json = (0, yaml_1.parseDocument)(yaml).toJSON();
|
|
93
|
+
const result = validateDynamicDde(json);
|
|
94
|
+
if (!result) {
|
|
95
|
+
const errors = validateDynamicDde.errors || [];
|
|
96
|
+
const error = new Error(`${vscode_uri_1.Utils.basename(ddeFilePath)} has "${errors.length}" errors"`);
|
|
97
|
+
errors.forEach(error => console.error(error));
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
DDE.validateJsonSchema = validateJsonSchema;
|
|
102
|
+
/**
|
|
103
|
+
* Creates and returns a new precompiler instance
|
|
104
|
+
* @param manifest
|
|
105
|
+
* @param libraries
|
|
106
|
+
* @param ddeHistory
|
|
107
|
+
* @constructor
|
|
108
|
+
*/
|
|
109
|
+
DDE.PreCompiler = (manifest, libraries, ddeHistory) => {
|
|
110
|
+
return new yamlDdePreCompiler_1.YamlPreCompiler.PreCompiler(manifest, libraries, ddeHistory);
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* File Generators
|
|
114
|
+
*/
|
|
115
|
+
/**
|
|
116
|
+
* Generate the needed xml for the myDatanet application
|
|
117
|
+
* @param ddeJSON
|
|
118
|
+
*/
|
|
119
|
+
function generateMyDatanetXML(ddeJSON) {
|
|
120
|
+
return (0, xml_1.generateXMLFromMap)(ddeJSON);
|
|
121
|
+
}
|
|
122
|
+
DDE.generateMyDatanetXML = generateMyDatanetXML;
|
|
123
|
+
/**
|
|
124
|
+
* Generate the xml dde notation and write it to the correct dist directory
|
|
125
|
+
* @param cwd
|
|
126
|
+
* @param fs
|
|
127
|
+
* @param ddeJSON
|
|
128
|
+
*/
|
|
129
|
+
async function exportMyDatanetXML(cwd, fs, ddeJSON) {
|
|
130
|
+
const xml = (0, xml_1.generateXMLFromMap)(ddeJSON);
|
|
131
|
+
const distFile = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.ddeXmlPath);
|
|
132
|
+
await fs.writeFile(distFile, xml);
|
|
133
|
+
console.log('Generated', defaultFiles_1.DefaultFiles.filePaths.dist.ddeXmlPath);
|
|
134
|
+
}
|
|
135
|
+
DDE.exportMyDatanetXML = exportMyDatanetXML;
|
|
136
|
+
})(DDE || (exports.DDE = DDE = {}));
|
|
137
|
+
async function getDependencies(cwd, fs, manifest) {
|
|
138
|
+
const ddeFiles = [];
|
|
139
|
+
const allDependencies = await dependencies_1.Dependencies.getAll(manifest);
|
|
140
|
+
for (const dependencyId in allDependencies) {
|
|
141
|
+
const depPath = dependencies_1.Dependencies.dependencyToPath(cwd, dependencyId);
|
|
142
|
+
const name = dependencies_1.Dependencies.dependencyIdToName(dependencyId);
|
|
143
|
+
const ddePath = vscode_uri_1.Utils.joinPath(depPath, `${exports.DDE_PATH}/${name}.dde`);
|
|
144
|
+
const hasDDE = await fs.stat(ddePath);
|
|
145
|
+
if (hasDDE) {
|
|
146
|
+
ddeFiles.push({
|
|
147
|
+
libraryName: name,
|
|
148
|
+
path: ddePath,
|
|
149
|
+
yaml: await DDE.readYamlFile(ddePath, fs)
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// push library projects dde file also into the list
|
|
154
|
+
if (manifest_1.Manifest.isLibraryProject(manifest)) {
|
|
155
|
+
const projectLibPath = vscode_uri_1.Utils.joinPath(cwd, `/${exports.DDE_PATH}/${manifest.name}.dde`);
|
|
156
|
+
if (await fs.stat(projectLibPath)) {
|
|
157
|
+
ddeFiles.push({
|
|
158
|
+
libraryName: manifest.name,
|
|
159
|
+
path: projectLibPath,
|
|
160
|
+
yaml: await DDE.readYamlFile(projectLibPath, fs)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return ddeFiles;
|
|
165
|
+
}
|
|
166
|
+
async function getHistoryJson(cwd, fs) {
|
|
167
|
+
const historyPath = vscode_uri_1.Utils.joinPath(cwd, exports.DDE_PATH, 'history.json');
|
|
168
|
+
try {
|
|
169
|
+
const binary = await fs.readFile(historyPath);
|
|
170
|
+
const historyString = (0, FS_1.convertBlobToString)(binary);
|
|
171
|
+
return JSON.parse(historyString);
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
console.warn('history.json does not exist');
|
|
175
|
+
return {};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=dde.js.map
|