本文整理汇总了TypeScript中minimist.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createConfig
/**
* @description Create configuration
*
* @param {string[]} argv command-line arguments
* @returns {object} configuration object
*/
function createConfig(rawArgv: string[]) {
const config = new nconf.Provider(),
parsedArgv = flat.unflatten(minimist(rawArgv), {delimiter: ':'}),
envWhitelist = _(process.env)
.keys()
.filter(function(key: string) {
return ENV_DELIMITER_REGEX.test(key) && !/^npm_config/.test(key);
})
.valueOf()
.concat(['loglevel']);
config.add('argv', {type: 'literal', store: parsedArgv});
config.env({
separator: ENV_DELIMITER,
whitelist: envWhitelist
});
return function get(key: string, defaultValue?: any): any {
var result = coerceValues(config.get(key));
if (_.isUndefined(result)) {
result = defaultValue;
}
return result;
};
}
示例2: executeCommandLine
// tslint:disable-next-line:cognitive-complexity
async function executeCommandLine() {
const argv = minimist(process.argv.slice(2), { '--': true })
const showVersion = argv.v || argv.version
if (showVersion) {
showToolVersion()
return
}
let config: string | undefined = argv.config
if (!config) {
config = defaultConfigName
}
const configPath = path.resolve(process.cwd(), config)
const configFileData: ConfigData | ConfigData[] = require(configPath)
const configDatas = Array.isArray(configFileData) ? configFileData : [configFileData]
const watchMode: boolean = argv.w || argv.watch
for (const configData of configDatas) {
if (!configData.inputFiles || configData.inputFiles.length === 0) {
throw new Error('Error: no input files.')
}
globAsync(configData.inputFiles.length === 1 ? configData.inputFiles[0] : `{${configData.inputFiles.join(',')}}`, configData.excludeFiles).then(uniqFiles => {
const htmlInputFiles: string[] = []
const jsCssInputFiles: string[] = []
const htmlOutputFiles: string[] = []
for (const file of uniqFiles) {
if (isHtmlExtension(file)) {
htmlInputFiles.push(file)
htmlOutputFiles.push(configData.outputFiles(file))
} else {
jsCssInputFiles.push(file)
}
}
if (watchMode) {
const variables: Variable[] = []
let count = 0
chokidar.watch(configData.inputFiles, { ignored: configData.excludeFiles }).on('all', (type: string, file: string) => {
console.log(`Detecting ${type}: ${file}`)
if (type === 'add' || type === 'change') {
if (isHtmlExtension(file)) {
const index = htmlInputFiles.findIndex(f => f === file)
if (index === -1) {
htmlInputFiles.push(file)
htmlOutputFiles.push(configData.outputFiles(file))
} else {
htmlInputFiles[index] = file
htmlOutputFiles[index] = configData.outputFiles(file)
}
count++
if (count > uniqFiles.length) {
revisionHtml(htmlInputFiles, htmlOutputFiles, variables, configData)
} else if (count === uniqFiles.length) {
revisionHtml(htmlInputFiles, htmlOutputFiles, variables, configData)
writeVariables(configData, variables)
}
} else {
revisionCssOrJs(file, configData).then(variable => {
const index = variables.findIndex(v => v.file === file)
if (index === -1) {
variables.push(variable)
} else {
const oldVariable = variables[index]
if (oldVariable.value && oldVariable.value !== variable.value) {
const oldFile = path.resolve(path.dirname(oldVariable.file), oldVariable.value)
console.log(`Removing ${oldFile}`)
fs.unlink(oldFile, error => {
if (error) {
console.log(error)
}
})
}
variables[index] = variable
}
count++
if (count >= uniqFiles.length) {
revisionHtml(htmlInputFiles, htmlOutputFiles, variables, configData)
writeVariables(configData, variables)
}
})
}
} else if (type === 'unlink') {
if (isHtmlExtension(file)) {
const index = htmlInputFiles.findIndex(f => f === file)
if (index !== -1) {
htmlInputFiles.splice(index, 1)
htmlOutputFiles.splice(index, 1)
revisionHtml(htmlInputFiles, htmlOutputFiles, variables, configData)
}
} else {
const index = variables.findIndex(v => v.file === file)
if (index !== -1) {
variables.splice(index, 1)
//.........这里部分代码省略.........
示例3: minimist
#!/usr/bin/env node
import bluebird from 'bluebird';
import fs from 'fs';
import jubatus from 'jubatus';
import _ from 'lodash';
import minimist from 'minimist';
import path from 'path';
import util from 'util';
const debug = util.debuglog('jubatus-tutorial-node');
const { common: { types: { Datum } }, classifier: { types: { LabeledDatum }, client: { Classifier } } } = jubatus;
const args = minimist(process.argv.slice(2), { default: { p: 9199, h: 'localhost', n: '', t: 0, c: 10 } });
debug('%o', args);
const { p: port, h: host, n: name, t: timeout, c: concurrency } = args;
const classifier = new Classifier(port, host, name, timeout);
const readFile = bluebird.promisify(fs.readFile);
const readDir = bluebird.promisify(fs.readdir);
const find = (dirname: string) => readDir(dirname).then(files => files.map(file => path.join(dirname, file)));
const mapStat = (file: string, iteratee: (stat: fs.Stats, file: string) => string | any) =>
new Promise<string>((resolve, reject) => fs.stat(file, (error, stat) => error ? reject(error) : resolve(iteratee(stat, file))));
const filterStat = (files: string[], predicate: (stat: fs.Stats) => boolean) =>
// tslint:disable-next-line:no-shadowed-variable
Promise.all(files.map(file => mapStat(file, stat => predicate(stat) && file))).then(files => files.filter(file => file));
const list = (dirname: string) => {
return find(dirname)
.then(files => filterStat(files, stat => stat.isDirectory()))
.then(directories => Promise.all(directories.map(directory => find(directory))))
示例4: getOption
export function getOption(name: string): string {
if (configData) {
return configData[name] || Private.getBodyData(name);
}
configData = Object.create(null);
let found = false;
// Use script tag if available.
if (typeof document !== 'undefined') {
const el = document.getElementById('jupyter-config-data');
if (el) {
configData = JSON.parse(el.textContent || '') as {
[key: string]: string;
};
found = true;
}
}
// Otherwise use CLI if given.
if (!found && typeof process !== 'undefined') {
try {
const cli = minimist(process.argv.slice(2));
const path: any = require('path');
let fullPath = '';
if ('jupyter-config-data' in cli) {
fullPath = path.resolve(cli['jupyter-config-data']);
} else if ('JUPYTER_CONFIG_DATA' in process.env) {
fullPath = path.resolve(process.env['JUPYTER_CONFIG_DATA']);
}
if (fullPath) {
/* tslint:disable */
// Force Webpack to ignore this require.
configData = eval('require')(fullPath) as { [key: string]: string };
/* tslint:enable */
}
} catch (e) {
console.error(e);
}
}
if (!JSONExt.isObject(configData)) {
configData = Object.create(null);
} else {
for (let key in configData) {
// Quote characters are escaped, unescape them.
configData[key] = String(configData[key])
.split(''')
.join('"');
}
}
return configData![name] || Private.getBodyData(name);
}
示例5: Bundler
export async function main(args: string[]): Promise<number> {
const parsedArgs: {srcs: string, output: string, entry: string} = minimist(args);
const inputFiles = parsedArgs.srcs.split(',');
return new Bundler().Bundle(join(workspaceRoot, parsedArgs.entry), inputFiles).then(result => {
writeFileSync(parsedArgs.output, result.bundledContent);
return 0;
}).catch(error => {
console.error('Sass bundling failed');
console.dir(error);
return 1;
});
}
示例6: minimist
.then(() => {
let args = minimist(environment.args);
let RegisteredCommand = findCommand(
environment.commands,
args._[0]
);
let command = new RegisteredCommand({
ui: this.ui,
project: this.project,
});
return command.validateAndRun(environment.args);
})
示例7: parseCliArgs
export function parseCliArgs(argv: string[]): CliArgTypes {
// remove optional unix node call
if (path.basename(argv[0] || '') === 'node') {
argv.splice(0, 1)
}
// remove optional windows node call
if (path.win32.basename(argv[0] || '') === 'node.exe') {
argv.splice(0, 1)
}
// remove optional linux text-run call
if (path.basename(argv[0] || '') === 'text-run') {
argv.splice(0, 1)
}
// remove optional Windows CLI call
if (argv[0] && argv[0].endsWith('dist\\cli\\cli.js')) {
argv.splice(0, 1)
}
const result = minimist(argv, { boolean: 'offline' })
const commands = result._ || []
delete result._
// extract command
let command = ''
if (availableCommands().includes(commands[0])) {
command = commands[0]
commands.splice(0, 1)
} else {
command = 'run'
}
result.command = command
result.files = commands[0]
return result
}
示例8: generate
var nameParts = schemaInput.properties[propertyName].items.id.split(".");
var typeName = nameParts[nameParts.length - 1];
propertiesString = propertiesString+ "\n {propertyName}:{typeName}[];".format({ propertyName: propertyName,typeName:typeName });
generate(output, typeName , schemaInput.properties[propertyName].items);
}
}
}
output[name] = "\n\nexport interface {className} {{properties}\n}".format({ className: name, properties:propertiesString });
}
}
var args = {};
if (sys.args != undefined)
{
args= minimist(sys.args, {});
}
var targetFileFullName = args.targetFileFullName;
if (targetFileFullName == null) {
targetFileFullName=path.resolve(__dirname, "out.d.ts");
}
var output = {};
generate(output, "Environment", schema);
var fileOptions = { encoding: 'utf-8' };
fs.writeFileSync(targetFileFullName, "//auto-generated", fileOptions);
for (var propertyName in output) {
fs.appendFileSync(targetFileFullName, output[propertyName], fileOptions);
}
示例9: Error
import minimist from 'minimist';
import _ from 'lodash';
import fs from 'fs';
import sax from 'sax';
import { buildSite } from '../../tests/e2e/utils/site-builder';
import c from '../../tests/e2e/test-constants';
const strict = true; // set to false for html-mode
const parser = sax.parser(strict, {});
const UnknownUserId = -2; // ??
const DefaultCategoryId = 2;
const args: any = minimist(process.argv.slice(2));
const wordpressXmlFilePath: string | undefined = args.wordpressCoreXmlExportFile;
if (!_.isString(wordpressXmlFilePath))
throw Error("Missing: --wordpressCoreXmlExportFile=...");
const writeToPath: string | undefined = args.writeTo;
if (!_.isString(writeToPath))
throw Error("Missing: --writeTo=...");
const fileText = fs.readFileSync(wordpressXmlFilePath, { encoding: 'utf8' });
const verboseStr: string | undefined = args.verbose || args.v;
const verbose: boolean = !!verboseStr && verboseStr !== 'f' && verboseStr !== 'false';
console.log("The input file starts with: " + fileText.substring(0, 200));
示例10: require
, heartbeat = require('./heartbeat')
, shelljs = require('shelljs');
/// <reference path="./definitions/Q.d.ts" />
import Q = require('q');
import cm = require('./common');
import cfgm = require('./configuration');
import ifm = require('./api/interfaces');
var SVC_FILE_NAME = '.service';
var _cfgPath = path.join(__dirname, '..', SVC_FILE_NAME);
// on OSX (Darwin), a launchd daemon will get installed as: com.sample.myserver
// on Linux, a start-stop-daemon will get installed as: myserver
var args = argparser(process.argv.slice(2));
var action = args['_'][0];
console.log('action: ' + action);
var showUsage = function (code) {
console.log('usage: svc.sh install, start, stop, restart');
console.log('\taction=install, start, stop');
console.log('\tnote: only install needs username and password');
process.exit(code);
};
if (!action || action === '-?') {
showUsage(action ? 0 : 1);
}
if (!cfgm.exists()) {
console.error('The agent must be configured before running as a service. Run the agent and configure.');
process.exit(1);
}