-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.ts
75 lines (66 loc) · 3.11 KB
/
js.ts
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
import * as spec from 'jsii-spec';
import { Generator } from '../generator';
import { PackageInfo, Target, TargetOptions } from '../target';
export default class JavaScript extends Target {
public static toPackageInfos(assm: spec.Assembly): { [language: string]: PackageInfo } {
const packageInfo: PackageInfo = {
repository: 'NPM',
url: `https://www.npmjs.com/package/${assm.name}/v/${assm.version}`,
usage: {
'package.json': {
language: 'js',
code: JSON.stringify({ [assm.name]: `^${assm.version}` }, null, 2)
},
'npm': {
language: 'console',
code: `$ npm i ${assm.name}@${assm.version}`
},
'yarn': {
language: 'console',
code: `$ yarn add ${assm.name}@${assm.version}`
}
}
};
return { typescript: packageInfo, javascript: packageInfo };
}
public static toNativeReference(type: spec.Type) {
const [, ...name] = type.fqn.split('.');
const resolvedName = name.join('.');
const result: { typescript: string, javascript?: string } = {
typescript: `import { ${resolvedName} } from '${type.assembly}';`
};
if (!spec.isInterfaceType(type)) {
result.javascript = `const { ${resolvedName} } = require('${type.assembly}');`;
} else {
result.javascript = `// ${resolvedName} is an interface`;
}
return result;
}
protected readonly generator = new PackOnly();
constructor(options: TargetOptions) {
super(options);
}
public build(sourceDir: string, outDir: string) {
return this.copyFiles(sourceDir, outDir);
}
}
// ##################
// # CODE GENERATOR #
// ##################
class PackOnly extends Generator {
protected getAssemblyOutputDir(_mod: spec.Assembly) {
return '.';
}
protected onBeginInterface(_ifc: spec.InterfaceType) { return; }
protected onEndInterface(_ifc: spec.InterfaceType) { return; }
protected onInterfaceMethod(_ifc: spec.InterfaceType, _method: spec.Method) { return; }
protected onInterfaceMethodOverload(_ifc: spec.InterfaceType, _overload: spec.Method, _originalMethod: spec.Method) { return; }
protected onInterfaceProperty(_ifc: spec.InterfaceType, _prop: spec.Property) { return; }
protected onProperty(_cls: spec.ClassType, _prop: spec.Property) { return; }
protected onStaticProperty(_cls: spec.ClassType, _prop: spec.Property) { return; }
protected onUnionProperty(_cls: spec.ClassType, _prop: spec.Property, _union: spec.UnionTypeReference) { return; }
protected onMethod(_cls: spec.ClassType, _method: spec.Method) { return; }
protected onMethodOverload(_cls: spec.ClassType, _overload: spec.Method, _originalMethod: spec.Method) { return; }
protected onStaticMethod(_cls: spec.ClassType, _method: spec.Method) { return; }
protected onStaticMethodOverload(_cls: spec.ClassType, _overload: spec.Method, _originalMethod: spec.Method) { return; }
}