This repository was archived by the owner on Dec 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 514
Expand file tree
/
Copy pathjsii.ts
More file actions
85 lines (73 loc) · 1.98 KB
/
jsii.ts
File metadata and controls
85 lines (73 loc) · 1.98 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import * as fs from 'fs-extra';
import * as path from 'path';
import { shell } from '../util';
export interface JsiiCompileOptions {
/**
* Name of the module.
*/
readonly name: string;
/**
* Name of the main module file without suffix.
*/
readonly main: string;
/**
* Path to the module file file.
*/
readonly providerPath: string;
/**
* Whether to print stdout.
* @default false
*/
readonly stdout?: boolean;
}
/**
* Compiles the source files in `workdir` with jsii.
*/
export async function jsiiCompile(workdir: string, options: JsiiCompileOptions) {
const stdout = options.stdout ?? false;
const name = options.name ?? 'dummy';
const compiler = require.resolve('jsii/bin/jsii');
const args = [ '--silence-warnings', 'reserved-word' ];
const main = options.main;
const modules = [
'constructs',
'cdktf',
'@types/node',
];
const pkg = {
name,
version: '0.0.0',
author: "dummy@dummy.com",
main: `${path.join(options.providerPath)}.js`,
types: `${path.join(options.providerPath)}.d.ts`,
license: 'Apache-2.0',
repository: { url: 'http://repo', type: 'git' },
jsii: {
outdir: "dist",
targets: {
python: {
distName: main.replace(/\//gi, '.'),
module: main.replace(/\//gi, '.').replace(/-/gi, '_')
}
}
},
dependencies: {
"constructs": "*",
"cdktf": "*",
},
peerDependencies: {
"constructs": "*",
"cdktf": "*",
}
};
for (const mod of modules) {
const sourcedir = path.dirname(require.resolve(`${mod}/package.json`));
await fs.mkdirp(path.join(workdir, path.join('node_modules', path.dirname(mod))));
await fs.ensureSymlink(sourcedir, path.join(workdir, 'node_modules', mod));
}
await fs.writeFile(path.join(workdir, 'package.json'), JSON.stringify(pkg, undefined, 2));
await shell(compiler, args, {
cwd: workdir,
stdio: [ 'inherit', stdout ? 'inherit' : 'ignore', 'inherit' ]
});
}