-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #623 from davismj/build/typescript
refactor: Convert to TypeScript
- Loading branch information
Showing
37 changed files
with
7,660 additions
and
8,099 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ jspm_packages | |
bower_components | ||
.idea | ||
.DS_STORE | ||
.rollupcache | ||
build/reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typescript.tsdk": "aurelia-router/node_modules/typescript/lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
const rollup = require('rollup'); | ||
const typescript = require('rollup-plugin-typescript2'); | ||
const rimraf = require('rimraf'); | ||
|
||
const LIB_NAME = 'aurelia-router'; | ||
const cacheRoot = '.rollupcache'; | ||
const externalLibs = [ | ||
'aurelia-dependency-injection', | ||
'aurelia-event-aggregator', | ||
'aurelia-logging', | ||
'aurelia-history', | ||
'aurelia-route-recognizer' | ||
]; | ||
|
||
clean().then(build).then(generateDts); | ||
|
||
/** | ||
* @type {() => Promise<Error | null>} | ||
*/ | ||
function clean() { | ||
console.log('\n==============\nCleaning dist folder...\n=============='); | ||
return new Promise(resolve => { | ||
rimraf('dist', (error) => { | ||
if (error) { | ||
throw error; | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
function generateDts() { | ||
console.log('\n==============\nGenerating dts bundle...\n=============='); | ||
return new Promise(resolve => { | ||
const ChildProcess = require('child_process'); | ||
ChildProcess.exec('npm run bundle-dts', (err, stdout, stderr) => { | ||
if (err || stderr) { | ||
console.log('Generating dts error:'); | ||
console.log(stderr); | ||
} else { | ||
console.log('Generated dts bundle successfully'); | ||
console.log(stdout); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
}; | ||
|
||
function build() { | ||
console.log('\n==============\nBuidling...\n=============='); | ||
return Promise.all([ | ||
{ | ||
input: 'src/index.ts', | ||
output: [ | ||
{ file: 'dist/es2015/index.js', format: 'es' } | ||
], | ||
external: externalLibs, | ||
plugins: [ | ||
typescript({ | ||
tsconfigOverride: { | ||
compilerOptions: { | ||
target: 'es2015' | ||
} | ||
}, | ||
cacheRoot: cacheRoot | ||
}), | ||
] | ||
}, | ||
{ | ||
input: 'src/index.ts', | ||
output: [ | ||
{ file: 'dist/commonjs/index.js', format: 'cjs' }, | ||
{ file: 'dist/amd/index.js', format: 'amd', amd: { id: LIB_NAME } }, | ||
{ file: 'dist/native-modules/index.js', format: 'es' } | ||
], | ||
external: externalLibs, | ||
plugins: [ | ||
typescript({ | ||
useTsconfigDeclarationDir: true, | ||
tsconfigOverride: { | ||
compilerOptions: { | ||
target: 'es5' | ||
} | ||
}, | ||
cacheRoot: cacheRoot | ||
}), | ||
] | ||
} | ||
].map(cfg => { | ||
return rollup | ||
.rollup(cfg) | ||
.then(bundle => Promise.all(cfg.output.map(o => bundle.write(o)))); | ||
})); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const fs = require('fs'); | ||
const paths = require('../paths'); | ||
const path = require('path'); | ||
const conventionalChangelog = require('conventional-changelog'); | ||
const dest = path.resolve(process.cwd(), paths.doc, 'CHANGELOG.md'); | ||
|
||
let changelogChunk = ''; | ||
const changelogStream = conventionalChangelog({ preset: 'angular' }) | ||
.on('data', chunk => changelogChunk += chunk.toString('utf8')) | ||
.on('end', () => { | ||
changelogStream.removeAllListeners(); | ||
const data = fs.readFileSync(dest, 'utf-8'); | ||
const fd = fs.openSync(dest, 'w+'); | ||
fs.writeSync(fd, Buffer.from(changelogChunk, 'utf8'), 0, changelogChunk.length, 0); | ||
fs.writeSync(fd, Buffer.from(data, 'utf8'), 0, data.length, changelogChunk.length); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
const args = require('../tasks/args'); | ||
const rollup = require('rollup'); | ||
const typescript = require('rollup-plugin-typescript2'); | ||
const ChildProcess = require('child_process'); | ||
|
||
const targetFormats = args.format || ['commonjs']; // by default only run devs for commonjs | ||
const targetDir = args.target; | ||
|
||
const buildConfigs = { | ||
es2015: { | ||
output: { | ||
file: 'dist/es2015/index.js', | ||
format: 'es' | ||
}, | ||
tsConfig: { | ||
tsconfigOverride: { | ||
compilerOptions: { | ||
target: 'es2015' | ||
} | ||
} | ||
} | ||
}, | ||
amd: { | ||
output: { | ||
file: 'dist/amd/index.js', | ||
format: 'amd', | ||
amd: { id: 'aurelia-router' } | ||
}, | ||
tsConfig: { | ||
tsconfigOverride: { | ||
compilerOptions: { | ||
target: 'es5' | ||
} | ||
} | ||
} | ||
}, | ||
commonjs: { | ||
output: { | ||
file: 'dist/commonjs/index.js', | ||
format: 'cjs' | ||
}, | ||
tsConfig: { | ||
tsconfigOverride: { | ||
compilerOptions: { | ||
target: 'es5' | ||
} | ||
} | ||
} | ||
}, | ||
'native-modules': { | ||
output: { | ||
file: 'dist/commonjs/index.js', | ||
format: 'es' | ||
}, | ||
tsConfig: { | ||
tsconfigOverride: { | ||
compilerOptions: { | ||
target: 'es5' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
console.log('Running dev with targets:', targetFormats); | ||
|
||
/** | ||
* @param {string} format | ||
*/ | ||
async function roll(format) { | ||
const inputOptions = { | ||
input: 'src/index.ts', | ||
external: [ | ||
'aurelia-dependency-injection', | ||
'aurelia-event-aggregator', | ||
'aurelia-logging', | ||
'aurelia-history', | ||
'aurelia-route-recognizer' | ||
], | ||
plugins: [ | ||
typescript(Object.assign( | ||
{ cacheRoot: '.rollupcache' }, | ||
buildConfigs[format].tsConfig | ||
)) | ||
] | ||
}; | ||
console.log('Starting watcher'); | ||
const watcher = rollup | ||
.watch({ | ||
...inputOptions, | ||
output: buildConfigs[format].output | ||
}); | ||
|
||
watcher.on('event', (e) => { | ||
if (e.code === 'BUNDLE_END') { | ||
console.log('Finished compilation. Running post task bundling dts.'); | ||
generateDtsBundle(); | ||
} | ||
}); | ||
} | ||
|
||
function generateDtsBundle() { | ||
return new Promise(resolve => { | ||
ChildProcess.exec('npm run bundle-dts', (err, stdout, stderr) => { | ||
if (err || stderr) { | ||
console.log('Bundling dts error'); | ||
console.log(err); | ||
console.log('========'); | ||
console.log('stderr'); | ||
console.log(stderr); | ||
} else { | ||
console.log('Generated dts bundle successfully'); | ||
} | ||
resolve(err ? [null, err] : [null, null]); | ||
}); | ||
}); | ||
} | ||
|
||
targetFormats.forEach(roll); | ||
|
||
console.log('Target directory for copy: "' + targetDir + '"'); | ||
if (targetDir) { | ||
console.log('Watching dist folder'); | ||
const gulpWatch = require('gulp-watch'); | ||
const path = require('path'); | ||
const cwd = process.cwd(); | ||
const destPath = path.join(cwd, targetDir, 'node_modules', 'aurelia-router'); | ||
const fs = require('fs'); | ||
gulpWatch('dist/**/*.*', { ignoreInitial: true }, (vinyl) => { | ||
if (vinyl.event !== 'unlink') { | ||
console.log(`change occurred at "${vinyl.path}". Copying over to specified project`); | ||
const subPath = vinyl.path.replace(cwd, ''); | ||
try { | ||
fs.createReadStream(vinyl.path) | ||
.pipe(fs.createWriteStream(path.join(destPath, subPath))); | ||
} catch (ex) { | ||
console.log(`Error trying to copy file from "${vinyl.path}" to "${destPath}"`); | ||
console.log(ex); | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = require('yargs') | ||
.options('target', { | ||
alias: 't', | ||
description: 'target module dir to copy build results into (eg. "--target ../other-module" to copy build results into "../other-module/node_modules/this-module/dist/…" whenever they change)' | ||
}) | ||
.options('format', { | ||
alias: 'f', | ||
array: true, | ||
description: 'format to compile to (eg. "es2015", "commonjs", …). Can be set muliple times to compile to multiple formats. Default is all formats.' | ||
}) | ||
.argv; |
Oops, something went wrong.