UNPKG

mili

Version:

Scaffolding with continuous control over the development of the project.

43 lines (42 loc) 1.9 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import * as fs from 'fs-extra'; import simpleGit from 'simple-git'; import * as ora from 'ora'; import * as path from 'path'; import { exec } from './exec'; export function copy(src, dist, showProgress = false) { return __awaiter(this, void 0, void 0, function* () { const git = simpleGit(src); const spinner = ora({ text: 'Load Files', discardStdin: true, }); if (showProgress) spinner.start(); const files = yield fs.readdir(src); const filepaths = []; for (const filepath of files) { const srcfilepath = path.join(src, filepath); const result = yield git.checkIgnore(srcfilepath); if (result.length) continue; const stat = yield fs.lstat(srcfilepath); if (stat.isDirectory()) filepaths.push(`${filepath}/.`); else filepaths.push(filepath); } const tarOutput = path.relative(src, dist); yield exec(`tar -cf ${tarOutput}.tar ${filepaths.join(' ')} && tar -xf ${dist}.tar -C ${dist}`, { cwd: src }); if (showProgress) spinner.succeed('Load All Files'); }); }