From bea1cd79b11f0c1954873974182756adf8dcfec0 Mon Sep 17 00:00:00 2001 From: Jeremy Danyow Date: Wed, 12 Oct 2016 23:39:54 -0400 Subject: [PATCH] fix(build): fix api.json generation related to #357 --- doc/shape-defs.js | 24 ++++++++++++++++++++++++ doc/tsconfig.json | 2 +- package.json | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/doc/shape-defs.js b/doc/shape-defs.js index fec1ce4e..7dc97bd9 100644 --- a/doc/shape-defs.js +++ b/doc/shape-defs.js @@ -9,6 +9,22 @@ try { const dtsPath = path.resolve(__dirname, `../dist/doc-temp/${packageName}.d.ts`); let defs = fs.readFileSync(dtsPath).toString(); + // aggregate external imports + const packages = {}; + const importRegex = /^\s*import\s+\{([^}]+)\}\s*from\s*'([\w|-]+)'/gm; + let importMatch = importRegex.exec(defs); + while (importMatch) { + const packageName = importMatch[2]; + const imports = packages[packageName] || (packages[packageName] = []); + const bindings = importMatch[1].split(',').map(x => x.trim()); + for (let binding of bindings) { + if (imports.indexOf(binding) === -1) { + imports.push(binding); + } + } + importMatch = importRegex.exec(defs); + } + // remove leading declare module defs = defs.replace(/^declare module ".*" \{/, ''); // remove "} declare module {" @@ -20,6 +36,14 @@ try { // remove "export *" defs = defs.replace(/^\s+export \*.*;$/gm, ''); + // write imports + for (let packageName in packages) { + if (packages.hasOwnProperty(packageName)) { + const imports = packages[packageName]; + defs = `import {${imports.sort()}} from '${packageName}';\n` + defs; + } + } + fs.writeFileSync(dtsPath, defs); console.log(`Shaped the dist/doc-temp/${packageName}.d.ts file.`); } catch (e) { diff --git a/doc/tsconfig.json b/doc/tsconfig.json index d07b2da1..21202da9 100644 --- a/doc/tsconfig.json +++ b/doc/tsconfig.json @@ -3,7 +3,7 @@ "compilerOptions": { "module": "commonjs", "moduleResolution": "node", - "target": "es5", + "target": "es6", "outDir": "dist/native-modules", "noImplicitAny": true, "noImplicitReturns": true, diff --git a/package.json b/package.json index 3e109062..e7432b7f 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "requirejs": "^2.2.0", "requirejs-text": "^2.0.12", "rimraf": "^2.5.4", - "typedoc": "^0.4.5", + "typedoc": "^0.5.0", "typescript": "^2.0.0" }, "aurelia": {