本文整理匯總了TypeScript中ora.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: async
export default async (args: Args, buildPath: string) => {
const serverOptions = await getServerOptions(args)
const protocol = serverOptions.https ? 'https' : 'http'
const url = `${protocol}://${serverOptions.host}:${serverOptions.port}`
const server = new Server({
buildPath,
...serverOptions,
})
await server.listen()
const spinner = ora()
spinner.succeed(`Server running on: ${url}`)
}
示例2: async
export default async (args: Args) => {
args = merge<Args>(
{
options: {
env: {
NODE_ENV: process.env.NODE_ENV || 'production',
},
},
middleware: [],
},
args
)
const spinner = ora('Building project').start()
let result
try {
result = await run('build', args)
} catch (err) {
spinner.fail('Failed to compile.')
printBuildError(err)
process.exit(1)
}
const { warnings } = result
if (warnings.length) {
spinner.warn('Compiled with warnings.')
// tslint:disable-next-line:no-console
console.log(warnings.join('\n\n'))
// tslint:disable-next-line:no-console
console.log(
'\nSearch for the ' +
chalk.underline(chalk.yellow('keywords')) +
' to learn more about each warning.'
)
// tslint:disable-next-line:no-console
console.log(
'To ignore, add ' +
chalk.cyan('// eslint-disable-next-line') +
' to the line before.\n'
)
} else {
spinner.succeed('Compiled successfully.')
}
}
示例3: async
export default async (args: Args) => {
const serverOptions = await getServerOptions(args)
const protocol = serverOptions.https ? 'https' : 'http'
const url = `${protocol}://${serverOptions.host}:${serverOptions.port}`
args = merge<Args>(
{
options: {
env: {
NODE_ENV: process.env.NODE_ENV || 'development',
},
},
middleware: [],
},
args
)
if (isInteractive) {
clearConsole()
}
const spinner = ora('Compiling project').start()
let multiCompiler: MultiCompiler
try {
multiCompiler = await run('start', args)
} catch (err) {
spinner.fail('Failed to compile')
// tslint:disable:no-console
console.log()
console.log(err.stackTrace || err)
console.log()
// tslint:enable:no-console
throw exitProcess(1)
}
const server = new Server({
multiCompiler,
...serverOptions,
})
await server.listen()
spinner.succeed(`Development server running on: ${url}`)
openBrowser(url)
const building = ora('Waiting for initial compilation to finish').start()
multiCompiler.plugin('done', (stats: Stats) => {
if (isInteractive) {
clearConsole()
}
// We have switched off the default Webpack output in WebpackDevServer
// options so we are going to "massage" the warnings and errors and present
// them in a readable focused way.
const messages = formatWebpackMessages(stats.toJson())
const isSuccessful = !messages.errors.length && !messages.warnings.length
if (isSuccessful) {
building.succeed(`Compiled successfully!`)
}
// If errors exist, only show errors.
if (messages.errors.length) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
if (messages.errors.length > 1) {
messages.errors.length = 1
}
building.fail(`Failed to compile`)
// tslint:disable-next-line:no-console
console.log(messages.errors.join('\n\n'))
return
}
// Show warnings if no errors were found.
if (messages.warnings.length) {
building.warn('Compiled with warnings')
// tslint:disable-next-line:no-console
console.log(messages.warnings.join('\n\n'))
// Teach some ESLint tricks.
// tslint:disable-next-line:no-console
console.log(
'\nSearch for the ' +
chalk.underline(chalk.yellow('keywords')) +
' to learn more about each warning.'
)
// tslint:disable-next-line:no-console
console.log(
'To ignore, add ' +
chalk.cyan('// eslint-disable-next-line') +
' to the line before.\n'
)
}
})
multiCompiler.plugin('invalid', () => {
if (isInteractive) {
clearConsole()
}
building.text = 'Compiling...'
building.start()
})
//.........這裏部分代碼省略.........
示例4: ora
import ora from 'ora'
export default ora()
示例5: async
return async (options: T) => {
const spinner = ora(spinnerLabel);
spinner.start();
try {
await fn(options);
spinner.succeed();
} catch (e) {
spinner.fail(e);
if (killProcess) {
process.exit(1);
}
}
};
示例6: runTask
async function runTask(name: string, taskFn: () => Promise<any>) {
const spinner = ora(name);
try {
spinner.start();
await taskFn();
spinner.succeed();
} catch (e) {
spinner.fail();
throw e;
}
}
示例7: async
export const createTestBundle = async (modulePath: string): Promise<TestBundle> => {
const bundler = browserify(modulePath, {
// Generate sourcemaps for debugging
debug: true,
// Expose the module under this global variable
standalone: 'moduleUnderTest',
// rootDir for sourcemaps
basedir: __dirname + '/../../src',
})
bundler.plugin(tsify, { project: __dirname + '/../../tsconfig.test.json' })
// If running through nyc, instrument bundle for coverage reporting too
if (process.env.NYC_CONFIG) {
bundler.transform(babelify.configure({ plugins: [babelPluginIstanbul], extensions: ['.tsx', '.ts'] }))
}
const spinner = ora(`Bundling ${modulePath}`)
bundler.on('file', (file, id) => {
spinner.text = `Bundling ${id}`
})
spinner.start()
try {
const bundle = await getStream(bundler.bundle())
return {
load(): DOMModuleSandbox {
const jsdom = new JSDOM('', { runScripts: 'dangerously' }) as JSDOM & {
window: { moduleUnderTest: any }
}
jsdom.window.eval(bundle)
return { window: jsdom.window, module: jsdom.window.moduleUnderTest }
},
}
} finally {
spinner.stop()
}
}
示例8: ora
import chalk from 'chalk';
import ora from 'ora';
import program from 'commander';
import rename from './redater';
let directoryValue!: string;
program
.version('0.0.3')
.description('Rename photos based on their date taken')
.arguments('<directory>')
.action(directory => {
directoryValue = directory;
});
program.parse(process.argv);
const spinner = ora('Renaming photos').start();
rename(directoryValue, spinner)
.then(() => {
spinner.text = 'Renamed';
spinner.succeed();
})
.catch(err => {
spinner.text = "Photos can't be renamed";
spinner.fail();
// tslint:disable-next-line
console.log(chalk.red(err.stack));
});
示例9: Error
(async () => {
const electronPrebuiltPath = argv.e ? path.resolve(process.cwd(), (argv.e as string)) : locateElectronPrebuilt();
let electronPrebuiltVersion = argv.v as string;
if (!electronPrebuiltVersion) {
try {
if (!electronPrebuiltPath) throw new Error('electron-prebuilt not found');
const pkgJson = require(path.join(electronPrebuiltPath, 'package.json'));
electronPrebuiltVersion = pkgJson.version;
} catch (e) {
throw new Error('Unable to find electron-prebuilt\'s version number, either install it or specify an explicit version');
}
}
let rootDirectory = argv.m as string;
if (!rootDirectory) {
// NB: We assume here that we're going to rebuild the immediate parent's
// node modules, which might not always be the case but it's at least a
// good guess
rootDirectory = path.resolve(__dirname, '../../..');
if (!await fs.pathExists(rootDirectory) || !await fs.pathExists(path.resolve(rootDirectory, 'package.json'))) {
// Then we try the CWD
rootDirectory = process.cwd();
if (!await fs.pathExists(rootDirectory) || !await fs.pathExists(path.resolve(rootDirectory, 'package.json'))) {
throw new Error('Unable to find parent node_modules directory, specify it via --module-dir, E.g. "--module-dir ." for the current directory');
}
}
} else {
rootDirectory = path.resolve(process.cwd(), rootDirectory);
}
let modulesDone = 0;
let moduleTotal = 0;
const rebuildSpinner = ora('Searching dependency tree').start();
let lastModuleName: string;
const redraw = (moduleName?: string) => {
if (moduleName) lastModuleName = moduleName;
if (argv.p) {
rebuildSpinner.text = `Building modules: ${modulesDone}/${moduleTotal}`;
} else {
rebuildSpinner.text = `Building module: ${lastModuleName}, Completed: ${modulesDone}`;
}
};
const rebuilder = rebuild({
buildPath: rootDirectory,
electronVersion: electronPrebuiltVersion,
arch: (argv.a as string) || process.arch,
extraModules: argv.w ? (argv.w as string).split(',') : [],
onlyModules: argv.o ? (argv.o as string).split(',') : null,
force: argv.f as boolean,
headerURL: argv.d as string,
types: argv.t ? (argv.t as string).split(',') as ModuleType[] : ['prod', 'optional'],
mode: argv.p ? 'parallel' : (argv.s ? 'sequential' : undefined),
debug: argv.b as boolean
});
const lifecycle = rebuilder.lifecycle;
lifecycle.on('module-found', (moduleName: string) => {
moduleTotal += 1;
redraw(moduleName);
});
lifecycle.on('module-done', () => {
modulesDone += 1;
redraw();
});
try {
await rebuilder;
} catch (err) {
rebuildSpinner.text = 'Rebuild Failed';
rebuildSpinner.fail();
throw err;
}
rebuildSpinner.text = 'Rebuild Complete';
rebuildSpinner.succeed();
})();
示例10: build
// Are we in production?
isProduction: process.env.NODE_ENV === "production",
// Host to bind the server to
host: process.env.HOST || "0.0.0.0",
// Port to start web server on
port: (process.env.PORT && parseInt(process.env.PORT)) || 3000,
// WebSocket port (for dev)
websocketPort:
(process.env.WS_PORT && parseInt(process.env.WS_PORT)) || undefined,
// Spinner
spinner: ora()
};
// Webpack compiler
export const compiler = webpack([serverConfig, clientConfig]);
export const staticCompiler = webpack([staticConfig]);
// Build function
export function build(buildStatic = false) {
// Determine which compiler to run
const buildCompiler = buildStatic ? staticCompiler : compiler;
return new Promise(resolve => {
buildCompiler.run((e, fullStats) => {
// If there's an error, exit out to the console
if (e) {