import * as path from "path" ; import * as fsx from "fs-extra" ; import * as yargs from "yargs" ; const BOOTSTRAP_ROOT = path . resolve ( __dirname , ".." , "bootstrap" ) ; yargs . help ( ) . strict ( ) . demandCommand ( ) . showHelpOnFail ( true ) . command ( "init" , "Create a new userscript" , { } , init ) . argv ; function init ( _ ) { const rootDir = process . cwd ( ) ; fsx . readdir ( rootDir , async ( err , files ) => { if ( err !== null ) { throw err ; } if ( relevant ( files ) . length > 0 ) { console . error ( "Directory not empty. Stopping." ) ; process . exit ( 1 ) ; } await fsx . copy ( BOOTSTRAP_ROOT , rootDir ) ; await fsx . rename ( path . resolve ( rootDir , "gitignore" ) , path . resolve ( rootDir , ".gitignore" ) ) ; } ) ; } function relevant ( files ) { return files . filter ( f => ! f . startsWith ( "." ) ) ; }