@@ -132,6 +132,9 @@ export async function findProjectDir(
132132}
133133
134134const PERIODS = {
135+ year : 365 * 24 * 60 * 60 * 1000 ,
136+ month : 30 * 24 * 60 * 60 * 1000 ,
137+ week : 7 * 24 * 60 * 60 * 1000 ,
135138 day : 24 * 60 * 60 * 1000 ,
136139 hour : 60 * 60 * 1000 ,
137140 minute : 60 * 1000 ,
@@ -152,37 +155,66 @@ export function prettyTime(diff: number) {
152155 return diff + "ms" ;
153156}
154157
158+ export function timeAgo ( diff : number ) {
159+ if ( diff > PERIODS . year ) {
160+ const v = Math . floor ( diff / PERIODS . year ) ;
161+ return `${ v } year${ v > 1 ? "s" : "" } ago` ;
162+ } else if ( diff > PERIODS . month ) {
163+ const v = Math . floor ( diff / PERIODS . month ) ;
164+ return `${ v } month${ v > 1 ? "s" : "" } ago` ;
165+ } else if ( diff > PERIODS . week ) {
166+ const v = Math . floor ( diff / PERIODS . week ) ;
167+ return `${ v } week${ v > 1 ? "s" : "" } ago` ;
168+ } else if ( diff > PERIODS . day ) {
169+ const v = Math . floor ( diff / PERIODS . day ) ;
170+ return `${ v } day${ v > 1 ? "s" : "" } ago` ;
171+ } else if ( diff > PERIODS . hour ) {
172+ const v = Math . floor ( diff / PERIODS . hour ) ;
173+ return `${ v } hour${ v > 1 ? "s" : "" } ago` ;
174+ } else if ( diff > PERIODS . minute ) {
175+ const v = Math . floor ( diff / PERIODS . minute ) ;
176+ return `${ v } minute${ v > 1 ? "s" : "" } ago` ;
177+ } else if ( diff > PERIODS . seconds ) {
178+ const v = Math . floor ( diff / PERIODS . seconds ) ;
179+ return `${ v } second${ v > 1 ? "s" : "" } ago` ;
180+ }
181+
182+ return "just now" ;
183+ }
184+
155185export async function exec (
156186 cmd : string ,
157187 args : string [ ] ,
158188 cwd : string ,
159189 env ?: Record < string , string | undefined > ,
160- captureStdout ?: boolean ,
190+ captureOutput ?: boolean ,
161191) {
162192 const cp = spawn (
163193 cmd ,
164194 args . map ( ( arg ) => process . platform === "win32" ? `"${ arg } "` : `'${ arg } '` ) ,
165195 {
166- stdio : captureStdout ? "pipe" : "inherit" ,
196+ stdio : captureOutput ? "pipe" : "inherit" ,
167197 cwd,
168198 shell : true ,
169199 env,
170200 } ,
171201 ) ;
172202
173- return new Promise < string | undefined > ( ( resolve ) => {
174- let stdoutChunks : string [ ] | undefined ;
203+ let output = "" ;
175204
176- if ( captureStdout ) {
177- stdoutChunks = [ ] ;
178- cp . stdout ?. on ( "data" , ( data ) => {
179- stdoutChunks ! . push ( data ) ;
180- } ) ;
181- }
205+ if ( captureOutput ) {
206+ cp . stdout ?. on ( "data" , ( data ) => {
207+ output += data ;
208+ } ) ;
209+ cp . stderr ?. on ( "data" , ( data ) => {
210+ output += data ;
211+ } ) ;
212+ }
182213
214+ return new Promise < string > ( ( resolve ) => {
183215 cp . on ( "exit" , ( code ) => {
184- const stdout = stdoutChunks ?. join ( "" ) ;
185- if ( code === 0 ) resolve ( stdout ) ;
216+ console . log ( output ) ;
217+ if ( code === 0 ) resolve ( output ) ;
186218 else process . exit ( code ?? 1 ) ;
187219 } ) ;
188220 } ) ;
0 commit comments