30 lines
877 B
TypeScript
30 lines
877 B
TypeScript
import { Publisher, PublisherFactory } from '../publisher'
|
|
import { ResolveResult } from '../resolver'
|
|
import { PackageManager } from './npm-resolver'
|
|
import * as child_process from 'child_process'
|
|
|
|
export interface NpmPublisherOptions {
|
|
package_manager?: PackageManager
|
|
}
|
|
|
|
export class NpmPublisher implements Publisher<NpmPublisherOptions> {
|
|
|
|
readonly options: NpmPublisherOptions
|
|
|
|
constructor(options?: NpmPublisherOptions) {
|
|
this.options = {
|
|
package_manager: 'yarn',
|
|
...options,
|
|
}
|
|
}
|
|
|
|
publish(results: ResolveResult[]): void {
|
|
const cmd = `yarn upgrade ${results.map((r) => `${r.current.name}@${r.recommended.version.version}`).join(' ')}`
|
|
child_process.execSync(cmd, { stdio: 'inherit' })
|
|
}
|
|
}
|
|
|
|
const factory: PublisherFactory<NpmPublisherOptions> = (options: NpmPublisherOptions) => new NpmPublisher(options)
|
|
export default factory
|
|
|