Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
feat: add cli
Browse files Browse the repository at this point in the history
  • Loading branch information
KnisterPeter committed Dec 3, 2018
1 parent a05bd30 commit 0bc8693
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
19 changes: 19 additions & 0 deletions lib/compiler/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { writeFileSync } from 'fs';
import { Compiler, CompilerHost } from './compiler';

const root = process.argv.length > 1 ? process.argv[2] : undefined;

const host: CompilerHost = {
writeFile: (filename, code) => writeFileSync(filename, code)
};

Compiler.create(host, root)
.run()
.then(() => {
process.exit(0);
})
.catch(e => {
setImmediate(() => {
throw e;
});
});
10 changes: 7 additions & 3 deletions lib/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ export interface CompilerHost {
export class Compiler {
public static create(
host: CompilerHost,
languageService = Compiler.createLanguageService()
root = '.',
languageService = Compiler.createLanguageService(root)
): Compiler {
return new Compiler(host, languageService);
}

private static createLanguageService(): ts.LanguageService {
const configFile = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
private static createLanguageService(root: string): ts.LanguageService {
const configFile = ts.findConfigFile(
root || process.cwd(),
ts.sys.fileExists
);
if (!configFile) {
throw new Error('Unable to find tsconfig.json');
}
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
"collectCoverage": true,
"collectCoverageFrom": [
"lib/**"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/lib/compiler/cli.ts",
"/lib/compiler/decorators.ts"
]
},
"renovate": {
Expand Down
1 change: 1 addition & 0 deletions tests/compiler/compiler.test.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export async function runCompiler(files: {
{
writeFile: (_, data) => resolve(data)
},
'.',
service
);
await compiler.run('/decorators.ts');
Expand Down
8 changes: 8 additions & 0 deletions tests/compiler/example/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { container } from '../../../lib/compiler/decorators';

export class Entry {}

@container({ units: [] })
export abstract class Container {
public abstract entry: Entry;
}

0 comments on commit 0bc8693

Please sign in to comment.