# eq-gulp-utils **Repository Path**: hello-wltz/eq-gulp-utils ## Basic Information - **Project Name**: eq-gulp-utils - **Description**: gulp 幫助函數庫 拷貝文件 編譯ts 執行終端命令 - **Primary Language**: NodeJS - **License**: ISC - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2019-03-17 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # eq-gulp-utils #### 介绍 eq-gulp 幫助函數庫 拷貝文件 編譯ts 執行終端命令 asar打包 #### 软件架构 commonjs #### 安装教程 1. npm i -D eq-gulp-utils 2. const {compile_ts, copy_folder, run_cmd} = require('eq-gulp-utils'); #### 使用说明 1. 拷貝文件 ``` copy_folder( source: [string], dest: string, ) => NodeJS.WritableStream ``` 拷貝./public下所有文件 排除./public/less文件夾 ``` gulp.task('copy:public', () => { return copy_folder(['./public/**/*', '!./public/less'], './tmp/webserver/public'); }); ``` 2. 編譯ts ``` compile_ts( rootDir: string, dest: string, options = {}, tsconfig = "tsconfig.json" ) => NodeJS.WritableStream ``` ``` gulp.task('compile:ts:app', () => { return compile_ts('./src/app', './tmp/app'); }); ``` 3. 執行終端命令 ``` run_cmd( cmd: string, params: [string], done: (proc:ChildProcess, resolve, reject) => Promise<{}>, stdio = ['pipe', 'pipe', 'pipe'], options = {}) => Promise<{}> ``` 執行asar 命令 輸出導入進程的輸出 出錯時輸出錯誤碼 ``` run_cmd( 'asar', options ? ['p', options, dir, output] : ['p', dir, output], (proc, resolve, reject) => { proc.stdout.pipe(process.stdout, { end: false }); proc.on('close', (code) => { if (code != 0) { reject(new Error(`return code : ${code}`)); } resolve(); }).on('error', (err) => { reject(err); }); },) ``` 4. asar打包 ``` asar(dir: string, output: string, options: string) => Promise<{}> ``` ``` gulp.task('asar:app', (cb) => { asar('./tmp/resources/app', './tmp/resources/app.asar').then(() => { cb(); }, () => { console.log(err); cb(); }); }) ```