Skip to content

Commit 84ed5b0

Browse files
author
Mike Pham
committed
feat: renaming some minor interfaces
1 parent c0e72d1 commit 84ed5b0

7 files changed

Lines changed: 44 additions & 43 deletions

File tree

‎src/Core/Actions/Packages.ts‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,25 @@ class Script extends UpdateScript {
1616
protected workspace(project: Project): Promise<Project> {
1717
return super.workspace(project)
1818
.then(async () => {
19-
if (project.owner) {
20-
const source = await project.owner.npm
21-
const target = await project.npm
22-
23-
target.author = source.author
24-
target.bugs = source.bugs
25-
target.description = source.description
26-
target.homepage = source.homepage
27-
target.license = source.license
28-
target.repository = source.repository
29-
30-
const filename = path.join(project.path, 'package.json')
31-
await Files.save(filename, target)
32-
this.log.task('workspace', filename)
19+
/* istanbul ignore next */
20+
if (!project.owner) {
21+
throw new Error(`${project.name} is a root project`)
3322
}
3423

24+
const source = await project.owner.npm
25+
const target = await project.npm
26+
27+
target.author = source.author
28+
target.bugs = source.bugs
29+
target.description = source.description
30+
target.homepage = source.homepage
31+
target.license = source.license
32+
target.repository = source.repository
33+
34+
const filename = path.join(project.path, 'package.json')
35+
await Files.save(filename, target)
36+
this.log.task('workspace', filename)
37+
3538
return project
3639
})
3740
}

‎src/Core/Files.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as fs from 'fs'
22
import * as path from 'path'
33

4-
import { IFiles, Stat } from './Interfaces'
4+
import { FileSystem, Stat } from './Interfaces'
55
import { Log, Logger } from './Logger'
66

7-
class InternalFiles {
7+
class InternalFileSystem implements FileSystem {
88
private readonly log: Log = Logger('chest:files')
99

1010
public basename(filepath: string): string {
@@ -140,4 +140,5 @@ class InternalFiles {
140140
}
141141
}
142142

143-
export const Files: IFiles = new InternalFiles()
143+
const files: FileSystem = new InternalFileSystem()
144+
export const Files: FileSystem = files
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs'
22

33
import { Stat } from './Stat'
44

5-
export interface IFiles {
5+
export interface FileSystem {
66
basename(filepath: string): string
77
deepdirs(rootpath: string): Promise<string[]>
88
deepfiles(rootpath: string): Promise<string[]>

‎src/Core/Interfaces/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export * from './Dictionary'
2-
export * from './IFiles'
2+
export * from './FileSystem'
33
export * from './LernaConfig'
44
export * from './NPM'
55
export * from './Stat'

‎src/Core/Logger.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ export interface Log {
1010
}
1111

1212
export function Logger(name: string, category?: string): Log {
13-
const cat = category ? `:${category}` : ''
13+
const cat = `:${category}`
1414
const bold = (name: string) => chalk.default.bold(`[${name}${cat}]`)
1515

1616
const log = (...args: any[]) => {
17+
/* istanbul ignore next */
1718
if (process.env.DEBUG && process.env.NODE_ENV === 'development') {
1819
console.log(...args)
1920
}

‎src/Core/UpdateScript.ts‎

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as cp from 'child_process'
2-
import * as path from 'path'
32

4-
import { Files, Log, Logger, Project, Updater } from './index'
3+
import { Log, Logger, Project, Updater } from './index'
54

65
export abstract class UpdateScript implements Updater {
76
protected readonly log: Log
@@ -16,17 +15,14 @@ export abstract class UpdateScript implements Updater {
1615
return this._name
1716
}
1817

19-
public get testing(): boolean {
20-
const env = (process.env.NODE_ENV || '').toLowerCase()
21-
return ['test', 'testing'].some(value => value === env)
22-
}
23-
2418
public exec(project: Project): Promise<Project> {
25-
return (
26-
project.children && project.children.length
27-
? Promise.all(project.children.map(child => this.workspace(child).then(proj => this.log.task(proj.name)))).then(() => project)
28-
: Promise.resolve(project)
29-
).then(() => this.log.task(this.name, project.name)).then(() => project)
19+
const rootProject = project.children && project.children.length
20+
? Promise.all(project.children.map(child => this.workspace(child).then(proj => this.log.task(proj.name)))).then(() => project)
21+
: Promise.resolve(project)
22+
23+
return rootProject
24+
.then(() => this.log.start(this.name, project.name))
25+
.then(() => project)
3026
}
3127

3228
protected workspace(project: Project): Promise<Project> {
@@ -35,32 +31,31 @@ export abstract class UpdateScript implements Updater {
3531
.then(() => project)
3632
}
3733

38-
protected npm<NPM>(basepath: string): Promise<NPM> {
39-
const filename = path.join(basepath, 'package.json')
40-
return Files.exists(filename).then(() => Files.json<NPM>(filename))
41-
}
42-
4334
protected run(project: Project, command: string, ...args: string[]): Promise<void> {
4435
return new Promise<void>((resolve, reject) => {
4536
this.log.debug('run', project.name, command, ...args)
4637

4738
const child = cp.exec(`${command} ${args.join(' ')}`, { cwd: project.path }, error => {
48-
if (error) this.log.error(error)
39+
/* istanbul ignore next */
40+
if (error) {
41+
this.log.error(error)
42+
}
4943
})
5044

5145
child.stderr.on('data', data =>
52-
this.args(project, process.stderr, data)
46+
this.stream(project, process.stderr, data)
5347
.map(lines => lines)
5448
.forEach(args => this.log.error(...args))
5549
)
5650

5751
child.stdout.on('data', data =>
58-
this.args(project, process.stdout, data)
52+
this.stream(project, process.stdout, data)
5953
.map(lines => lines)
6054
.forEach(args => this.log.task(...args))
6155
)
6256

6357
child.addListener('exit', (code: number, signal: string) => {
58+
/* istanbul ignore next */
6459
if (code === 0) {
6560
resolve()
6661
} else {
@@ -70,11 +65,12 @@ export abstract class UpdateScript implements Updater {
7065
})
7166
}
7267

73-
private args(project: Project, stream: NodeJS.WriteStream, data: string | Buffer): string[][] {
68+
private stream(project: Project, stream: NodeJS.WriteStream, data: string | Buffer): string[][] {
7469
const format = (lines: string[]): string[][] => {
7570
return lines.filter(line => line.trim()).map(line => [project.name, '>', line])
7671
}
7772

73+
/* istanbul ignore next */
7874
if (data instanceof Buffer) {
7975
return format(data.toString().replace('\r', '').split('\n'))
8076
}

‎tsconfig.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"noImplicitThis": true,
1919
"outDir": "lib",
2020
"pretty": true,
21-
"removeComments": true,
21+
"removeComments": false,
2222
"sourceMap": true,
2323
"strict": true,
2424
"strictNullChecks": true,
@@ -40,4 +40,4 @@
4040
"include": [
4141
"src/**/*.ts"
4242
]
43-
}
43+
}

0 commit comments

Comments
 (0)