Skip to content

Commit

Permalink
fix(build): fix api.json generation
Browse files Browse the repository at this point in the history
related to aurelia#357
  • Loading branch information
jdanyow committed Oct 13, 2016
1 parent 707835a commit bea1cd7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions doc/shape-defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {"
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion doc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
"target": "es6",
"outDir": "dist/native-modules",
"noImplicitAny": true,
"noImplicitReturns": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit bea1cd7

Please sign in to comment.