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
6 changes: 4 additions & 2 deletions src/Chest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as chaiAsPromised from 'chai-as-promised'
import { Chest } from './Chest'
import { Files, Project, Registry } from './Core'

const TIMEOUT = 5000

const expect = chai.expect

describe('when loading projects', () => {
Expand All @@ -19,12 +21,12 @@ describe('when loading projects', () => {
const directory = Files.join(process.cwd(), 'testables', 'single')
const args = Object.keys(Registry.all())
return Chest.run(directory, ...args)
})
}).timeout(TIMEOUT)

it('should run scripts for workspace project', () => {
const directory = Files.join(process.cwd(), 'testables', 'workspaces')
const args = Object.keys(Registry.all())
return Chest.run(directory, ...args)
})
}).timeout(TIMEOUT)

})
10 changes: 5 additions & 5 deletions 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, Project, Registry, TypeScriptOptions } from '../index'
import { Files, Project, Registry, TypeScriptConfig } from '../index'

const TIMEOUT = 5000

Expand All @@ -15,17 +15,17 @@ describe('when collecting type declarations', () => {
const script = Registry.get('typings')
return Project.load(single).then(project =>
script.exec(project)
.then(project => project.json<TypeScriptOptions>('tsconfig.json'))
.then(json => expect(json.compilerOptions.types).to.contain('chalk'))
.then(project => project.json<TypeScriptConfig>('tsconfig.json'))
.then(tsconfig => expect(tsconfig.compilerOptions.types).to.have.lengthOf(2))
)
}).timeout(TIMEOUT)

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

Expand Down
28 changes: 18 additions & 10 deletions src/Core/Actions/Typings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Files, NPM, Project, Registry, TypeScriptOptions, UpdateScript } from '../index'
import { Files, NPM, Project, Registry, TypeScriptConfig, UpdateScript } from '../index'

/*
* Updates the "types" property of "tsconfig.json" files by
Expand All @@ -13,31 +13,39 @@ class Script extends UpdateScript {

public exec(project: Project): Promise<Project> {
return super.exec(project).then(project =>
this.declarations([project, ...project.children])
this.dependencies([project, ...project.children])
.then(typings => this.typings(project, typings))
.then(() => project)
)
}

private declarations(projects: Project[]): Promise<string[]> {
private dependencies(projects: Project[]): Promise<string[]> {
return Promise.all(projects.map(project => project.npm))
.then(npms => npms.map(npm => this.dependencies(npm)))
.then(npms => npms.map(npm => this.mergedeps(npm)))
.then(deps => deps.reduce((previous, current) => previous.concat(current), []))
.then(deps => Array.from(new Set(deps)))
.then(deps => Array.from(new Set(deps)).sort())
}

private dependencies(npm: NPM): string[] {
private mergedeps(npm: NPM): string[] {
const deps = Object.keys(npm.dependencies || {})
const devs = Object.keys(npm.devDependencies || {})
return Array.from(new Set([...deps, ...devs]))
return Array.from(new Set([...deps, ...devs])).sort()
}

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 || npm.typeScriptVersion).map(npm => npm.name))
.then(typings => project.json<TypeScriptOptions>('tsconfig.json').then(tsconfig => {
tsconfig.compilerOptions.types = typings.sort()
.then(npms => {
npms.forEach(npm => this.log.info('dependency', npm.name))
return npms
})
.then(npms => npms.filter(npm => npm.types || npm.typings || npm.typeScriptVersion))
.then(npms => {
npms.forEach(npm => this.log.task(`${npm.name} ->`, npm.types || npm.typings || npm.name))
return npms
})
.then(npms => project.json<TypeScriptConfig>('tsconfig.json').then(tsconfig => {
tsconfig.compilerOptions.types = npms.map(npm => npm.name).sort()
return tsconfig
}))
.then(tsconfig => project.save('tsconfig.json', tsconfig))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CompilerOptions } from 'typescript'

export interface TypeScriptOptions {
export interface TypeScriptConfig {
compilerOptions: CompilerOptions
}
2 changes: 1 addition & 1 deletion src/Core/Interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './Dictionary'
export * from './NPM'
export * from './TypeScriptOptions'
export * from './TypeScriptConfig'
export * from './Updater'
2 changes: 1 addition & 1 deletion src/Core/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Project {
this._owner = owner
this._path = path

this.log = Logger(`project:${this.name}`)
this.log = Logger(`chest:project:${this.name}`)
}

public get children(): Project[] {
Expand Down
14 changes: 2 additions & 12 deletions src/Core/Registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,9 @@ class DoesNothingGoesNowhereRoot extends UpdateScript {
}
}

class DoesNothingGoesNowhereProjects extends UpdateScript {
constructor() {
super(ProjectsScriptName)
}
}

describe('when using the script registry', () => {

it('should return registered script names', () => {
expect(Registry.names().length).to.be.gt(0)
})
it('should return registered script names', () => expect(Registry.names().length).to.be.gt(0))

it('should register new script object', () => {
expect(Registry.contains(RootScriptName)).to.equal(false)
Expand All @@ -35,8 +27,6 @@ describe('when using the script registry', () => {
expect(Registry.get(RootScriptName).name).to.equal(RootScriptName)
})

it('should throw error when calling "get" and script does not exist', () => {
expect(() => Registry.get('invalid')).to.throw()
})
it('should throw error when calling passing invalid to "get"', () => expect(() => Registry.get('invalid')).to.throw())

})
3 changes: 2 additions & 1 deletion testables/workspaces-invalid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
},
"description": "invalid workspace project",
"devDependencies": {
"@types/chalk": "*"
"@types/chalk": "*",
"@types/node": "^8.0.52"
},
"name": "project-single",
"private": true,
Expand Down
3 changes: 0 additions & 3 deletions testables/workspaces-invalid/tsconfig.json

This file was deleted.

3 changes: 2 additions & 1 deletion testables/workspaces/packages/simple-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
},
"description": "project with workspaces",
"devDependencies": {
"@types/chalk": "^2.2.0"
"@types/chalk": "^2.2.0",
"@types/node": "^8.0.52"
},
"name": "simple-package",
"version": "1.0.0"
Expand Down
3 changes: 0 additions & 3 deletions testables/workspaces/packages/simple-package/tsconfig.json

This file was deleted.

3 changes: 2 additions & 1 deletion testables/workspaces/projects/simple-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
},
"description": "project with workspaces",
"devDependencies": {
"@types/chalk": "^2.2.0"
"@types/chalk": "^2.2.0",
"@types/node": "^8.0.52"
},
"name": "simple-project",
"version": "1.0.0"
Expand Down
3 changes: 0 additions & 3 deletions testables/workspaces/projects/simple-project/tsconfig.json

This file was deleted.

1 change: 1 addition & 0 deletions testables/workspaces/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"types": [
"@types/node",
"chalk"
]
}
Expand Down
4 changes: 4 additions & 0 deletions testables/workspaces/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