@intelligentgraphics/ig.gfx.packager 3.0.0-beta.0 → 3.0.0-beta.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/build/cli.mjs +43 -338
- package/build/cli.mjs.map +1 -1
- package/build/commands/build/docs.mjs +34 -0
- package/build/commands/build/docs.mjs.map +1 -0
- package/build/commands/build/index.mjs +169 -0
- package/build/commands/build/index.mjs.map +1 -0
- package/build/commands/build/tsc.mjs +84 -0
- package/build/commands/build/tsc.mjs.map +1 -0
- package/build/commands/{generate.ts.mjs → generate.mjs} +3 -13
- package/build/commands/generate.mjs.map +1 -0
- package/build/commands/{postinstall.ts.mjs → postinstall.mjs} +4 -11
- package/build/commands/postinstall.mjs.map +1 -0
- package/build/commands/{publish.mjs → publish/index.mjs} +20 -288
- package/build/commands/publish/index.mjs.map +1 -0
- package/build/commands/publish/zip.mjs +168 -0
- package/build/commands/publish/zip.mjs.map +1 -0
- package/build/commands/{publishNpm.ts.mjs → publishNpm.mjs} +11 -19
- package/build/commands/publishNpm.mjs.map +1 -0
- package/build/index.mjs +1 -1
- package/build/index.mjs.map +1 -1
- package/build/lib/assetService.mjs +111 -0
- package/build/lib/assetService.mjs.map +1 -0
- package/build/lib/banner.mjs +20 -0
- package/build/lib/banner.mjs.map +1 -0
- package/build/{dependencies.mjs → lib/dependencies.mjs} +4 -64
- package/build/lib/dependencies.mjs.map +1 -0
- package/build/lib/error.mjs +15 -0
- package/build/lib/error.mjs.map +1 -0
- package/build/lib/fs.mjs +19 -0
- package/build/lib/fs.mjs.map +1 -0
- package/build/lib/git.mjs +37 -0
- package/build/lib/git.mjs.map +1 -0
- package/build/lib/localization.mjs +16 -0
- package/build/lib/localization.mjs.map +1 -0
- package/build/lib/log.mjs +9 -0
- package/build/lib/log.mjs.map +1 -0
- package/build/lib/npmPackage.mjs +19 -0
- package/build/lib/npmPackage.mjs.map +1 -0
- package/build/lib/package.mjs +129 -0
- package/build/lib/package.mjs.map +1 -0
- package/build/lib/packageVersion.mjs +174 -0
- package/build/lib/packageVersion.mjs.map +1 -0
- package/build/lib/parseVersion.mjs +54 -0
- package/build/lib/parseVersion.mjs.map +1 -0
- package/build/lib/prompter.mjs +31 -0
- package/build/lib/prompter.mjs.map +1 -0
- package/build/lib/publishedPackage.mjs +66 -0
- package/build/lib/publishedPackage.mjs.map +1 -0
- package/build/{scripts.mjs → lib/scripts.mjs} +1 -2
- package/build/lib/scripts.mjs.map +1 -0
- package/build/lib/stripUtf8Bom.mjs +11 -0
- package/build/lib/stripUtf8Bom.mjs.map +1 -0
- package/build/lib/toposort.mjs +26 -0
- package/build/lib/toposort.mjs.map +1 -0
- package/build/lib/versionFile.mjs +78 -0
- package/build/lib/versionFile.mjs.map +1 -0
- package/build/lib/workspace.mjs +51 -0
- package/build/lib/workspace.mjs.map +1 -0
- package/package.json +2 -2
- package/readme.md +5 -0
- package/build/commands/build.mjs +0 -326
- package/build/commands/build.mjs.map +0 -1
- package/build/commands/generate.ts.mjs.map +0 -1
- package/build/commands/postinstall.ts.mjs.map +0 -1
- package/build/commands/publish.mjs.map +0 -1
- package/build/commands/publishNpm.ts.mjs.map +0 -1
- package/build/dependencies.mjs.map +0 -1
- package/build/scripts.mjs.map +0 -1
- package/build/versionFile.mjs +0 -365
- package/build/versionFile.mjs.map +0 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as terser from 'terser';
|
|
4
|
+
import { logPackageMessage } from '../../lib/log.mjs';
|
|
5
|
+
import { translate } from '../../lib/localization.mjs';
|
|
6
|
+
import { build } from './tsc.mjs';
|
|
7
|
+
import { generateDocs } from './docs.mjs';
|
|
8
|
+
import { readPackageCreatorManifest, readPackageNpmManifest } from '../../lib/package.mjs';
|
|
9
|
+
import { getPackageTypescriptFiles } from '../../lib/scripts.mjs';
|
|
10
|
+
import { toposort } from '../../lib/toposort.mjs';
|
|
11
|
+
|
|
12
|
+
const buildFolders = async options => {
|
|
13
|
+
if (options.outDir !== undefined && options.clean) {
|
|
14
|
+
fs.rmSync(options.outDir, {
|
|
15
|
+
recursive: true
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const workspace = options.workspace;
|
|
19
|
+
const folders = options.packages;
|
|
20
|
+
const sortedPackages = sortPackagesByBuildOrder(folders);
|
|
21
|
+
let index = 1;
|
|
22
|
+
for (const location of sortedPackages) {
|
|
23
|
+
if (options.skipPackagesWithoutTsFiles && getPackageTypescriptFiles(location).length === 0) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
ensureTsConfig(location);
|
|
27
|
+
const data = readPackageCreatorManifest(location);
|
|
28
|
+
const logStep = step => logPackageMessage(data.Package, step, index, folders.length);
|
|
29
|
+
logStep(translate("messages.building"));
|
|
30
|
+
const outputDirectory = options.outDir || location.scriptsDir;
|
|
31
|
+
fs.mkdirSync(outputDirectory, {
|
|
32
|
+
recursive: true
|
|
33
|
+
});
|
|
34
|
+
const buildResult = await build(location, outputDirectory);
|
|
35
|
+
const banner = options.banner ? createBannerComment(options.banner) : undefined;
|
|
36
|
+
if (banner) {
|
|
37
|
+
buildResult.js = banner + "\n" + buildResult.js;
|
|
38
|
+
buildResult.definitions = banner + "\n" + buildResult.definitions;
|
|
39
|
+
}
|
|
40
|
+
fs.writeFileSync(path.join(outputDirectory, `${data.Package}.js`), buildResult.js, {
|
|
41
|
+
encoding: "utf8"
|
|
42
|
+
});
|
|
43
|
+
fs.writeFileSync(path.join(outputDirectory, `${data.Package}.d.ts`), buildResult.definitions, {
|
|
44
|
+
encoding: "utf8"
|
|
45
|
+
});
|
|
46
|
+
if (options.minimize) {
|
|
47
|
+
const minifyResult = await terser.minify(buildResult.js, {
|
|
48
|
+
ecma: 5
|
|
49
|
+
});
|
|
50
|
+
const minifiedPath = path.join(outputDirectory, `${data.Package}.min.js`);
|
|
51
|
+
fs.writeFileSync(minifiedPath, minifyResult.code, {
|
|
52
|
+
encoding: "utf8"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (location.path.includes("Basics")) {
|
|
56
|
+
fs.mkdirSync(path.join(workspace.path, "lib"), {
|
|
57
|
+
recursive: true
|
|
58
|
+
});
|
|
59
|
+
logStep(translate("messages.basicsCopy"));
|
|
60
|
+
fs.writeFileSync(path.join(workspace.path, "lib", `${data.Package}.d.ts`), buildResult.definitions, {
|
|
61
|
+
encoding: "utf8"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (options.docs) {
|
|
65
|
+
logStep(translate("messages.docsGeneration"));
|
|
66
|
+
await generateDocs(location, path.join(outputDirectory, `${data.Package}.d.ts`), path.join(workspace.path, "docs", data.Package), data.Package);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// logStep(translate("messages.built"));
|
|
70
|
+
|
|
71
|
+
index++;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const ensureTsConfig = location => {
|
|
75
|
+
const tsconfigPath = path.join(location.scriptsDir, "tsconfig.json");
|
|
76
|
+
if (!fs.existsSync(tsconfigPath)) {
|
|
77
|
+
const content = {};
|
|
78
|
+
applyTsConfigOption(content);
|
|
79
|
+
fs.writeFileSync(tsconfigPath, JSON.stringify(content, undefined, "\t"), "utf8");
|
|
80
|
+
} else {
|
|
81
|
+
const content = JSON.parse(fs.readFileSync(tsconfigPath, "utf8"));
|
|
82
|
+
applyTsConfigOption(content);
|
|
83
|
+
fs.writeFileSync(tsconfigPath, JSON.stringify(content, undefined, "\t"), "utf8");
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const applyTsConfigOption = data => {
|
|
87
|
+
data.compilerOptions = data.compilerOptions ?? {};
|
|
88
|
+
data.compilerOptions.target = "es5";
|
|
89
|
+
data.compilerOptions.lib = ["es5", "dom"];
|
|
90
|
+
};
|
|
91
|
+
const sortPackagesByBuildOrder = folders => {
|
|
92
|
+
const packages = Array.from(folders).reduce((acc, location) => {
|
|
93
|
+
const data = readPackageNpmManifest(location);
|
|
94
|
+
if (data !== undefined) {
|
|
95
|
+
acc[data.name] = {
|
|
96
|
+
data,
|
|
97
|
+
location
|
|
98
|
+
};
|
|
99
|
+
} else {
|
|
100
|
+
acc[location.path] = {
|
|
101
|
+
data: undefined,
|
|
102
|
+
location
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return acc;
|
|
106
|
+
}, {});
|
|
107
|
+
const packageDependencies = Object.getOwnPropertyNames(packages).reduce((acc, packageName) => {
|
|
108
|
+
const packageData = packages[packageName];
|
|
109
|
+
if (packageData.data === undefined) {
|
|
110
|
+
acc[packageName] = [];
|
|
111
|
+
} else {
|
|
112
|
+
acc[packageName] = Object.getOwnPropertyNames({
|
|
113
|
+
...packageData.data.devDependencies,
|
|
114
|
+
...packageData.data.dependencies,
|
|
115
|
+
...packageData.data.peerDependencies
|
|
116
|
+
}).filter(packageName => packages[packageName] !== undefined);
|
|
117
|
+
}
|
|
118
|
+
return acc;
|
|
119
|
+
}, {});
|
|
120
|
+
const sortedPackages = toposort(packageDependencies);
|
|
121
|
+
const result = [];
|
|
122
|
+
for (const packageName of sortedPackages) {
|
|
123
|
+
const location = packages[packageName].location;
|
|
124
|
+
if (readPackageCreatorManifest(location).Package.endsWith(".Basics")) {
|
|
125
|
+
result.unshift(location);
|
|
126
|
+
} else {
|
|
127
|
+
result.push(location);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
};
|
|
132
|
+
const createBannerComment = banner => {
|
|
133
|
+
const bannerParts = [];
|
|
134
|
+
if (banner.text) {
|
|
135
|
+
bannerParts.push(" * " + banner.text);
|
|
136
|
+
}
|
|
137
|
+
{
|
|
138
|
+
const details = [];
|
|
139
|
+
if (banner.version) {
|
|
140
|
+
details.push(`Version: ${banner.version}`);
|
|
141
|
+
}
|
|
142
|
+
if (banner.commit) {
|
|
143
|
+
if (banner.commitDirty) {
|
|
144
|
+
details.push(`Commit: ${banner.commit} (dirty)`);
|
|
145
|
+
} else {
|
|
146
|
+
details.push(`Commit: ${banner.commit}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (banner.date) {
|
|
150
|
+
details.push(`Date: ${banner.date.toISOString()}`);
|
|
151
|
+
}
|
|
152
|
+
const detailsText = details.map(line => ` * ${line}`).join("\n");
|
|
153
|
+
if (detailsText) {
|
|
154
|
+
bannerParts.push(detailsText);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const bannerText = bannerParts.join("\n\n");
|
|
158
|
+
if (bannerText) {
|
|
159
|
+
return `/*
|
|
160
|
+
${bannerText}
|
|
161
|
+
*
|
|
162
|
+
* @preserve
|
|
163
|
+
*/`;
|
|
164
|
+
}
|
|
165
|
+
return undefined;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export { buildFolders };
|
|
169
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/commands/build/index.ts"],"sourcesContent":["import * as path from \"path\";\nimport * as fs from \"fs\";\nimport * as terser from \"terser\";\n\nimport { logPackageMessage } from \"../../lib/log\";\nimport { translate } from \"../../lib/localization\";\nimport { build as tscBuild } from \"./tsc\";\nimport { generateDocs } from \"./docs\";\nimport {\n\tPackageLocation,\n\treadPackageCreatorManifest,\n\treadPackageNpmManifest,\n} from \"../../lib/package\";\nimport { WorkspaceLocation } from \"../../lib/workspace\";\nimport { getPackageTypescriptFiles } from \"../../lib/scripts\";\nimport { toposort } from \"../../lib/toposort\";\nimport { PackageJSON } from \"../../lib/packageJSON\";\n\nexport interface BannerOptions {\n\ttext: string | undefined;\n\tversion: string | undefined;\n\tcommit: string | undefined;\n\tcommitDirty: boolean | undefined;\n\tdate: Date | undefined;\n}\n\nexport interface BuildFoldersOptions {\n\tworkspace: WorkspaceLocation;\n\tpackages: PackageLocation[];\n\toutDir?: string;\n\tminimize: boolean;\n\tbanner?: BannerOptions;\n\tclean?: boolean;\n\tdocs?: boolean;\n\tskipPackagesWithoutTsFiles?: boolean;\n}\n\nexport interface BuildFolderOptions extends BuildFoldersOptions {\n\toutFile: string;\n}\n\nexport interface FolderBuilderResult {\n\tjs: string;\n\tdefinitions: string;\n}\n\nexport type FolderBuilder = (\n\tlocation: PackageLocation,\n\toutputDir: string,\n) => Promise<FolderBuilderResult>;\n\ntype FolderData = {\n\tlocation: PackageLocation;\n\tdata?: PackageJSON;\n};\n\nexport const buildFolders = async (options: BuildFoldersOptions) => {\n\tif (options.outDir !== undefined && options.clean) {\n\t\tfs.rmSync(options.outDir, { recursive: true });\n\t}\n\n\tconst workspace = options.workspace;\n\tconst folders = options.packages;\n\n\tconst sortedPackages = sortPackagesByBuildOrder(folders);\n\n\tlet index = 1;\n\n\tfor (const location of sortedPackages) {\n\t\tif (\n\t\t\toptions.skipPackagesWithoutTsFiles &&\n\t\t\tgetPackageTypescriptFiles(location).length === 0\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tensureTsConfig(location);\n\n\t\tconst data = readPackageCreatorManifest(location);\n\n\t\tconst logStep = (step: string) =>\n\t\t\tlogPackageMessage(data.Package, step, index, folders.length);\n\n\t\tlogStep(translate(\"messages.building\"));\n\n\t\tconst outputDirectory = options.outDir || location.scriptsDir;\n\t\tfs.mkdirSync(outputDirectory, { recursive: true });\n\n\t\tconst buildResult = await tscBuild(location, outputDirectory);\n\t\tconst banner = options.banner\n\t\t\t? createBannerComment(options.banner)\n\t\t\t: undefined;\n\n\t\tif (banner) {\n\t\t\tbuildResult.js = banner + \"\\n\" + buildResult.js;\n\t\t\tbuildResult.definitions = banner + \"\\n\" + buildResult.definitions;\n\t\t}\n\n\t\tfs.writeFileSync(\n\t\t\tpath.join(outputDirectory, `${data.Package}.js`),\n\t\t\tbuildResult.js,\n\t\t\t{ encoding: \"utf8\" },\n\t\t);\n\t\tfs.writeFileSync(\n\t\t\tpath.join(outputDirectory, `${data.Package}.d.ts`),\n\t\t\tbuildResult.definitions,\n\t\t\t{ encoding: \"utf8\" },\n\t\t);\n\n\t\tif (options.minimize) {\n\t\t\tconst minifyResult = await terser.minify(buildResult.js, {\n\t\t\t\tecma: 5,\n\t\t\t});\n\n\t\t\tconst minifiedPath = path.join(\n\t\t\t\toutputDirectory,\n\t\t\t\t`${data.Package}.min.js`,\n\t\t\t);\n\t\t\tfs.writeFileSync(minifiedPath, minifyResult.code!, {\n\t\t\t\tencoding: \"utf8\",\n\t\t\t});\n\t\t}\n\n\t\tif (location.path.includes(\"Basics\")) {\n\t\t\tfs.mkdirSync(path.join(workspace.path, \"lib\"), {\n\t\t\t\trecursive: true,\n\t\t\t});\n\n\t\t\tlogStep(translate(\"messages.basicsCopy\"));\n\t\t\tfs.writeFileSync(\n\t\t\t\tpath.join(workspace.path, \"lib\", `${data.Package}.d.ts`),\n\t\t\t\tbuildResult.definitions,\n\t\t\t\t{ encoding: \"utf8\" },\n\t\t\t);\n\t\t}\n\n\t\tif (options.docs) {\n\t\t\tlogStep(translate(\"messages.docsGeneration\"));\n\t\t\tawait generateDocs(\n\t\t\t\tlocation,\n\t\t\t\tpath.join(outputDirectory, `${data.Package}.d.ts`),\n\t\t\t\tpath.join(workspace.path, \"docs\", data.Package),\n\t\t\t\tdata.Package,\n\t\t\t);\n\t\t}\n\n\t\t// logStep(translate(\"messages.built\"));\n\n\t\tindex++;\n\t}\n};\n\nconst ensureTsConfig = (location: PackageLocation) => {\n\tconst tsconfigPath = path.join(location.scriptsDir, \"tsconfig.json\");\n\n\tif (!fs.existsSync(tsconfigPath)) {\n\t\tconst content = {};\n\t\tapplyTsConfigOption(content);\n\n\t\tfs.writeFileSync(\n\t\t\ttsconfigPath,\n\t\t\tJSON.stringify(content, undefined, \"\\t\"),\n\t\t\t\"utf8\",\n\t\t);\n\t} else {\n\t\tconst content = JSON.parse(fs.readFileSync(tsconfigPath, \"utf8\"));\n\t\tapplyTsConfigOption(content);\n\t\tfs.writeFileSync(\n\t\t\ttsconfigPath,\n\t\t\tJSON.stringify(content, undefined, \"\\t\"),\n\t\t\t\"utf8\",\n\t\t);\n\t}\n};\n\nconst applyTsConfigOption = (data: {\n\tcompilerOptions?: { target?: string; lib?: string[] };\n}) => {\n\tdata.compilerOptions = data.compilerOptions ?? {};\n\tdata.compilerOptions.target = \"es5\";\n\tdata.compilerOptions.lib = [\"es5\", \"dom\"];\n};\n\nconst sortPackagesByBuildOrder = (\n\tfolders: PackageLocation[],\n): PackageLocation[] => {\n\tconst packages = Array.from(folders).reduce(\n\t\t(\n\t\t\tacc: Record<string, FolderData>,\n\t\t\tlocation,\n\t\t): Record<string, FolderData> => {\n\t\t\tconst data = readPackageNpmManifest(location);\n\n\t\t\tif (data !== undefined) {\n\t\t\t\tacc[data.name] = {\n\t\t\t\t\tdata,\n\t\t\t\t\tlocation,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tacc[location.path] = {\n\t\t\t\t\tdata: undefined,\n\t\t\t\t\tlocation,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n\n\tconst packageDependencies = Object.getOwnPropertyNames(packages).reduce(\n\t\t(acc, packageName) => {\n\t\t\tconst packageData = packages[packageName];\n\n\t\t\tif (packageData.data === undefined) {\n\t\t\t\tacc[packageName] = [];\n\t\t\t} else {\n\t\t\t\tacc[packageName] = Object.getOwnPropertyNames({\n\t\t\t\t\t...packageData.data.devDependencies,\n\t\t\t\t\t...packageData.data.dependencies,\n\t\t\t\t\t...packageData.data.peerDependencies,\n\t\t\t\t}).filter((packageName) => packages[packageName] !== undefined);\n\t\t\t}\n\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n\n\tconst sortedPackages = toposort(packageDependencies);\n\tconst result: PackageLocation[] = [];\n\n\tfor (const packageName of sortedPackages) {\n\t\tconst location = packages[packageName].location;\n\n\t\tif (readPackageCreatorManifest(location).Package.endsWith(\".Basics\")) {\n\t\t\tresult.unshift(location);\n\t\t} else {\n\t\t\tresult.push(location);\n\t\t}\n\t}\n\n\treturn result;\n};\n\nconst createBannerComment = (banner: BannerOptions) => {\n\tconst bannerParts: string[] = [];\n\n\tif (banner.text) {\n\t\tbannerParts.push(\" * \" + banner.text);\n\t}\n\n\t{\n\t\tconst details: string[] = [];\n\n\t\tif (banner.version) {\n\t\t\tdetails.push(`Version: ${banner.version}`);\n\t\t}\n\t\tif (banner.commit) {\n\t\t\tif (banner.commitDirty) {\n\t\t\t\tdetails.push(`Commit: ${banner.commit} (dirty)`);\n\t\t\t} else {\n\t\t\t\tdetails.push(`Commit: ${banner.commit}`);\n\t\t\t}\n\t\t}\n\t\tif (banner.date) {\n\t\t\tdetails.push(`Date: ${banner.date.toISOString()}`);\n\t\t}\n\n\t\tconst detailsText = details.map((line) => ` * ${line}`).join(\"\\n\");\n\t\tif (detailsText) {\n\t\t\tbannerParts.push(detailsText);\n\t\t}\n\t}\n\n\tconst bannerText = bannerParts.join(\"\\n\\n\");\n\n\tif (bannerText) {\n\t\treturn `/*\n${bannerText}\n*\n* @preserve\t\t\t\n*/`;\n\t}\n\n\treturn undefined;\n};\n"],"names":["buildFolders","options","outDir","undefined","clean","fs","rmSync","recursive","workspace","folders","packages","sortedPackages","sortPackagesByBuildOrder","index","location","skipPackagesWithoutTsFiles","getPackageTypescriptFiles","length","ensureTsConfig","data","readPackageCreatorManifest","logStep","step","logPackageMessage","Package","translate","outputDirectory","scriptsDir","mkdirSync","buildResult","tscBuild","banner","createBannerComment","js","definitions","writeFileSync","path","join","encoding","minimize","minifyResult","terser","minify","ecma","minifiedPath","code","includes","docs","generateDocs","tsconfigPath","existsSync","content","applyTsConfigOption","JSON","stringify","parse","readFileSync","compilerOptions","target","lib","Array","from","reduce","acc","readPackageNpmManifest","name","packageDependencies","Object","getOwnPropertyNames","packageName","packageData","devDependencies","dependencies","peerDependencies","filter","toposort","result","endsWith","unshift","push","bannerParts","text","details","version","commit","commitDirty","date","toISOString","detailsText","map","line","bannerText"],"mappings":";;;;;;;;;;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,IAAI,CAAC,CAAA;AAClE,IAAA,IAAImD,WAAW,EAAE;AAChBR,MAAAA,WAAW,CAACD,IAAI,CAACS,WAAW,CAAC,CAAA;AAC9B,KAAA;AACD,GAAA;AAEA,EAAA,MAAMG,UAAU,GAAGX,WAAW,CAAC3C,IAAI,CAAC,MAAM,CAAC,CAAA;AAE3C,EAAA,IAAIsD,UAAU,EAAE;IACf,OAAQ,CAAA;AACV,EAAEA,UAAW,CAAA;AACb;AACA;AACA,EAAG,CAAA,CAAA;AACF,GAAA;AAEA,EAAA,OAAOxF,SAAS,CAAA;AACjB,CAAC;;;;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import { getPackageTypescriptFiles } from '../../lib/scripts.mjs';
|
|
5
|
+
|
|
6
|
+
const tryReadTsConfig = location => {
|
|
7
|
+
const {
|
|
8
|
+
config
|
|
9
|
+
} = ts.readConfigFile(path.join(location.scriptsDir, "tsconfig.json"), path => {
|
|
10
|
+
try {
|
|
11
|
+
return fs.readFileSync(path, "utf8");
|
|
12
|
+
} catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return config;
|
|
17
|
+
};
|
|
18
|
+
const build = async (location, outputDir) => {
|
|
19
|
+
const config = tryReadTsConfig(location);
|
|
20
|
+
config.compilerOptions.lib = ["es5", "dom"];
|
|
21
|
+
const result = ts.convertCompilerOptionsFromJson(config.compilerOptions, location.scriptsDir);
|
|
22
|
+
const compilerOptions = {
|
|
23
|
+
...result.options,
|
|
24
|
+
removeComments: false,
|
|
25
|
+
declaration: true,
|
|
26
|
+
sourceMap: false,
|
|
27
|
+
// We don't use tsc to actually emit the files, but we still need to set the correct
|
|
28
|
+
// output directory so the compiler can rewrite the `reference path` directives.
|
|
29
|
+
outFile: path.join(outputDir, "out.js"),
|
|
30
|
+
target: ts.ScriptTarget.ES5,
|
|
31
|
+
noEmitOnError: true
|
|
32
|
+
};
|
|
33
|
+
const host = ts.createCompilerHost(compilerOptions);
|
|
34
|
+
host.getCurrentDirectory = () => location.scriptsDir;
|
|
35
|
+
let js;
|
|
36
|
+
let definitions;
|
|
37
|
+
host.writeFile = (fileName, data, writeByteOrderMark) => {
|
|
38
|
+
if (fileName.endsWith(".js")) {
|
|
39
|
+
js = data;
|
|
40
|
+
} else if (fileName.endsWith(".d.ts")) {
|
|
41
|
+
definitions = data;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const files = getPackageTypescriptFiles(location);
|
|
45
|
+
if (files.length === 0) {
|
|
46
|
+
throw new Error(`Expected typescript files to exist when building a package. Packages only consisting of animation jsons do not need to be built.`);
|
|
47
|
+
}
|
|
48
|
+
const programOptions = {
|
|
49
|
+
rootNames: files,
|
|
50
|
+
options: compilerOptions,
|
|
51
|
+
host
|
|
52
|
+
};
|
|
53
|
+
const program = ts.createProgram(programOptions);
|
|
54
|
+
const emitResult = program.emit();
|
|
55
|
+
const allDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
56
|
+
if (!emitResult.emitSkipped) {
|
|
57
|
+
if (allDiagnostics.length > 0) {
|
|
58
|
+
console.log(allDiagnostics.map(createErrorMessage).join("\n"));
|
|
59
|
+
}
|
|
60
|
+
if (js === undefined || definitions === undefined) {
|
|
61
|
+
throw new Error(`Unexpected: no js or definitions were created`);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
js,
|
|
65
|
+
definitions
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const error = allDiagnostics.map(createErrorMessage).join("\n");
|
|
69
|
+
throw new Error(error);
|
|
70
|
+
};
|
|
71
|
+
const createErrorMessage = diagnostic => {
|
|
72
|
+
if (!diagnostic.file) {
|
|
73
|
+
return `${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`;
|
|
74
|
+
}
|
|
75
|
+
const {
|
|
76
|
+
line,
|
|
77
|
+
character
|
|
78
|
+
} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
79
|
+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
80
|
+
return `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export { build, tryReadTsConfig };
|
|
84
|
+
//# sourceMappingURL=tsc.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsc.mjs","sources":["../../../src/commands/build/tsc.ts"],"sourcesContent":["import ts from \"typescript\";\nimport * as path from \"path\";\nimport * as fs from \"fs\";\n\nimport { PackageLocation } from \"../../lib/package\";\n\nimport { FolderBuilder } from \".\";\nimport { getPackageTypescriptFiles } from \"../../lib/scripts\";\n\nexport const tryReadTsConfig = (location: PackageLocation) => {\n\tconst { config } = ts.readConfigFile(\n\t\tpath.join(location.scriptsDir, \"tsconfig.json\"),\n\t\t(path) => {\n\t\t\ttry {\n\t\t\t\treturn fs.readFileSync(path, \"utf8\");\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t);\n\n\treturn config as {\n\t\tcompilerOptions: ts.CompilerOptions;\n\t};\n};\n\nexport const build: FolderBuilder = async (\n\tlocation: PackageLocation,\n\toutputDir: string,\n) => {\n\tconst config = tryReadTsConfig(location);\n\n\tconfig.compilerOptions.lib = [\"es5\", \"dom\"];\n\n\tconst result = ts.convertCompilerOptionsFromJson(\n\t\tconfig.compilerOptions,\n\t\tlocation.scriptsDir,\n\t);\n\n\tconst compilerOptions: ts.CompilerOptions = {\n\t\t...result.options,\n\t\tremoveComments: false,\n\t\tdeclaration: true,\n\t\tsourceMap: false,\n\t\t// We don't use tsc to actually emit the files, but we still need to set the correct\n\t\t// output directory so the compiler can rewrite the `reference path` directives.\n\t\toutFile: path.join(outputDir, \"out.js\"),\n\t\ttarget: ts.ScriptTarget.ES5,\n\t\tnoEmitOnError: true,\n\t};\n\n\tconst host = ts.createCompilerHost(compilerOptions);\n\thost.getCurrentDirectory = () => location.scriptsDir;\n\n\tlet js: string | undefined;\n\tlet definitions: string | undefined;\n\n\thost.writeFile = (fileName, data, writeByteOrderMark) => {\n\t\tif (fileName.endsWith(\".js\")) {\n\t\t\tjs = data;\n\t\t} else if (fileName.endsWith(\".d.ts\")) {\n\t\t\tdefinitions = data;\n\t\t}\n\t};\n\n\tconst files = getPackageTypescriptFiles(location);\n\n\tif (files.length === 0) {\n\t\tthrow new Error(\n\t\t\t`Expected typescript files to exist when building a package. Packages only consisting of animation jsons do not need to be built.`,\n\t\t);\n\t}\n\n\tconst programOptions: ts.CreateProgramOptions = {\n\t\trootNames: files,\n\t\toptions: compilerOptions,\n\t\thost,\n\t};\n\n\tconst program = ts.createProgram(programOptions);\n\tconst emitResult = program.emit();\n\tconst allDiagnostics = ts.getPreEmitDiagnostics(program);\n\n\tif (!emitResult.emitSkipped) {\n\t\tif (allDiagnostics.length > 0) {\n\t\t\tconsole.log(allDiagnostics.map(createErrorMessage).join(\"\\n\"));\n\t\t}\n\n\t\tif (js === undefined || definitions === undefined) {\n\t\t\tthrow new Error(`Unexpected: no js or definitions were created`);\n\t\t}\n\n\t\treturn { js, definitions };\n\t}\n\n\tconst error = allDiagnostics.map(createErrorMessage).join(\"\\n\");\n\n\tthrow new Error(error);\n};\n\nconst createErrorMessage = (diagnostic: ts.Diagnostic) => {\n\tif (!diagnostic.file) {\n\t\treturn `${ts.flattenDiagnosticMessageText(\n\t\t\tdiagnostic.messageText,\n\t\t\t\"\\n\",\n\t\t)}`;\n\t}\n\n\tconst { line, character } = diagnostic.file.getLineAndCharacterOfPosition(\n\t\tdiagnostic.start!,\n\t);\n\n\tconst message = ts.flattenDiagnosticMessageText(\n\t\tdiagnostic.messageText,\n\t\t\"\\n\",\n\t);\n\n\treturn `${diagnostic.file.fileName} (${line + 1},${\n\t\tcharacter + 1\n\t}): ${message}`;\n};\n"],"names":["tryReadTsConfig","location","config","ts","readConfigFile","path","join","scriptsDir","fs","readFileSync","undefined","build","outputDir","compilerOptions","lib","result","convertCompilerOptionsFromJson","options","removeComments","declaration","sourceMap","outFile","target","ScriptTarget","ES5","noEmitOnError","host","createCompilerHost","getCurrentDirectory","js","definitions","writeFile","fileName","data","writeByteOrderMark","endsWith","files","getPackageTypescriptFiles","length","Error","programOptions","rootNames","program","createProgram","emitResult","emit","allDiagnostics","getPreEmitDiagnostics","emitSkipped","console","log","map","createErrorMessage","error","diagnostic","file","flattenDiagnosticMessageText","messageText","line","character","getLineAndCharacterOfPosition","start","message"],"mappings":";;;;;AASaA,MAAAA,eAAe,GAAIC,QAAyB,IAAK;EAC7D,MAAM;AAAEC,IAAAA,MAAAA;AAAO,GAAC,GAAGC,EAAE,CAACC,cAAc,CACnCC,IAAI,CAACC,IAAI,CAACL,QAAQ,CAACM,UAAU,EAAE,eAAe,CAAC,EAC9CF,IAAI,IAAK;IACT,IAAI;AACH,MAAA,OAAOG,EAAE,CAACC,YAAY,CAACJ,IAAI,EAAE,MAAM,CAAC,CAAA;AACrC,KAAC,CAAC,MAAM;AACP,MAAA,OAAOK,SAAS,CAAA;AACjB,KAAA;AACD,GAAC,CACD,CAAA;AAED,EAAA,OAAOR,MAAM,CAAA;AAGd,EAAC;MAEYS,KAAoB,GAAG,OACnCV,QAAyB,EACzBW,SAAiB,KACb;AACJ,EAAA,MAAMV,MAAM,GAAGF,eAAe,CAACC,QAAQ,CAAC,CAAA;EAExCC,MAAM,CAACW,eAAe,CAACC,GAAG,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAE3C,EAAA,MAAMC,MAAM,GAAGZ,EAAE,CAACa,8BAA8B,CAC/Cd,MAAM,CAACW,eAAe,EACtBZ,QAAQ,CAACM,UAAU,CACnB,CAAA;AAED,EAAA,MAAMM,eAAmC,GAAG;IAC3C,GAAGE,MAAM,CAACE,OAAO;AACjBC,IAAAA,cAAc,EAAE,KAAK;AACrBC,IAAAA,WAAW,EAAE,IAAI;AAC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AAAA,EAAAA,IAAI,GAAG,CAAE,IAC/CC,SAAS,GAAG,CACZ,CAAA,GAAA,EAAKG,OAAQ,CAAC,CAAA,CAAA;AAChB,CAAC;;;;"}
|
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
import ts from 'typescript';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import 'update-notifier';
|
|
6
|
-
import 'fs';
|
|
7
|
-
import 'path';
|
|
8
|
-
import 'yargs/yargs';
|
|
9
|
-
import 'url';
|
|
10
|
-
import 'y18n';
|
|
11
|
-
import 'write-pkg';
|
|
12
|
-
import 'inquirer';
|
|
13
|
-
import 'glob';
|
|
2
|
+
import { writePackageCreatorIndex } from '../lib/package.mjs';
|
|
3
|
+
import { getPackageTypescriptFiles } from '../lib/scripts.mjs';
|
|
14
4
|
|
|
15
5
|
function findTsNode(node, callback) {
|
|
16
6
|
let result;
|
|
@@ -189,4 +179,4 @@ function extract(location, ignore = []) {
|
|
|
189
179
|
}
|
|
190
180
|
|
|
191
181
|
export { extract };
|
|
192
|
-
//# sourceMappingURL=generate.
|
|
182
|
+
//# sourceMappingURL=generate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.mjs","sources":["../../src/commands/generate.ts"],"sourcesContent":["import ts from \"typescript\";\n\nimport {\n\tPackageLocation,\n\twritePackageCreatorIndex,\n\treadPackageCreatorIndex,\n} from \"../lib/package\";\nimport { getPackageTypescriptFiles } from \"../lib/scripts\";\nimport {\n\tCreatorIndexEntry,\n\tCreatorIndexParameter,\n\tCreatorIndexParameterType,\n} from \"../lib/package\";\n\nfunction findTsNode<T extends ts.Node>(\n\tnode: ts.Node,\n\tcallback: (node: ts.Node) => node is T,\n): T | undefined;\nfunction findTsNode(\n\tnode: ts.Node,\n\tcallback: (node: ts.Node) => boolean,\n): ts.Node | undefined;\nfunction findTsNode(\n\tnode: ts.Node,\n\tcallback: (node: ts.Node) => boolean,\n): ts.Node | undefined {\n\tlet result: ts.Node | undefined;\n\n\tts.forEachChild(node, (child) => {\n\t\tif (callback(child)) {\n\t\t\tresult = child;\n\t\t\treturn true;\n\t\t}\n\t});\n\n\treturn result;\n}\n\nfunction capitalizeFirstLetter(string) {\n\treturn string?.charAt(0).toUpperCase() + string?.slice(1);\n}\n\nfunction parseDefault(value: string, type: string) {\n\tconst uType: CreatorIndexParameterType = capitalizeFirstLetter(type);\n\tif (value === \"null\") return null;\n\tswitch (uType) {\n\t\tcase \"LengthM\":\n\t\tcase \"ArcDEG\":\n\t\tcase \"Float\":\n\t\t\treturn parseFloat(value);\n\t\tcase \"Integer\":\n\t\tcase \"Int\":\n\t\t\treturn parseInt(value);\n\t\tcase \"Boolean\":\n\t\tcase \"Bool\":\n\t\t\treturn value === \"true\";\n\t\tcase \"Material\":\n\t\tcase \"String\":\n\t\tdefault:\n\t\t\treturn value.replace(/^\"/, \"\").replace(/\"$/, \"\");\n\t}\n}\n\nfunction findEvaluatorNode(node: ts.Node): ts.ClassDeclaration | undefined {\n\tif (\n\t\tts.isModuleDeclaration(node) &&\n\t\tnode.body &&\n\t\tts.isModuleDeclaration(node.body) &&\n\t\tnode.body.body\n\t) {\n\t\tconst classDeclaration = findTsNode(\n\t\t\tnode.body.body,\n\t\t\t(child): child is ts.ClassDeclaration => {\n\t\t\t\tif (!ts.isClassDeclaration(child)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tconst isEvaluator = child.heritageClauses?.some((clause) => {\n\t\t\t\t\tif (clause.token !== ts.SyntaxKind.ExtendsKeyword) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn clause.types.some((type) =>\n\t\t\t\t\t\ttype.getText().includes(\"Evaluator\"),\n\t\t\t\t\t);\n\t\t\t\t});\n\n\t\t\t\treturn isEvaluator ?? false;\n\t\t\t},\n\t\t);\n\n\t\treturn classDeclaration;\n\t}\n}\n\nfunction getParameter(evaluatorNode: ts.ClassDeclaration) {\n\tlet memb = evaluatorNode.members?.find(\n\t\t(member) => member?.name?.getText().toLowerCase() == \"create\",\n\t);\n\tif (ts.isMethodDeclaration(memb!)) {\n\t\treturn memb.parameters.find(\n\t\t\t(para) => para.name.getText().toLowerCase() == \"parameters\",\n\t\t);\n\t}\n}\n\nfunction findParametersInterface(\n\tnode: ts.Node,\n\tinterfaceName: string,\n): ts.InterfaceDeclaration | undefined {\n\tif (\n\t\tts.isModuleDeclaration(node) &&\n\t\tnode.body &&\n\t\tts.isModuleDeclaration(node.body) &&\n\t\tnode.body.body\n\t) {\n\t\tconst interfaceDeclaration = findTsNode(\n\t\t\tnode.body.body,\n\t\t\t(child): child is ts.InterfaceDeclaration =>\n\t\t\t\tts.isInterfaceDeclaration(child) &&\n\t\t\t\tchild.name.getText() == interfaceName,\n\t\t);\n\n\t\treturn interfaceDeclaration;\n\t}\n\n\treturn undefined;\n}\n\nfunction getModuleName(sourceFile: ts.Node): string {\n\tlet fullName = \"\";\n\tif (ts.isModuleDeclaration(sourceFile)) {\n\t\tfullName += sourceFile.name.getText();\n\n\t\tlet packageB = sourceFile.body!;\n\t\tif (ts.isModuleDeclaration(packageB)) {\n\t\t\tfullName += \".\" + packageB.name.getText();\n\t\t}\n\t}\n\treturn fullName;\n}\n\nfunction genParameters(\n\tinterfac: ts.InterfaceDeclaration,\n): CreatorIndexParameter[] {\n\treturn interfac.members.map((member, i) => {\n\t\tlet para = {} as CreatorIndexParameter;\n\n\t\tpara.Name = member.name!.getText();\n\t\tif (para.Name.length > 45)\n\t\t\tthrow new Error(`Parameter name length >45 '${para.Name}'`);\n\n\t\tlet rawDocTags = ts.getJSDocTags(member);\n\t\tif (rawDocTags.length) {\n\t\t\tlet dict = getTagDict(rawDocTags);\n\t\t\tif (dict.summary) para.Description = dict.summary;\n\t\t\tif (dict.creatorType)\n\t\t\t\tpara.Type = dict.creatorType as CreatorIndexParameterType;\n\t\t\tif (dict.default && dict.creatorType)\n\t\t\t\tpara.Default = parseDefault(dict.default, dict.creatorType);\n\t\t\tpara.DisplayIndex = i + 1;\n\t\t}\n\t\treturn para;\n\t});\n}\n\ninterface IDocTags {\n\tdefault?: string;\n\tcreatorType?: string;\n\tsummary?: string;\n}\n\nfunction getTagDict(tags: any): IDocTags {\n\tlet dict = {};\n\ttags.forEach((tag) => {\n\t\tdict[tag.tagName.text] = tag.comment;\n\t});\n\treturn dict;\n}\n\nfunction findParametersInterfaceInFiles(\n\tprogram: ts.Program,\n\tfileList: string[],\n\tname: string,\n): ts.InterfaceDeclaration | undefined {\n\tfor (const file of fileList) {\n\t\tconst sourceFile = program.getSourceFile(file);\n\n\t\tif (sourceFile === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`Expected a source file to exist for file name \"${file}\"`,\n\t\t\t);\n\t\t}\n\n\t\tlet interfaceDeclaration: ts.InterfaceDeclaration | undefined;\n\n\t\tts.forEachChild(sourceFile, (node) => {\n\t\t\tinterfaceDeclaration = findParametersInterface(node, name);\n\n\t\t\treturn interfaceDeclaration !== undefined;\n\t\t});\n\n\t\tif (interfaceDeclaration !== undefined) {\n\t\t\treturn interfaceDeclaration;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Extracts and returns script array for _Index.json from a src folder\n *\n * @param folderPath path to a src folder\n */\nexport function extract(location: PackageLocation, ignore: string[] = []) {\n\tconst files = getPackageTypescriptFiles(location);\n\tconst filtered = files.filter((path) => {\n\t\treturn !ignore.some((suffix) => path.endsWith(suffix));\n\t});\n\tlet arr = new Array<CreatorIndexEntry>();\n\n\tlet program = ts.createProgram(filtered, { allowJs: true });\n\tprogram.getTypeChecker();\n\tfiltered.forEach((file) => {\n\t\t// Create a Program to represent the project, then pull out the\n\t\t// source file to parse its AST.\n\t\tconst sourceFile = program.getSourceFile(file);\n\n\t\t// Loop through the root AST nodes of the file\n\t\tts.forEachChild(sourceFile!, (node) => {\n\t\t\tconst evalNode = findEvaluatorNode(node);\n\n\t\t\tif (evalNode === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet moduleName = getModuleName(node);\n\n\t\t\tif (evalNode.name === undefined) {\n\t\t\t\tthrow new Error(`Expected evaluator class to have a name`);\n\t\t\t}\n\n\t\t\tconst name = moduleName + \".\" + evalNode.name.getText();\n\n\t\t\tif (name.length > 45)\n\t\t\t\tthrow new Error(`Package name length >45 '${name}'`);\n\n\t\t\tlet para = getParameter(evalNode);\n\t\t\tlet paraName = (para?.type as any).typeName.getText();\n\t\t\tlet interfac = findParametersInterfaceInFiles(\n\t\t\t\tprogram,\n\t\t\t\tfiltered,\n\t\t\t\tparaName,\n\t\t\t);\n\n\t\t\tif (interfac === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to find parameters type declaration for evaluator ${evalNode.name.getText()}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst obj: CreatorIndexEntry = {\n\t\t\t\tName: name,\n\t\t\t\tParameters: [],\n\t\t\t\tType: \"Evaluator\",\n\t\t\t};\n\n\t\t\tlet rawDocTags = ts.getJSDocTags(evalNode);\n\t\t\tif (rawDocTags.length) {\n\t\t\t\tlet dict = getTagDict(rawDocTags);\n\t\t\t\tif (dict.summary) obj.Description = dict.summary;\n\t\t\t\tif (dict.creatorType)\n\t\t\t\t\tobj.Type = dict.creatorType as \"Interactor\" | \"Evaluator\";\n\t\t\t}\n\n\t\t\tobj.Parameters = genParameters(interfac);\n\n\t\t\tarr.push(obj);\n\t\t});\n\t});\n\n\twritePackageCreatorIndex(location, arr);\n}\n"],"names":["findTsNode","node","callback","result","ts","forEachChild","child","capitalizeFirstLetter","string","charAt","toUpperCase","slice","parseDefault","value","type","uType","parseFloat","parseInt","replace","findEvaluatorNode","isModuleDeclaration","body","classDeclaration","isClassDeclaration","isEvaluator","heritageClauses","some","clause","token","SyntaxKind","ExtendsKeyword","types","getText","includes","getParameter","evaluatorNode","memb","members","find","member","name","toLowerCase","isMethodDeclaration","parameters","para","findParametersInterface","interfaceName","interfaceDeclaration","isInterfaceDeclaration","undefined","getModuleName","sourceFile","fullName","packageB","genParameters","interfac","map","i","Name","length","Error","rawDocTags","getJSDocTags","dict","getTagDict","summary","Description","creatorType","Type","default","Default","DisplayIndex","tags","forEach","tag","tagName","text","comment","findParametersInterfaceInFiles","program","fileList","file","getSourceFile","extract","location","ignore","files","getPackageTypescriptFiles","filtered","filter","path","suffix","endsWith","arr","Array","createProgram","allowJs","getTypeChecker","evalNode","moduleName","paraName","typeName","obj","Parameters","push","writePackageCreatorIndex"],"mappings":";;;;AAsBA,SAASA,UAAU,CAClBC,IAAa,EACbC,QAAoC,EACd;AACtB,EAAA,IAAIC,MAA2B,CAAA;AAE/BC,EAAAA,EAAE,CAACC,YAAY,CAACJ,IAAI,EAAGK,KAAK,IAAK;AAChC,IAAA,IAAIJ,QAAQ,CAACI,KAAK,CAAC,EAAE;AACpBH,MAAAA,MAAM,GAAGG,KAAK,CAAA;AACd,MAAA,OAAO,IAAI,CAAA;AACZ,KAAA;AACD,GAAC,CAAC,CAAA;AAEF,EAAA,OAAOH,MAAM,CAAA;AACd,CAAA;AAEA,SAASI,qBAAqB,CAACC,MAAM,EAAE;EACtC,OAAO,CAAAA,MAAM,KAAA,IAAA,IAANA,MAAM,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAANA,MAAM,CAAEC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,EAAE,KAAGF,MAAM,KAAA,IAAA,IAANA,MAAM,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAANA,MAAM,CAAEG,KAAK,CAAC,CAAC,CAAC,CAAA,CAAA;AAC1D,CAAA;AAEA,SAASC,YAAY,CAACC,KAAa,EAAEC,IAAY,EAAE;AAClD,EAAA,MAAMC,KAAgC,GAAGR,qBAAqB,CAACO,IAAI,CAAC,CAAA;AACpE,EAAA,IAAID,KAAK,KAAK,MAAM,EAAE,OAAO,IAAI,CAAA;AACjC,EAAA,QAAQE,KAAK;AACZ,IAAA,KAAK,SA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ACN,CAAA;AAED,MAAA,IAAIP,UAAU,GAAGzD,EAAE,CAAC0D,YAAY,CAACoC,QAAQ,CAAC,CAAA;MAC1C,IAAIrC,UAAU,CAACF,MAAM,EAAE;AACtB,QAAA,IAAII,IAAI,GAAGC,UAAU,CAACH,UAAU,CAAC,CAAA;QACjC,IAAIE,IAAI,CAACE,OAAO,EAAEqC,GAAG,CAACpC,WAAW,GAAGH,IAAI,CAACE,OAAO,CAAA;QAChD,IAAIF,IAAI,CAACI,WAAW,EACnBmC,GAAG,CAAClC,IAAI,GAAGL,IAAI,CAACI,WAAyC,CAAA;AAC3D,OAAA;AAEAmC,MAAAA,GAAG,CAACC,UAAU,GAAGjD,aAAa,CAACC,QAAQ,CAAC,CAAA;AAExCsC,MAAAA,GAAG,CAACW,IAAI,CAACF,GAAG,CAAC,CAAA;AACd,KAAC,CAAC,CAAA;AACH,GAAC,CAAC,CAAA;AAEFG,EAAAA,wBAAwB,CAACrB,QAAQ,EAAES,GAAG,CAAC,CAAA;AACxC;;;;"}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
import * as path from 'path';
|
|
3
2
|
import * as fs from 'fs';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import '
|
|
7
|
-
import 'yargs/yargs';
|
|
8
|
-
import 'url';
|
|
9
|
-
import 'y18n';
|
|
10
|
-
import 'write-pkg';
|
|
11
|
-
import 'inquirer';
|
|
12
|
-
import 'resolve';
|
|
3
|
+
import { readWorkspaceNpmManifest, getWorkspaceLibPath } from '../lib/workspace.mjs';
|
|
4
|
+
import { readPublishedPackageNpmManifest } from '../lib/publishedPackage.mjs';
|
|
5
|
+
import { determineWorkspaceIGLibraries } from '../lib/dependencies.mjs';
|
|
13
6
|
|
|
14
7
|
const DEFINITION_FILE_HINT = "// This file is automatically managed by the ig.gfx.packager.";
|
|
15
8
|
const executePostInstall = workspace => {
|
|
@@ -49,4 +42,4 @@ const executePostInstall = workspace => {
|
|
|
49
42
|
};
|
|
50
43
|
|
|
51
44
|
export { executePostInstall };
|
|
52
|
-
//# sourceMappingURL=postinstall.
|
|
45
|
+
//# sourceMappingURL=postinstall.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postinstall.mjs","sources":["../../src/commands/postinstall.ts"],"sourcesContent":["import * as path from \"path\";\nimport * as fs from \"fs\";\n\nimport {\n\tgetWorkspaceLibPath,\n\treadWorkspaceNpmManifest,\n\tWorkspaceLocation,\n} from \"../lib/workspace\";\nimport { readPublishedPackageNpmManifest } from \"../lib/publishedPackage\";\nimport { determineWorkspaceIGLibraries } from \"../lib/dependencies\";\n\nconst DEFINITION_FILE_HINT =\n\t\"// This file is automatically managed by the ig.gfx.packager.\";\n\nexport const executePostInstall = (workspace: WorkspaceLocation) => {\n\tconst manifest = readWorkspaceNpmManifest(workspace);\n\n\tif (manifest === undefined) {\n\t\tthrow new Error(`Expected an npm manifest to exist.`);\n\t}\n\n\tconst libPath = getWorkspaceLibPath(workspace);\n\n\tfs.mkdirSync(libPath, { recursive: true });\n\n\tconst existingDefinitions = fs.readdirSync(libPath);\n\n\t// delete all existing definition files that are managed by the packager.\n\t// we'll recreate all needed definitions in the next step.\n\tfor (const existingDefinitionName of existingDefinitions) {\n\t\tconst content = fs.readFileSync(\n\t\t\tpath.join(libPath, existingDefinitionName),\n\t\t\t{ encoding: \"utf-8\" },\n\t\t);\n\n\t\tif (content.startsWith(DEFINITION_FILE_HINT)) {\n\t\t\tfs.rmSync(path.join(libPath, existingDefinitionName));\n\t\t}\n\t}\n\n\tconst libraryLocations = determineWorkspaceIGLibraries(workspace);\n\n\tfor (const location of libraryLocations) {\n\t\tconst manifest = readPublishedPackageNpmManifest(location);\n\n\t\t// add a hint to the top of the file so we know it's managed by the packager.\n\t\tconst content = `${DEFINITION_FILE_HINT}\n// This is a reference to version ${manifest.version}.\n// Run \"npm install\" to install the types if they are missing or not up to date.\n/// <reference types=\"${manifest.name}\" />`;\n\n\t\tfs.writeFileSync(\n\t\t\tpath.join(getWorkspaceLibPath(workspace), manifest.types),\n\t\t\tcontent,\n\t\t\t{\n\t\t\t\tencoding: \"utf8\",\n\t\t\t},\n\t\t);\n\t}\n};\n"],"names":["DEFINITION_FILE_HINT","executePostInstall","workspace","manifest","readWorkspaceNpmManifest","undefined","Error","libPath","getWorkspaceLibPath","fs","mkdirSync","recursive","existingDefinitions","readdirSync","existingDefinitionName","content","readFileSync","path","join","encoding","startsWith","rmSync","libraryLocations","determineWorkspaceIGLibraries","location","readPublishedPackageNpmManifest","version","name","writeFileSync","types"],"mappings":";;;;;;AAWA,MAAMA,oBAAoB,GACzB,+DAA+D,CAAA;AAEnDC,MAAAA,kBAAkB,GAAIC,SAA4B,IAAK;AACnE,EAAA,MAAMC,QAAQ,GAAGC,wBAAwB,CAACF,SAAS,CAAC,CAAA;EAEpD,IAAIC,QAAQ,KAAKE,SAAS,EAAE;AAC3B,IAAA,MAAM,IAAIC,KAAK,CAAE,CAAA,kCAAA,CAAmC,CAAC,CAAA;AACtD,GAAA;AAEA,EAAA,MAAMC,OAAO,GAAGC,mBAAmB,CAACN,SAAS,CAAC,CAAA;AAE9CO,EAAAA,EAAE,CAACC,SAAS,CAACH,OAAO,EAAE;AAAEI,IAAAA,SAAS,EAAE,IAAA;AAAK,GAAC,CAAC,CAAA;AAE1C,EAAA,MAAMC,mBAAmB,GAAGH,EAAE,CAACI,WAAW,CAACN,OAAO,CAAC,CAAA;;AAEnD;AACA;AACA,EAAA,KAAK,MAAMO,sBAAsB,IAAIF,mBAAmB,EAAE;AACzD,IAAA,MAAMG,OAAO,GAAGN,EAAE,CAACO,YAAY,CAC9BC,IAAI,CAACC,IAAI,CAACX,OAAO,EAAEO,sBAAsB,CAAC,EAC1C;AAAEK,MAAAA,QAAQ,EAAE,OAAA;AAAQ,KAAC,CACrB,CAAA;AAED,IAAA,IAAIJ,OAAO,CAACK,UAAU,CAACpB,oBAAoB,CAAC,EAAE;MAC7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