diff --git a/dist/main/atom/onSaveHandler.js b/dist/main/atom/onSaveHandler.js index 7a76e3515..eac4bf7cf 100644 --- a/dist/main/atom/onSaveHandler.js +++ b/dist/main/atom/onSaveHandler.js @@ -11,18 +11,21 @@ function handle(event) { }); mainPanelView_1.show(); parent.getProjectFileDetails({ filePath: event.filePath }).then(function (fileDetails) { - if (!fileDetails.project.compileOnSave) - return; - if (fileDetails.project.compilerOptions.out) - return; - textUpdated.then(function () { return parent.emitFile({ filePath: event.filePath }); }) - .then(function (res) { - var status = fileStatusCache_1.getFileStatus(event.filePath); - status.modified = false; - status.emitDiffers = res.emitError; - mainPanelView_1.panelView.updateFileStatus(event.filePath); - mainPanelView_1.errorView.showEmittedMessage(res); - }); + if (fileDetails.project.compileOnSave + && !fileDetails.project.compilerOptions.out + && !fileDetails.project.buildOnSave) { + textUpdated.then(function () { return parent.emitFile({ filePath: event.filePath }); }) + .then(function (res) { + var status = fileStatusCache_1.getFileStatus(event.filePath); + status.modified = false; + status.emitDiffers = res.emitError; + mainPanelView_1.panelView.updateFileStatus(event.filePath); + mainPanelView_1.errorView.showEmittedMessage(res); + }); + } + if (fileDetails.project.buildOnSave) { + atom.commands.dispatch(atom.views.getView(event.editor), 'typescript:build'); + } }); } exports.handle = handle; diff --git a/dist/main/tsconfig/tsconfig.js b/dist/main/tsconfig/tsconfig.js index 4ba925b0c..3af6f929f 100644 --- a/dist/main/tsconfig/tsconfig.js +++ b/dist/main/tsconfig/tsconfig.js @@ -154,6 +154,7 @@ function getDefaultInMemoryProject(srcFile) { typings: typings.ours.concat(typings.implicit), formatCodeOptions: formatting.defaultFormatCodeOptions(), compileOnSave: true, + buildOnSave: false, scripts: {} }; return { @@ -243,7 +244,8 @@ function getProjectSync(pathOrSrcFile) { package: pkg, typings: [], externalTranspiler: projectSpec.externalTranspiler == undefined ? undefined : projectSpec.externalTranspiler, - scripts: projectSpec.scripts || {} + scripts: projectSpec.scripts || {}, + buildOnSave: !!projectSpec.buildOnSave }; var validationResult = validator.validate(projectSpec.compilerOptions); if (validationResult.errorMessage) { diff --git a/docs/tsconfig.md b/docs/tsconfig.md index ff907b9cd..39f814b30 100644 --- a/docs/tsconfig.md +++ b/docs/tsconfig.md @@ -17,6 +17,7 @@ i.e. an empty JSON file at the *root* of your project :heart: This will be suffi * [`filesGlob`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#filesglob): To make it easier for you to just add / remove files in your project we add `filesGlob` which accepts an array of `glob / minimatch / RegExp` patterns (similar to grunt) to specify source files. * [`formatCodeOptions`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#formatcodeoptions) : Code formatting options * [`compileOnSave`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#compileonsave) : Should AtomTS compile on save +* [`buildOnSave`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#buildOnSave) : Should AtomTS build on save * [`scripts`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#scripts) : Sometimes its useful to have post build scripts * [`version`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#version) : The TypeScript version @@ -90,6 +91,15 @@ Inspired by `project.json` : https://github.com/aspnet/Home/wiki/Project.json-fi } ``` +### buildOnSave +Build means *compile all files*. Useful if for some reason you are using `--out`. Default is `false`. Note that build is a slow process, therefore we recommend leaving it off. But in case this is the way you want to go its there for your convenience. + +```json +{ + "buildOnSave": true +} +``` + ### version This exists simply to make it easier for the future you to know which TypeScript version was used when this project file was created. You can read more here [Microsoft/TypeScript#2113](https://github.com/Microsoft/TypeScript/issues/2133) diff --git a/lib/main/atom/onSaveHandler.ts b/lib/main/atom/onSaveHandler.ts index 1b4d1ba1e..c9b6b7909 100644 --- a/lib/main/atom/onSaveHandler.ts +++ b/lib/main/atom/onSaveHandler.ts @@ -30,18 +30,28 @@ export function handle(event: { filePath: string; editor: AtomCore.IEditor }) { // Compile on save parent.getProjectFileDetails({ filePath: event.filePath }).then(fileDetails => { - if (!fileDetails.project.compileOnSave) return; - if (fileDetails.project.compilerOptions.out) return; - - textUpdated.then(() => parent.emitFile({ filePath: event.filePath })) - .then((res) => { - let status = getFileStatus(event.filePath); - status.modified = false; - - // If there was a compilation error, the file differs from the one on the disk - status.emitDiffers = res.emitError; - panelView.updateFileStatus(event.filePath); - errorView.showEmittedMessage(res); - }); + if (fileDetails.project.compileOnSave + && !fileDetails.project.compilerOptions.out + && !fileDetails.project.buildOnSave) { + + textUpdated.then(() => parent.emitFile({ filePath: event.filePath })) + .then((res) => { + let status = getFileStatus(event.filePath); + status.modified = false; + + // If there was a compilation error, the file differs from the one on the disk + status.emitDiffers = res.emitError; + panelView.updateFileStatus(event.filePath); + errorView.showEmittedMessage(res); + }); + } + + if (fileDetails.project.buildOnSave) { + // Trigger a build ;) + atom.commands.dispatch( + atom.views.getView(event.editor), + 'typescript:build'); + } + }); } diff --git a/lib/main/tsconfig/tsconfig.ts b/lib/main/tsconfig/tsconfig.ts index 64ba62c5d..a22b4d43d 100644 --- a/lib/main/tsconfig/tsconfig.ts +++ b/lib/main/tsconfig/tsconfig.ts @@ -115,6 +115,7 @@ interface TypeScriptProjectRawSpecification { filesGlob?: string[]; // optional: An array of 'glob / minimatch / RegExp' patterns to specify source files formatCodeOptions?: formatting.FormatCodeOptions; // optional: formatting options compileOnSave?: boolean; // optional: compile on save. Ignored to build tools. Used by IDEs + buildOnSave?: boolean; externalTranspiler?: string; scripts?: { postbuild?: string }; } @@ -130,6 +131,7 @@ export interface TypeScriptProjectSpecification { filesGlob?: string[]; formatCodeOptions: ts.FormatCodeOptions; compileOnSave: boolean; + buildOnSave: boolean; package?: UsefulFromPackageJson; externalTranspiler?: string; scripts: { postbuild?: string }; @@ -299,12 +301,13 @@ export function getDefaultInMemoryProject(srcFile: string): TypeScriptProjectFil files = increaseProjectForReferenceAndImports(files); files = uniq(files.map(fsu.consistentPath)); - let project : TypeScriptProjectSpecification = { + let project: TypeScriptProjectSpecification = { compilerOptions: defaults, files, typings: typings.ours.concat(typings.implicit), formatCodeOptions: formatting.defaultFormatCodeOptions(), compileOnSave: true, + buildOnSave: false, scripts: {} }; @@ -417,7 +420,8 @@ export function getProjectSync(pathOrSrcFile: string): TypeScriptProjectFileDeta package: pkg, typings: [], externalTranspiler: projectSpec.externalTranspiler == undefined ? undefined : projectSpec.externalTranspiler, - scripts: projectSpec.scripts || {} + scripts: projectSpec.scripts || {}, + buildOnSave: !!projectSpec.buildOnSave }; // Validate the raw compiler options before converting them to TS compiler options @@ -426,7 +430,7 @@ export function getProjectSync(pathOrSrcFile: string): TypeScriptProjectFileDeta throw errorWithDetails( new Error(errors.GET_PROJECT_PROJECT_FILE_INVALID_OPTIONS), { projectFilePath: fsu.consistentPath(projectFile), errorMessage: validationResult.errorMessage } - ); + ); } // Convert the raw options to TS options @@ -525,17 +529,17 @@ function increaseProjectForReferenceAndImports(files: string[]): string[] { return null; }).filter(file=> !!file) .concat( - preProcessedFileInfo.importedFiles - .filter((fileReference) => pathIsRelative(fileReference.fileName)) - .map(fileReference => { - var file = path.resolve(dir, fileReference.fileName + '.ts'); - if (!fs.existsSync(file)) { - file = path.resolve(dir, fileReference.fileName + '.d.ts'); - } - return file; - }) - ) - ); + preProcessedFileInfo.importedFiles + .filter((fileReference) => pathIsRelative(fileReference.fileName)) + .map(fileReference => { + var file = path.resolve(dir, fileReference.fileName + '.ts'); + if (!fs.existsSync(file)) { + file = path.resolve(dir, fileReference.fileName + '.d.ts'); + } + return file; + }) + ) + ); }); return selectMany(referenced);