зеркало из https://github.com/microsoft/just.git
Added a tar task (#348)
* adding a tartask * update tar version * Change files
This commit is contained in:
Родитель
b371807229
Коммит
75b14a7d48
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"type": "minor",
|
||||
"comment": "Adds a new set of tar create and extract tasks",
|
||||
"packageName": "just-scripts",
|
||||
"email": "kchau@microsoft.com",
|
||||
"commit": "d8c91d78ed4337dbb8a592f388e382a8dd3628a2",
|
||||
"date": "2020-04-06T21:36:07.923Z"
|
||||
}
|
|
@ -2,17 +2,23 @@
|
|||
"name": "just-scripts",
|
||||
"version": "0.36.1",
|
||||
"description": "Just Stack Scripts",
|
||||
"keywords": [],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/microsoft/just"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "",
|
||||
"main": "./lib/index.js",
|
||||
"bin": {
|
||||
"just-scripts": "bin/just-scripts.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"main": "./lib/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start": "tsc -w --preserveWatchOutput",
|
||||
"test": "jest",
|
||||
"test:update": "jest --updateSnapshot"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "^10.12.18",
|
||||
"chalk": "^2.4.1",
|
||||
|
@ -28,24 +34,19 @@
|
|||
"webpack-merge": "^4.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/supports-color": "5.3.0",
|
||||
"@types/diff-match-patch": "1.0.32",
|
||||
"@types/fs-extra": "^5.0.4",
|
||||
"@types/glob": "^7.1.1",
|
||||
"@types/jest": "^24.0.13",
|
||||
"@types/prompts": "^1.2.0",
|
||||
"@types/run-parallel-limit": "^1.0.0",
|
||||
"@types/supports-color": "5.3.0",
|
||||
"@types/tar": "^4.0.3",
|
||||
"@types/webpack-merge": "^4.1.3",
|
||||
"async-done": "^1.3.2",
|
||||
"jest": "^24.0.0",
|
||||
"jest-cli": "^24.8.0",
|
||||
"mock-fs": "^4.8.0",
|
||||
"typescript": "~3.4.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start": "tsc -w --preserveWatchOutput",
|
||||
"test": "jest",
|
||||
"test:update": "jest --updateSnapshot"
|
||||
"typescript": "~3.8.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,3 +14,4 @@ export * from './prettierTask';
|
|||
export * from './eslintTask';
|
||||
export * from './webpackCliInitTask';
|
||||
export * from './webpackCliTask';
|
||||
export * from './tarTask';
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
import { resolve, logger, TaskFunction } from 'just-task';
|
||||
import { Stats } from 'fs';
|
||||
|
||||
type ArchiveErrorCode =
|
||||
| 'TAR_ENTRY_INFO'
|
||||
| 'TAR_ENTRY_INVALID'
|
||||
| 'TAR_ENTRY_ERROR'
|
||||
| 'TAR_ENTRY_UNSUPPORTED'
|
||||
| 'TAR_ABORT'
|
||||
| 'TAR_BAD_ARCHIVE';
|
||||
|
||||
export { ArchiveErrorCode };
|
||||
|
||||
export interface CreateOptions {
|
||||
file: string;
|
||||
gzip?:
|
||||
| boolean
|
||||
| {
|
||||
level?: number;
|
||||
memLevel?: number;
|
||||
};
|
||||
cwd?: string;
|
||||
onwarn?: (code: ArchiveErrorCode, message: string, data: any) => void;
|
||||
prefix?: string;
|
||||
filter?: (path: string, stat: Stats) => boolean;
|
||||
preservePaths?: boolean;
|
||||
mode?: number;
|
||||
noDirRecurse?: boolean;
|
||||
follow?: boolean;
|
||||
noMtime?: boolean;
|
||||
mtime?: Date;
|
||||
}
|
||||
|
||||
export interface CreateArchiveTaskOptions extends CreateOptions {
|
||||
fileList?: string[];
|
||||
glob?: string[] | string;
|
||||
globOptions?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an tar (optionally gzipped) archive
|
||||
* @param options
|
||||
*/
|
||||
export function createTarTask(options: CreateArchiveTaskOptions = { file: 'archive.tar.gz' }): TaskFunction {
|
||||
const resolvedTar = resolve('tar');
|
||||
const resolvedGlob = resolve('glob');
|
||||
|
||||
if (!resolvedTar) {
|
||||
logger.error('Please make sure to have "tar" as a dependency in your package.json');
|
||||
throw new Error('Required dependency "tar" is not installed');
|
||||
}
|
||||
|
||||
const tar = require(resolvedTar);
|
||||
let { fileList = [], glob, globOptions = {}, ...restOptions } = options;
|
||||
|
||||
if (glob && resolvedGlob) {
|
||||
const globModule = require(resolvedGlob);
|
||||
glob = Array.isArray(glob) ? glob : [glob];
|
||||
|
||||
fileList = glob.reduce((collection, pattern) => {
|
||||
return collection.concat(globModule.sync(pattern, { ...(restOptions.cwd ? { cwd: restOptions.cwd } : undefined), ...globOptions }));
|
||||
}, []);
|
||||
}
|
||||
|
||||
return function archive() {
|
||||
return tar.create(restOptions, fileList);
|
||||
};
|
||||
}
|
||||
|
||||
export interface ExtractOptions {
|
||||
file: string;
|
||||
gzip?:
|
||||
| boolean
|
||||
| {
|
||||
level?: number;
|
||||
memLevel?: number;
|
||||
};
|
||||
cwd?: string;
|
||||
newer?: boolean;
|
||||
strip?: number;
|
||||
onwarn?: (code: ArchiveErrorCode, message: string, data: any) => void;
|
||||
preserveOwner?: boolean;
|
||||
filter?: (path: string, stat: Stats) => boolean;
|
||||
preservePaths?: boolean;
|
||||
unlink?: boolean;
|
||||
noMtime?: boolean;
|
||||
}
|
||||
|
||||
export interface ExtractArchiveTaskOptions extends ExtractOptions {
|
||||
fileList?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an tar (optionally gzipped) archive
|
||||
* @param options
|
||||
*/
|
||||
export function extractTarTask(options: ExtractArchiveTaskOptions = { file: 'archive.tar.gz' }): TaskFunction {
|
||||
const resolvedTar = resolve('tar');
|
||||
|
||||
if (!resolvedTar) {
|
||||
logger.error('Please make sure to have "tar" as a dependency in your package.json');
|
||||
throw new Error('Required dependency "tar" is not installed');
|
||||
}
|
||||
|
||||
const tar = require(resolvedTar);
|
||||
const { fileList, ...restOptions } = options;
|
||||
|
||||
return function archive() {
|
||||
return tar.extract(restOptions, fileList);
|
||||
};
|
||||
}
|
|
@ -2271,7 +2271,7 @@
|
|||
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370"
|
||||
integrity sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==
|
||||
|
||||
"@types/tar@^4.0.0":
|
||||
"@types/tar@^4.0.0", "@types/tar@^4.0.3":
|
||||
version "4.0.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/tar/-/tar-4.0.3.tgz#e2cce0b8ff4f285293243f5971bd7199176ac489"
|
||||
integrity sha512-Z7AVMMlkI8NTWF0qGhC4QIX0zkV/+y0J8x7b/RsHrN0310+YNjoJd8UrApCiGBCWtKjxS9QhNqLi2UJNToh5hA==
|
||||
|
@ -13310,6 +13310,11 @@ typescript@~3.4.4:
|
|||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99"
|
||||
integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==
|
||||
|
||||
typescript@~3.8.3:
|
||||
version "3.8.3"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
|
||||
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
|
||||
|
||||
uglify-js@3.4.x:
|
||||
version "3.4.10"
|
||||
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.10.tgz#9ad9563d8eb3acdfb8d38597d2af1d815f6a755f"
|
||||
|
|
Загрузка…
Ссылка в новой задаче