本文整理匯總了TypeScript中shelljs.set函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript set函數的具體用法?TypeScript set怎麽用?TypeScript set使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了set函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: require
const onSpecCompleted = (format: string) => {
if (preserveOutput) {
const {tmpdir} = require('os');
const {cp, mkdir, rm, set} = require('shelljs');
const tempRootDir = join(tmpdir(), 'ngcc-spec', format);
const outputDir = OUTPUT_PATH;
set('-e');
rm('-rf', tempRootDir);
mkdir('-p', tempRootDir);
cp('-R', join(support.basePath, outputDir), tempRootDir);
global.console.log(`Copied '${outputDir}' to '${tempRootDir}'.`);
}
};
示例2: main
function main(args: string[]): number {
// Exit immediately when encountering an error.
shx.set('-e');
// Keep track of whether an error has occured so that we can return an appropriate exit code.
let errorHasOccured = false;
// This utility expects all of its arguments to be specified in a params file generated by
// bazel (see https://docs.bazel.build/versions/master/skylark/lib/Args.html#use_param_file).
const paramFilePath = args[0];
// Bazel params may be surrounded with quotes
function unquoteParameter(s: string) { return s.replace(/^'(.*)'$/, '$1'); }
// Parameters are specified in the file one per line.
const params = fs.readFileSync(paramFilePath, 'utf-8').split('\n').map(unquoteParameter);
const [
// Output directory for the npm package.
out,
// The package segment of the ng_package rule's label (e.g. 'package/common').
srcDir,
// The bazel-bin dir joined with the srcDir (e.g. 'bazel-bin/package.common').
// This is the intended output location for package artifacts.
binDir,
// The bazel-genfiles dir joined with the srcDir (e.g. 'bazel-bin/package.common').
genfilesDir,
// JSON data mapping each entry point to the generated bundle index and
// flat module metadata, for example
// {"@angular/core": {
// "index": "bazel-bin/packages/core/core.js",
// "typing": "bazel-bin/packages/core/core.d.ts",
// "metadata": "bazel-bin/packages/core/core.metadata.json"
// },
// ...
// }
modulesManifestArg,
// Path to the package's README.md.
readmeMd,
// List of rolled-up flat ES2015 modules
fesm2015Arg,
// List of rolled-up flat ES5 modules
fesm5Arg,
// List of individual ES2015 modules
esm2015Arg,
// List of individual ES5 modules
esm5Arg,
// List of all UMD bundles generated by rollup.
bundlesArg,
// List of all files in the ng_package rule's srcs.
srcsArg,
// List of all files in the ng_package rule's data.
dataArg,
// Path to the package's LICENSE.
licenseFile,
] = params;
const fesm2015 = fesm2015Arg.split(',').filter(s => !!s);
const fesm5 = fesm5Arg.split(',').filter(s => !!s);
const esm2015 = esm2015Arg.split(',').filter(s => !!s);
const esm5 = esm5Arg.split(',').filter(s => !!s);
const bundles = bundlesArg.split(',').filter(s => !!s);
const srcs = srcsArg.split(',').filter(s => !!s);
const dataFiles: string[] = dataArg.split(',').filter(s => !!s);
const modulesManifest = JSON.parse(modulesManifestArg);
if (readmeMd) {
copyFile(readmeMd, out);
}
/**
* Writes a file into the package based on its input path, relativizing to the package path.
* @param inputPath Path to the file in the input tree.
* @param fileContent Content of the file.
*/
function writeFileFromInputPath(inputPath: string, fileContent: string) {
// We want the relative path from the given file to its ancestor "root" directory.
// This root depends on whether the file lives in the source tree (srcDir) as a basic file
// input to ng_package, the bin output tree (binDir) as the output of another rule, or
// the genfiles output tree (genfilesDir) as the output of a genrule.
let rootDir: string;
if (inputPath.includes(binDir)) {
rootDir = binDir;
} else if (inputPath.includes(genfilesDir)) {
rootDir = genfilesDir;
} else {
rootDir = srcDir;
//.........這裏部分代碼省略.........
示例3: main
function main(args: string[]): number {
shx.set('-e');
const
[out, srcDir, binDir, readmeMd, fesms2015Arg, fesms5Arg, bundlesArg, srcsArg, stampData,
licenseFile] = args;
const fesms2015 = fesms2015Arg.split(',').filter(s => !!s);
const fesms5 = fesms5Arg.split(',').filter(s => !!s);
const bundles = bundlesArg.split(',').filter(s => !!s);
const srcs = srcsArg.split(',').filter(s => !!s);
shx.mkdir('-p', out);
let primaryEntryPoint: string|null = null;
const secondaryEntryPoints = new Set<string>();
function replaceVersionPlaceholders(filePath: string) {
if (stampData) {
const version = shx.grep('BUILD_SCM_VERSION', stampData).split(' ')[1].trim();
return shx.sed(/0.0.0-PLACEHOLDER/, version, filePath);
}
return shx.cat(filePath);
}
function writeFesm(file: string, baseDir: string) {
const parts = path.basename(file).split('__');
const entryPointName = parts.join('/').replace(/\..*/, '');
if (primaryEntryPoint === null || primaryEntryPoint === entryPointName) {
primaryEntryPoint = entryPointName;
} else {
secondaryEntryPoints.add(entryPointName);
}
const filename = parts.splice(-1)[0];
const dir = path.join(baseDir, ...parts);
shx.mkdir('-p', dir);
shx.cp(file, dir);
shx.mv(path.join(dir, path.basename(file)), path.join(dir, filename));
}
function moveBundleIndex(f: string) {
let ext: string;
if (f.endsWith('.d.ts'))
ext = '.d.ts';
else if (f.endsWith('.metadata.json'))
ext = '.metadata.json';
else
throw new Error('Bundle index files should be .d.ts or .metadata.json');
const relative = path.relative(binDir, f);
let outputPath: string|undefined = undefined;
for (const secondary of secondaryEntryPoints.values()) {
if (relative.startsWith(secondary)) {
const filename = secondary.split('/').pop();
outputPath = path.join(out, secondary, filename + ext);
}
}
if (!outputPath) {
outputPath = path.join(out, primaryEntryPoint + ext);
}
return outputPath;
}
if (readmeMd) {
shx.cp(readmeMd, path.join(out, 'README.md'));
}
fesms2015.forEach(fesm2015 => writeFesm(fesm2015, path.join(out, 'esm2015')));
fesms5.forEach(fesm5 => writeFesm(fesm5, path.join(out, 'esm5')));
const bundlesDir = path.join(out, 'bundles');
shx.mkdir('-p', bundlesDir);
bundles.forEach(bundle => { shx.cp(bundle, bundlesDir); });
const allsrcs = shx.find('-R', binDir);
allsrcs.filter(filter('.d.ts')).forEach((f: string) => {
const content = fs.readFileSync(f, {encoding: 'utf-8'})
// Strip the named AMD module for compatibility with non-bazel users
.replace(/^\/\/\/ <amd-module name=.*\/>\n/, '');
let outputPath: string;
if (f.endsWith('.bundle_index.d.ts')) {
outputPath = moveBundleIndex(f);
} else {
outputPath = path.join(out, path.relative(binDir, f));
}
shx.mkdir('-p', path.dirname(outputPath));
fs.writeFileSync(outputPath, content);
});
for (const src of srcs) {
replaceVersionPlaceholders(src).to(path.join(out, path.relative(srcDir, src)));
}
allsrcs.filter(filter('.bundle_index.metadata.json')).forEach((f: string) => {
replaceVersionPlaceholders(f).to(moveBundleIndex(f));
});
const licenseBanner = licenseFile ? fs.readFileSync(licenseFile, {encoding: 'utf-8'}) : '';
for (const secondaryEntryPoint of secondaryEntryPoints.values()) {
const baseName = secondaryEntryPoint.split('/').pop();
//.........這裏部分代碼省略.........
示例4: main
function main(args: string[]): number {
shx.set('-e');
args = fs.readFileSync(args[0], {encoding: 'utf-8'}).split('\n').map(s => s === '\'\'' ? '' : s);
const
[out, srcDir, binDir, readmeMd, fesms2015Arg, fesms5Arg, bundlesArg, srcsArg, stampData,
licenseFile] = args;
const fesms2015 = fesms2015Arg.split(',').filter(s => !!s);
const fesms5 = fesms5Arg.split(',').filter(s => !!s);
const bundles = bundlesArg.split(',').filter(s => !!s);
const srcs = srcsArg.split(',').filter(s => !!s);
shx.mkdir('-p', out);
let primaryEntryPoint: string|null = null;
const secondaryEntryPoints = new Set<string>();
function replaceVersionPlaceholders(filePath: string, content: string) {
if (stampData) {
const version = shx.grep('BUILD_SCM_VERSION', stampData).split(' ')[1].trim();
// Split the replacement into separate strings so we don't match it while publishing
return content.replace(
new RegExp(
'0.0.0' +
'-PLACEHOLDER',
'g'),
version);
}
return content;
}
/**
* Inserts properties into the package.json file(s) in the package so that
* they point to all the right generated artifacts.
*
* @param filePath file being copied
* @param content current file content
*/
function amendPackageJson(filePath: string, content: string) {
const parsedPackage = JSON.parse(content);
let nameParts = parsedPackage['name'].split('/');
// for scoped packages, we don't care about the scope segment of the path
if (nameParts[0].startsWith('@')) nameParts = nameParts.splice(1);
let rel = Array(nameParts.length - 1).fill('..').join('/');
if (!rel) {
rel = '.';
}
const indexFile = nameParts[nameParts.length - 1];
parsedPackage['main'] = `${rel}/bundles/${nameParts.join('-')}.umd.js`;
parsedPackage['module'] = `${rel}/esm5/${indexFile}.js`;
parsedPackage['es2015'] = `${rel}/esm2015/${indexFile}.js`;
parsedPackage['typings'] = `./${indexFile}.d.ts`;
return JSON.stringify(parsedPackage, null, 2);
}
function writeFesm(file: string, baseDir: string) {
const parts = path.basename(file).split('__');
const entryPointName = parts.join('/').replace(/\..*/, '');
if (primaryEntryPoint === null || primaryEntryPoint === entryPointName) {
primaryEntryPoint = entryPointName;
} else {
secondaryEntryPoints.add(entryPointName);
}
const filename = parts.splice(-1)[0];
const dir = path.join(baseDir, ...parts);
shx.mkdir('-p', dir);
shx.cp(file, dir);
shx.mv(path.join(dir, path.basename(file)), path.join(dir, filename));
}
function moveBundleIndex(f: string) {
let ext: string;
if (f.endsWith('.d.ts'))
ext = '.d.ts';
else if (f.endsWith('.metadata.json'))
ext = '.metadata.json';
else
throw new Error('Bundle index files should be .d.ts or .metadata.json');
const relative = path.relative(binDir, f);
let outputPath: string|undefined = undefined;
for (const secondary of secondaryEntryPoints.values()) {
if (relative.startsWith(secondary)) {
const filename = secondary.split('/').pop();
outputPath = path.join(out, secondary, filename + ext);
}
}
if (!outputPath) {
outputPath = path.join(out, primaryEntryPoint + ext);
}
return outputPath;
}
if (readmeMd) {
shx.cp(readmeMd, path.join(out, 'README.md'));
}
fesms2015.forEach(fesm2015 => writeFesm(fesm2015, path.join(out, 'esm2015')));
fesms5.forEach(fesm5 => writeFesm(fesm5, path.join(out, 'esm5')));
//.........這裏部分代碼省略.........