Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript -> TypeScript #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# serverless-plugin-typescript
[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) [![npm version](https://badge.fury.io/js/serverless-plugin-typescript.svg)](https://badge.fury.io/js/serverless-plugin-typescript) [![Build Status](https://travis-ci.org/prisma/serverless-plugin-typescript.svg?branch=master)](https://travis-ci.org/prisma/serverless-plugin-typescript)

Serverless plugin for zero-config Typescript support
Serverless plugin for zero-config TypeScript support

## Features

Expand Down Expand Up @@ -84,10 +84,10 @@ compilation begins, it will check to see that the file indicated exists with a

### Automatic compilation

The normal Serverless deploy procedure will automatically compile with Typescript:
The normal Serverless deploy procedure will automatically compile with TypeScript:

- Create the Serverless project with `serverless create -t aws-nodejs`
- Install Serverless Typescript as above
- Install Serverless TypeScript as above
- Deploy with `serverless deploy`

### Usage with serverless-offline
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class TypeScriptPlugin {

async compileTs(): Promise<string[]> {
this.prepare()
this.serverless.cli.log('Compiling with Typescript...')
this.serverless.cli.log('Compiling with TypeScript...')

if (!this.originalServicePath) {
// Save original service path and functions
Expand All @@ -145,15 +145,15 @@ export class TypeScriptPlugin {
this.serverless.config.servicePath = path.join(this.originalServicePath, BUILD_FOLDER)
}

const tsconfig = typescript.getTypescriptConfig(
const tsconfig = typescript.getTypeScriptConfig(
this.originalServicePath,
this.isWatching ? null : this.serverless.cli
)

tsconfig.outDir = BUILD_FOLDER

const emitedFiles = await typescript.run(this.rootFileNames, tsconfig)
this.serverless.cli.log('Typescript compiled.')
this.serverless.cli.log('TypeScript compiled.')
return emitedFiles
}

Expand Down
16 changes: 8 additions & 8 deletions src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as fs from 'fs-extra'
import * as _ from 'lodash'
import * as path from 'path'

export function makeDefaultTypescriptConfig() {
const defaultTypescriptConfig: ts.CompilerOptions = {
export function makeDefaultTypeScriptConfig() {
const defaultTypeScriptConfig: ts.CompilerOptions = {
preserveConstEnums: true,
strictNullChecks: true,
sourceMap: true,
Expand All @@ -15,7 +15,7 @@ export function makeDefaultTypescriptConfig() {
rootDir: './',
}

return defaultTypescriptConfig
return defaultTypeScriptConfig
}

export function extractFileNames(cwd: string, provider: string, functions?: { [key: string]: Serverless.Function }): string[] {
Expand All @@ -39,7 +39,7 @@ export function extractFileNames(cwd: string, provider: string, functions?: { [k
// Check that the file indeed exists.
if (!fs.existsSync(path.join(cwd, main))) {
console.log(`Cannot locate entrypoint, ${main} not found`)
throw new Error('Typescript compilation failed')
throw new Error('TypeScript compilation failed')
}

return [main]
Expand All @@ -66,7 +66,7 @@ export function extractFileNames(cwd: string, provider: string, functions?: { [k

// Can't find the files. Watch will have an exception anyway. So throw one with error.
console.log(`Cannot locate handler - ${fileName} not found`)
throw new Error('Typescript compilation failed. Please ensure handlers exists with ext .ts or .js')
throw new Error('TypeScript compilation failed. Please ensure handlers exists with ext .ts or .js')
})
}

Expand All @@ -88,7 +88,7 @@ export async function run(fileNames: string[], options: ts.CompilerOptions): Pro
})

if (emitResult.emitSkipped) {
throw new Error('Typescript compilation failed')
throw new Error('TypeScript compilation failed')
}

return emitResult.emittedFiles.filter(filename => filename.endsWith('.js'))
Expand All @@ -110,7 +110,7 @@ export function getSourceFiles(
return programmFiles
}

export function getTypescriptConfig(
export function getTypeScriptConfig(
cwd: string,
logger?: { log: (str: string) => void }
): ts.CompilerOptions {
Expand Down Expand Up @@ -142,5 +142,5 @@ export function getTypescriptConfig(
return configParseResult.options
}

return makeDefaultTypescriptConfig()
return makeDefaultTypeScriptConfig()
}
2 changes: 1 addition & 1 deletion src/watchFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as typescript from './typescript'
import { watchFile, unwatchFile, Stats} from 'fs'

export function watchFiles(rootFileNames: string[], originalServicePath: string, cb: () => void) {
const tsConfig = typescript.getTypescriptConfig(originalServicePath)
const tsConfig = typescript.getTypeScriptConfig(originalServicePath)
let watchedFiles = typescript.getSourceFiles(rootFileNames, tsConfig)

watchedFiles.forEach(fileName => {
Expand Down
8 changes: 4 additions & 4 deletions tests/typescript.getTypescriptConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {getTypescriptConfig, makeDefaultTypescriptConfig} from '../src/typescript'
import {getTypeScriptConfig, makeDefaultTypeScriptConfig} from '../src/typescript'

describe('getTypescriptConfig', () => {
describe('getTypeScriptConfig', () => {
it(`returns default typescript configuration if the one provided doesn't exist`, () => {
expect(
getTypescriptConfig('/ciaone/my-folder'),
getTypeScriptConfig('/ciaone/my-folder'),
).toEqual(
makeDefaultTypescriptConfig()
makeDefaultTypeScriptConfig()
)
})
})