import Minipass from 'minipass' ; import * as path from 'path' ; import { ReadEntry } from 'tar' ; export function sanitizedName ( name ) { return name . replace ( /[\W_]+/g , '' ) . normalize ( 'NFD' ) . replace ( /[\u0300-\u036f]/g , '' ) ; } class Transformer extends Minipass { data : string ; constructor ( private name ) { super ( ) ; this . data = '' ; } write ( data ) { this . data += data ; return true ; } end ( ) { let replaced = this . data . replace ( /Hello App Display Name/g , this . name ) . replace ( /HelloWorld/g , sanitizedName ( this . name ) ) . replace ( /helloworld/g , sanitizedName ( this . name . toLowerCase ( ) ) ) ; super . write ( replaced ) ; return super . end ( ) ; } } export function createEntryResolver ( name ) { return ( entry ) => { if ( name ) { entry . path = entry . path . replace ( /HelloWorld/g , entry . path . includes ( 'android' ) ? sanitizedName ( name . toLowerCase ( ) ) : sanitizedName ( name ) ) . replace ( /helloworld/g , sanitizedName ( name ) . toLowerCase ( ) ) ; } if ( entry . type && /^file$/i . test ( entry . type ) && path . basename ( entry . path ) === 'gitignore' ) { entry . path = entry . path . replace ( /gitignore$/ , '.gitignore' ) ; } } ; } export function createFileTransform ( name ) { return ( entry ) => { if ( ! [ '.png' , '.jpg' , '.jpeg' , '.gif' , '.webp' , '.psd' , '.tiff' , '.svg' , '.jar' , '.keystore' , ] . includes ( path . extname ( entry . path ) ) && name ) { return new Transformer ( name ) ; } return undefined ; } ; }