import { Command , flags } from '@oclif/command' ; import { ArchTypes , PlatformTypes } from '@oclif/config' ; import * as qq from 'qqjs' ; import aws from '../../aws' ; import { log } from '../../log' ; import * as Tarballs from '../../tarballs' ; export default class Publish extends Command { static description = `publish an oclif CLI to S3

"aws-sdk" will need to be installed as a devDependency to publish.
` ; static flags = { root : flags . string ( { char : 'r' , description : 'path to oclif CLI root' , default : '.' , required : true } ) , targets : flags . string ( { char : 't' , description : 'comma-separated targets to pack (e.g.: linux-arm,win32-x64)' } ) , } ; buildConfig ! : Tarballs . IConfig ; async run ( ) { const { flags } = this . parse ( Publish ) ; if ( process . platform === 'win32' ) throw new Error ( 'publish does not function on windows' ) ; const targetOpts = flags . targets ? flags . targets . split ( ',' ) : undefined ; this . buildConfig = await Tarballs . buildConfig ( flags . root , { targets : targetOpts } ) ; const { s3Config , targets , dist , version , config } = this . buildConfig ; if ( ! await qq . exists ( dist ( config . s3Key ( 'versioned' , { ext : '.tar.gz' } ) ) ) ) this . error ( 'run "oclif-dev pack" before publishing' ) ; const S3Options = { Bucket : s3Config . bucket ! , ACL : s3Config . acl || 'public-read' , } ; const ManifestS3Options = { ... S3Options , CacheControl : 'max-age=86400' , ContentType : 'application/json' } ; const uploadTarball = async ( options ? ) => { const TarballS3Options = { ... S3Options , CacheControl : 'max-age=604800' } ; const releaseTarballs = async ( ext ) => { const versioned = config . s3Key ( 'versioned' , ext , options ) ; const unversioned = config . s3Key ( 'unversioned' , ext , options ) ; await aws . s3 . uploadFile ( dist ( versioned ) , { ... TarballS3Options , ContentType : 'application/gzip' , Key : versioned } ) ; await aws . s3 . uploadFile ( dist ( versioned ) , { ... TarballS3Options , ContentType : 'application/gzip' , Key : unversioned } ) ; } ; await releaseTarballs ( '.tar.gz' ) ; if ( this . buildConfig . xz ) await releaseTarballs ( '.tar.xz' ) ; const manifest = config . s3Key ( 'manifest' , options ) ; await aws . s3 . uploadFile ( dist ( manifest ) , { ... ManifestS3Options , Key : manifest } ) ; } ; if ( targets . length > 0 ) log ( 'uploading targets' ) ; for ( const target of targets ) await uploadTarball ( target ) ; log ( 'uploading vanilla' ) ; await uploadTarball ( ) ; log ( `published ${ version }` ) ; } }