1- import * as fs from 'fs ' ;
1+ import * as path from 'node:path ' ;
22import * as cp from 'child_process' ;
3- import * as glob from 'glob' ;
4- import * as fsExtra from 'fs-extra' ;
5- import * as path from 'path' ;
6- import * as rimraf from 'rimraf' ;
3+ import ora from 'ora' ;
74import { Config } from './config' ;
85
96export type RunnerFn = ( config : Config ) => Promise < any > ;
107export type TaskDef = [ string , RunnerFn ] ;
118export type BaseFn = ( command : string ) => string ;
129
13- export function copy ( target : string , destination : string ) : Promise < void > {
14- return new Promise ( ( resolve , reject ) => {
15- fsExtra . copy ( target , path . resolve ( destination ) , ( err ) => {
16- if ( err ) return reject ( err ) ;
17- resolve ( ) ;
18- } ) ;
19- } ) ;
20- }
21-
22- export function remove ( target : string ) : Promise < void > {
23- return new Promise ( ( resolve , reject ) => {
24- fsExtra . remove ( target , ( err ) => {
25- if ( err ) return reject ( err ) ;
26- resolve ( ) ;
27- } ) ;
28- } ) ;
29- }
30-
31- export function writeFile ( target : string , contents : string ) : Promise < void > {
32- return new Promise ( ( resolve , reject ) => {
33- fs . writeFile ( target , contents , ( err ) => {
34- if ( err ) return reject ( err ) ;
35- resolve ( ) ;
36- } ) ;
37- } ) ;
38- }
39-
40- export function getListOfFiles (
41- globPath : string ,
42- exclude ?: string | string [ ]
43- ) : Promise < string [ ] > {
44- return new Promise ( ( resolve , reject ) => {
45- const options = exclude ? { ignore : exclude } : { } ;
46-
47- glob ( globPath , options , ( error , matches ) => {
48- if ( error ) {
49- return reject ( error ) ;
50- }
51-
52- resolve ( matches ) ;
53- } ) ;
54- } ) ;
55- }
56-
57- export function removeRecursively ( glob : string ) : Promise < void > {
58- return new Promise ( ( resolve , reject ) => {
59- rimraf ( glob , ( err ) => {
60- if ( err ) {
61- reject ( err ) ;
62- } else {
63- resolve ( ) ;
64- }
65- } ) ;
66- } ) ;
10+ export function createBuilder ( tasks : TaskDef [ ] ) {
11+ return async function ( config : Config ) {
12+ for ( const [ name , runner ] of tasks ) {
13+ await runTask ( name , ( ) => runner ( config ) ) ;
14+ }
15+ } ;
6716}
6817
6918export function exec (
@@ -82,6 +31,10 @@ export function exec(
8231 } ) ;
8332}
8433
34+ export function getTopLevelPackages ( config : Config ) {
35+ return config . packages . map ( ( packageDescription ) => packageDescription . name ) ;
36+ }
37+
8538export function cmd ( command : string , args : string [ ] ) : Promise < string > {
8639 return exec ( command , args , ( command : string ) => command ) ;
8740}
@@ -90,19 +43,6 @@ export function git(args: string[]): Promise<string> {
9043 return cmd ( 'git' , args ) ;
9144}
9245
93- export function ignoreErrors < T > ( promise : Promise < T > ) : Promise < T | null > {
94- return promise . catch ( ( ) => null ) ;
95- }
96-
97- export function fromNpm ( command : string ) {
98- return baseDir ( `./node_modules/.bin/${ command } ` ) ;
99- }
100-
101- export function getPackageFilePath ( pkg : string , filename : string ) {
102- return baseDir ( `./modules/${ pkg } /${ filename } ` ) ;
103- }
104-
105- const ora = require ( 'ora' ) ;
10646async function runTask ( name : string , taskFn : ( ) => Promise < any > ) {
10747 const spinner = ora ( name ) ;
10848
@@ -119,40 +59,10 @@ async function runTask(name: string, taskFn: () => Promise<any>) {
11959 }
12060}
12161
122- export function createBuilder ( tasks : TaskDef [ ] ) {
123- return async function ( config : Config ) {
124- for ( let [ name , runner ] of tasks ) {
125- await runTask ( name , ( ) => runner ( config ) ) ;
126- }
127- } ;
128- }
129-
130- export function flatMap < K , J > ( list : K [ ] , mapFn : ( item : K ) => J [ ] ) : J [ ] {
131- return list . reduce ( function ( newList , nextItem ) {
132- return [ ...newList , ...mapFn ( nextItem ) ] ;
133- } , [ ] as J [ ] ) ;
134- }
135-
136- export function getTopLevelPackages ( config : Config ) {
137- return config . packages . map ( ( packageDescription ) => packageDescription . name ) ;
138- }
139-
140- export function baseDir ( ...dirs : string [ ] ) : string {
62+ function baseDir ( ...dirs : string [ ] ) : string {
14163 return `"${ path . resolve ( __dirname , '../' , ...dirs ) } "` ;
14264}
14365
144- export async function sleep ( ms : number ) {
145- return new Promise ( ( resolve ) => {
146- setTimeout ( resolve , ms ) ;
147- } ) ;
148- }
149-
150- export function getPrNumber ( prNumber : string , circlePR : string ) : string {
151- const PR_NUMBER = prNumber ;
152-
153- if ( ! PR_NUMBER && circlePR ) {
154- return circlePR ;
155- }
156-
157- return PR_NUMBER ;
66+ function fromNpm ( command : string ) {
67+ return baseDir ( `./node_modules/.bin/${ command } ` ) ;
15868}
0 commit comments