Skip to content

Commit

Permalink
Bump meteor-typescript NPM version,
Browse files Browse the repository at this point in the history
process typings accordingly to the structure the typings util lays them out (main and browser),
minor improvements to the logging

Urigo/angular2-meteor#102
  • Loading branch information
barbatus committed May 4, 2016
1 parent 788a543 commit b909ca1
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 44 deletions.
40 changes: 24 additions & 16 deletions logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,49 @@ const util = Npm.require('util');

class Logger_ {
constructor() {
this.llevel = process.env.TYPESCRIPT_LOG;
this.llevel = process.env.TYPESCRIPT_LOG;
}

newDebug(name) {
let debug = new Debug(name);
if (this.isDebug) debug.start();
return debug;
newProfiler(name) {
let profiler = new Profiler(name);
if (this.isProfile) profiler.start();
return profiler;
}

get isDebug() {
return this.llevel >= 2;
}

log(msg) {
get isProfile() {
return this.llevel >= 3;
}

get isAssert() {
return this.llevel >= 4;
}

log(msg, ...args) {
if (this.llevel >= 1) {
console.log(msg);
console.log.apply(null, [msg].concat(args));
}
}

debug(msg) {
debug(msg, ...args) {
if (this.isDebug) {
console.log(msg);
this.log.apply(this, msg, args);
}
}

assert(msg, ...args) {
if (this.isAssert) {
this.log.apply(this, msg, args);
}
}
};

Logger = new Logger_();

class Debug {
class Profiler {
constructor(name) {
this.name = name;
}
Expand All @@ -41,12 +55,6 @@ class Debug {
this._started = true;
}

log(msg, ...args) {
if (this._started) {
console.log.apply(null, [msg].concat(args));
}
}

end() {
if (this._started) {
console.timeEnd(util.format('%s time', this.name));
Expand Down
4 changes: 2 additions & 2 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package.describe({
name: 'barbatus:typescript-compiler',
version: '0.5.7',
version: '0.5.9',
summary: 'TypeScript Compiler for Meteor',
git: 'https://github.com/barbatus/ts-compilers',
documentation: 'README.md'
});

Npm.depends({
'meteor-typescript': '0.6.4',
'meteor-typescript': '0.6.9',
'async': '1.4.0',
'minimatch': '3.0.0'
});
Expand Down
73 changes: 47 additions & 26 deletions typescript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ TypeScriptCompiler = class TypeScriptCompiler {

inputFiles = this.excludeFiles(inputFiles);

let archMap = {}, filesMap = {};
let filesMap = {}, archMap = {};
inputFiles.forEach((inputFile, index) => {
if (inputFile.isConfig()) return;

let arch = inputFile.getArch();
let archFiles = archMap[arch];
if (! archFiles) {
archFiles = [];
archMap[arch] = archFiles;
}
archFiles.push(inputFile);
filesMap[this.getExtendedPath(inputFile)] = index;
archMap[inputFile.getArch()] = [];
});

_.keys(archMap).forEach(arch => {
let archFiles = this.getArchFiles(inputFiles, arch);
archMap[arch] = archFiles;
});

let getFileContent = filePath => {
Expand All @@ -51,20 +48,21 @@ TypeScriptCompiler = class TypeScriptCompiler {
let useCache = this.tsconfig.useCache;
let buildOptions = { compilerOptions, typings, useCache };

let dcompile = Logger.newDebug('compilation');
let pcompile = Logger.newProfiler('compilation');
_.keys(archMap).forEach((arch, cb) => {
let archFiles = archMap[arch];
let filePaths = archFiles.map(inputFile => this.getExtendedPath(inputFile));
dcompile.log('process files: %s', filePaths);
Logger.log('process files: %s', filePaths);
buildOptions.arch = arch;

let dbuild = Logger.newDebug('tsBuild');
let pbuild = Logger.newProfiler('tsBuild');
let tsBuild = new TSBuild(filePaths, getFileContent, buildOptions);
pbuild.end();

let pfiles = Logger.newProfiler('tsEmitFiles');
let future = new Future;
async.each(archFiles, (inputFile, cb) => {
if (inputFile.isDeclaration()) { cb(); return; };

// Don't emit typings.
archFiles = archFiles.filter(inputFile => !inputFile.isDeclaration());
async.eachLimit(archFiles, this.maxParallelism, (inputFile, cb) => {
let co = compilerOptions;
let source = inputFile.getContentsAsString();
let inputFilePath = inputFile.getPathInPackage();
Expand All @@ -81,28 +79,27 @@ TypeScriptCompiler = class TypeScriptCompiler {
let filePath = this.getExtendedPath(inputFile);
let moduleName = this.getFileModuleName(inputFile, co);

let demit = Logger.newDebug('tsEmit');
let pemit = Logger.newProfiler('tsEmit');
let result = tsBuild.emit(filePath, moduleName);
this.processDiagnostics(inputFile, result.diagnostics, co);
demit.end();
pemit.end();

toBeAdded.data = result.code;
let module = compilerOptions.module;
toBeAdded.bare = toBeAdded.bare || module === 'none';
toBeAdded.hash = result.hash;
toBeAdded.sourceMap = result.sourceMap;

inputFile.addJavaScript(toBeAdded);

cb();
}, future.resolver());

future.wait();
pfiles.end();

dbuild.end();
future.wait();
});

dcompile.end();
pcompile.end();
}

extendFiles(inputFiles, mixins) {
Expand Down Expand Up @@ -193,19 +190,43 @@ TypeScriptCompiler = class TypeScriptCompiler {
excludeFiles(inputFiles) {
let resultFiles = inputFiles;

let dexclude = Logger.newDebug('exclude');
let pexclude = Logger.newProfiler('exclude');
for (let ex of this.tsconfig.exclude) {
resultFiles = resultFiles.filter(inputFile => {
let path = inputFile.getPathInPackage();
dexclude.log('exclude pattern %s: %s', ex, path);
Logger.assert('exclude pattern %s: %s', ex, path);
return ! minimatch(path, ex);
});
}
dexclude.end();
pexclude.end();

return resultFiles;
}

getArchFiles(inputFiles, arch) {
let archFiles = inputFiles.filter((inputFile, index) => {
if (inputFile.isConfig()) return false;

return inputFile.getArch() === arch;
});

// Include only typings that current arch needs,
// typings/main is for the server only and
// typings/browser - for the client.
let excludes = arch.startsWith('web') ?
['typings/main/**', 'typings/main.d.ts'] :
['typings/browser/**', 'typings/browser.d.ts'];

for (let ex of excludes) {
archFiles = archFiles.filter(inputFile => {
let path = inputFile.getPathInPackage();
return ! minimatch(path, ex);
});
}

return archFiles;
}

getTypings(filePaths) {
check(filePaths, Array);

Expand Down

0 comments on commit b909ca1

Please sign in to comment.