11import * as yaml from "js-yaml" ;
22import chalk from "chalk" ;
3- import path from "path" ;
43import * as fs from "fs-extra" ;
54import * as yargs from "yargs" ;
65import { Commander } from "./commander" ;
@@ -13,35 +12,24 @@ import {Utils} from "./utils";
1312import { Argv } from "./argv" ;
1413import assert from "assert" ;
1514
16- const generateGitIgnore = ( cwd : string , stateDir : string ) => {
17- const gitIgnoreFilePath = `${ cwd } /${ stateDir } /.gitignore` ;
18- const gitIgnoreContent = "*\n!.gitignore\n" ;
19- if ( ! fs . existsSync ( gitIgnoreFilePath ) ) {
20- fs . outputFileSync ( gitIgnoreFilePath , gitIgnoreContent ) ;
21- }
22- } ;
23-
2415export async function handler ( args : any , writeStreams : WriteStreams , jobs : Job [ ] = [ ] ) {
2516 const argv = await Argv . build ( args , writeStreams ) ;
2617 const cwd = argv . cwd ;
2718 const stateDir = argv . stateDir ;
28- const file = argv . file ;
2919 let parser : Parser | null = null ;
3020
3121 if ( argv . completion ) {
3222 yargs . showCompletionScript ( ) ;
3323 return [ ] ;
3424 }
3525
36- assert ( fs . existsSync ( `${ cwd } /${ file } ` ) , `${ path . resolve ( cwd ) } /${ file } could not be found` ) ;
37-
3826 if ( argv . fetchIncludes ) {
3927 await Parser . create ( argv , writeStreams , 0 , jobs ) ;
4028 return [ ] ;
4129 }
4230
4331 if ( argv . preview ) {
44- const pipelineIid = await state . getPipelineIid ( cwd , stateDir ) ;
32+ const pipelineIid = await state . getPipelineIid ( stateDir ) ;
4533 parser = await Parser . create ( argv , writeStreams , pipelineIid , jobs , false ) ;
4634 const gitlabData = parser . gitlabData ;
4735 for ( const jobName of Object . keys ( gitlabData ) ) {
@@ -55,46 +43,43 @@ export async function handler (args: any, writeStreams: WriteStreams, jobs: Job[
5543 }
5644 writeStreams . stdout ( `---\n${ yaml . dump ( gitlabData , { lineWidth : 160 } ) } ` ) ;
5745 } else if ( argv . list || argv . listAll ) {
58- const pipelineIid = await state . getPipelineIid ( cwd , stateDir ) ;
46+ const pipelineIid = await state . getPipelineIid ( stateDir ) ;
5947 parser = await Parser . create ( argv , writeStreams , pipelineIid , jobs ) ;
6048 Commander . runList ( parser , writeStreams , argv . listAll ) ;
6149 } else if ( argv . listJson ) {
62- const pipelineIid = await state . getPipelineIid ( cwd , stateDir ) ;
50+ const pipelineIid = await state . getPipelineIid ( stateDir ) ;
6351 parser = await Parser . create ( argv , writeStreams , pipelineIid , jobs ) ;
6452 Commander . runJson ( parser , writeStreams ) ;
6553 } else if ( argv . listCsv || argv . listCsvAll ) {
66- const pipelineIid = await state . getPipelineIid ( cwd , stateDir ) ;
54+ const pipelineIid = await state . getPipelineIid ( stateDir ) ;
6755 parser = await Parser . create ( argv , writeStreams , pipelineIid , jobs ) ;
6856 Commander . runCsv ( parser , writeStreams , argv . listCsvAll ) ;
6957 } else if ( argv . job . length > 0 ) {
7058 assert ( argv . stage === null , "You cannot use --stage when starting individual jobs" ) ;
71- generateGitIgnore ( cwd , stateDir ) ;
7259 const time = process . hrtime ( ) ;
7360 if ( argv . needs || argv . onlyNeeds ) {
74- await fs . remove ( `${ cwd } / ${ stateDir } /artifacts` ) ;
75- await state . incrementPipelineIid ( cwd , stateDir ) ;
61+ await fs . remove ( `${ stateDir } /artifacts` ) ;
62+ await state . incrementPipelineIid ( stateDir ) ;
7663 }
77- const pipelineIid = await state . getPipelineIid ( cwd , stateDir ) ;
64+ const pipelineIid = await state . getPipelineIid ( stateDir ) ;
7865 parser = await Parser . create ( argv , writeStreams , pipelineIid , jobs ) ;
7966 await Utils . rsyncTrackedFiles ( cwd , stateDir , ".docker" ) ;
8067 await Commander . runJobs ( argv , parser , writeStreams ) ;
8168 if ( argv . needs || argv . onlyNeeds ) {
8269 writeStreams . stderr ( chalk `{grey pipeline finished} in {grey ${ prettyHrtime ( process . hrtime ( time ) ) } }\n` ) ;
8370 }
8471 } else if ( argv . stage ) {
85- generateGitIgnore ( cwd , stateDir ) ;
8672 const time = process . hrtime ( ) ;
87- const pipelineIid = await state . getPipelineIid ( cwd , stateDir ) ;
73+ const pipelineIid = await state . getPipelineIid ( stateDir ) ;
8874 parser = await Parser . create ( argv , writeStreams , pipelineIid , jobs ) ;
8975 await Utils . rsyncTrackedFiles ( cwd , stateDir , ".docker" ) ;
9076 await Commander . runJobsInStage ( argv , parser , writeStreams ) ;
9177 writeStreams . stderr ( chalk `{grey pipeline finished} in {grey ${ prettyHrtime ( process . hrtime ( time ) ) } }\n` ) ;
9278 } else {
93- generateGitIgnore ( cwd , stateDir ) ;
9479 const time = process . hrtime ( ) ;
95- await fs . remove ( `${ cwd } / ${ stateDir } /artifacts` ) ;
96- await state . incrementPipelineIid ( cwd , stateDir ) ;
97- const pipelineIid = await state . getPipelineIid ( cwd , stateDir ) ;
80+ await fs . remove ( `${ stateDir } /artifacts` ) ;
81+ await state . incrementPipelineIid ( stateDir ) ;
82+ const pipelineIid = await state . getPipelineIid ( stateDir ) ;
9883 parser = await Parser . create ( argv , writeStreams , pipelineIid , jobs ) ;
9984 await Utils . rsyncTrackedFiles ( cwd , stateDir , ".docker" ) ;
10085 await Commander . runPipeline ( argv , parser , writeStreams ) ;
0 commit comments