Skip to content
Merged
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
4 changes: 3 additions & 1 deletion src/Core/Actions/Packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Script extends UpdateScript {
super(Script.Name, UpdaterType.Projects)
}

public async workspace(project: Project): Promise<void> {
public async workspace(project: Project): Promise<Project> {
if (project.owner) {
const source = await project.owner.npm
const target = await project.npm
Expand All @@ -35,6 +35,8 @@ class Script extends UpdateScript {
this.log.task('workspace', filename)
}
}

return project
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/Core/Actions/Typings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'mocha'

import { expect } from 'chai'
import { Files, Registry } from '../index'
import { Files, Registry, TypeScriptOptions } from '../index'

const testables = Files.join(process.cwd(), 'testables')
const single = Files.join(testables, 'single')
Expand All @@ -12,11 +12,15 @@ describe('when collecting type declarations', () => {
it('should execute single', () => {
const script = Registry.get('typings')
return script.exec(single)
.then(project => project.json<TypeScriptOptions>('tsconfig.json'))
.then(json => expect(json.compilerOptions.types).to.contain('chalk'))
})

it('should execute workspaces', () => {
const script = Registry.get('typings')
return script.exec(workspaces)
.then(project => project.json<TypeScriptOptions>('tsconfig.json'))
.then(json => expect(json.compilerOptions.types).to.contain('chalk'))
})

})
19 changes: 7 additions & 12 deletions src/Core/Actions/Typings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { CompilerOptions } from 'typescript'
import { Files, NPM, Project, Registry, UpdateScript, UpdaterType } from '../index'

interface TsConfig {
compilerOptions: CompilerOptions
}
import { Files, NPM, Project, Registry, TypeScriptOptions, UpdateScript, UpdaterType } from '../index'

/*
* Updates the "types" property of "tsconfig.json" files by
Expand All @@ -16,13 +11,13 @@ class Script extends UpdateScript {
super(Script.Name, UpdaterType.Root)
}

public exec(rootpath: string): Promise<void> {
public exec(rootpath: string): Promise<Project> {
return Project.load(rootpath)
.then(project =>
this.declarations([project, ...project.children])
.then(typings => this.typings(project, typings))
.then(() => project)
)
.then(() => void (0))
}

private declarations(projects: Project[]): Promise<string[]> {
Expand All @@ -41,12 +36,12 @@ class Script extends UpdateScript {
private typings(project: Project, typings: string[]): Promise<void> {
return Promise.all(typings.map(typing => Files.join(project.path, 'node_modules', typing, 'package.json')))
.then(typings => Promise.all(typings.map(typing => Files.json<NPM>(typing))))
.then(npms => npms.filter(npm => npm.types || npm.typings).map(npm => npm.name))
.then(typings => project.json<TsConfig>('tsconfig.json').then(tsconfig => {
tsconfig.compilerOptions.types = typings
.then(npms => npms.filter(npm => npm.types || npm.typings || npm.typeScriptVersion).map(npm => npm.name))
.then(typings => project.json<TypeScriptOptions>('tsconfig.json').then(tsconfig => {
tsconfig.compilerOptions.types = typings.sort()
return tsconfig
}))
.then(tsconfig => this.testing ? Promise.resolve() : Files.save('tsconfig.json', tsconfig))
.then(tsconfig => project.save('tsconfig.json', tsconfig))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Actions/Yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class Yarn extends UpdateScript {
super(Yarn.Name, UpdaterType.Root)
}

public exec(rootpath: string): Promise<void> {
return Project.load(rootpath).then(project => this.run(project, 'yarn'))
public exec(rootpath: string): Promise<Project> {
return Project.load(rootpath).then(project => this.run(project, 'yarn').then(() => project))
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Core/Interfaces/TypeScriptOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CompilerOptions } from 'typescript'

export interface TypeScriptOptions {
compilerOptions: CompilerOptions
}
4 changes: 2 additions & 2 deletions src/Core/Interfaces/Updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Project } from '../Project'
export interface Updater {
name: string
type: UpdaterType
exec(rootpath: string): Promise<void>
workspace(project: Project): Promise<void>
exec(rootpath: string): Promise<Project>
workspace(project: Project): Promise<Project>
}

export type Updaters = {
Expand Down
1 change: 1 addition & 0 deletions src/Core/Interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './Dictionary'
export * from './NPM'
export * from './TypeScriptOptions'
export * from './Updater'
export * from './UpdaterType'
3 changes: 2 additions & 1 deletion src/Core/Registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Dictionary, Updater, Updaters } from './Interfaces'
import { Project } from './Project'

export class Registry {
private static readonly registrations: Updaters = {}
Expand All @@ -15,7 +16,7 @@ export class Registry {
return !!this.registrations[name.toLowerCase()]
}

public static execute(root: string, ...args: string[]): Promise<void[]> {
public static execute(root: string, ...args: string[]): Promise<Project[]> {
return Promise.all(args.map(arg => arg.toLowerCase()).map(name => this.registrations[name].exec(root)))
}

Expand Down
8 changes: 4 additions & 4 deletions src/Core/UpdateScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export abstract class UpdateScript implements Updater {
return this._type
}

public exec(rootpath: string): Promise<void> {
return Promise.resolve()
public exec(rootpath: string): Promise<Project> {
return Promise.resolve(Project.InvalidProject)
}

public workspace(project: Project): Promise<void> {
return Promise.resolve()
public workspace(project: Project): Promise<Project> {
return Promise.resolve(Project.InvalidProject)
}

protected npm<NPM>(basepath: string): Promise<NPM> {
Expand Down
3 changes: 2 additions & 1 deletion testables/single/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
},
"description": "single project",
"devDependencies": {
"@types/chalk": "^2.2.0"
"@types/chalk": "^2.2.0",
"@types/node": "^8.0.52"
},
"name": "project-single",
"version": "1.0.0"
Expand Down
5 changes: 4 additions & 1 deletion testables/single/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"compilerOptions": {
"types": []
"types": [
"@types/node",
"chalk"
]
}
}
4 changes: 4 additions & 0 deletions testables/single/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
dependencies:
chalk "*"

"@types/node@^8.0.52":
version "8.0.53"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.53.tgz#396b35af826fa66aad472c8cb7b8d5e277f4e6d8"

ansi-styles@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88"
Expand Down