forked from eclipse-aasportal/AASPortal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-app-info.js
56 lines (46 loc) · 1.62 KB
/
create-app-info.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { readFile, writeFile } from 'fs/promises';
import { existsSync } from 'fs';
import { dirname, resolve, join } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
main();
async function main() {
const project = await read(resolve(__dirname, 'package.json'));
const file = resolve(__dirname, 'projects/aas-server/app-info.json');
const appInfo = await read(file);
for (const item in appInfo) {
appInfo[item] = project[item];
}
appInfo.libraries = await readLibrariesAsync(project);
await write(file, appInfo);
}
async function read(file) {
return JSON.parse(await readFile(file));
}
async function write(file, data) {
return writeFile(file, JSON.stringify(data));
}
async function readLibrariesAsync(project) {
const libraries = [];
let nodeModulesFolder = join(__dirname, 'node_modules');
if (existsSync(nodeModulesFolder)) {
for (const name in project.dependencies) {
let packageFile = join(nodeModulesFolder, name, 'package.json');
if (existsSync(packageFile)) {
try {
const pkg = JSON.parse((await readFile(packageFile)).toString());
libraries.push({
name: pkg.name,
version: pkg.version,
description: pkg.description,
license: pkg.license,
homepage: pkg.homepage
});
} catch (error) {
noop();
}
}
}
}
return libraries;
}