本文整理汇总了TypeScript中opn类的典型用法代码示例。如果您正苦于以下问题:TypeScript opn类的具体用法?TypeScript opn怎么用?TypeScript opn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了opn类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: handler
export async function handler(
context: Context,
argv: { endpoint: string; port: string; web: boolean; serverOnly: boolean },
) {
const localPlaygroundPath = `/Applications/GraphQL\ Playground.app/Contents/MacOS/GraphQL\ Playground`
const isLocalPlaygroundAvailable = fs.existsSync(localPlaygroundPath)
const shouldStartServer =
argv.serverOnly || argv.web || !isLocalPlaygroundAvailable
const shouldOpenBrowser = !argv.serverOnly
if (shouldStartServer) {
const link = await startServer({
context,
endpoint: argv.endpoint,
port: argv.port,
})
if (shouldOpenBrowser) {
opn(link)
}
} else {
const envPath = getTmpPath()
fs.writeFileSync(envPath, JSON.stringify(process.env))
const url = `graphql-playground://?cwd=${process.cwd()}&envPath=${envPath}`
opn(url, { wait: false })
}
}
示例2: startWithPort
/**
* @param {Object} options
* @param {Number} options.port -- port number
* @param {String} options.host -- hostname string
* @param {String=} options.page -- page path, ex: "/", "/index.html"
* @param {(String|String[])} options.browser -- names of browser apps to launch
* @return {Promise}
*/
function startWithPort(options: ServerOptions) {
options.port = options.port || 8080;
options.host = options.host || "localhost";
console.log('Starting Polyserve on port ' + options.port);
let app = express();
let polyserve = makeApp({
componentDir: options.componentDir,
packageName: options.packageName,
root: process.cwd(),
});
app.use(apiProxy('localhost', 8421));
app.get('/', function (req, res) {
res.redirect(301, `/components/${polyserve.packageName}/`);
});
app.use('/components/', polyserve);
let server = http.createServer(app);
let serverStartedResolve: (r: any) => void;
let serverStartedReject: (r: any) => void;
let serverStartedPromise = new Promise((resolve, reject) => {
serverStartedResolve = resolve;
serverStartedReject = reject;
});
server = app.listen(options.port, options.host,
() => serverStartedResolve(server));
server.on('error', function(err: any) {
if (err.code === 'EADDRINUSE') {
console.error(portInUseMessage(options.port));
}
serverStartedReject(err);
});
let baseUrl = `http://${options.host}:${options.port}/components/${polyserve.packageName}/`;
console.log(`Files in this directory are available under ${baseUrl}`);
if (options.page) {
let url = baseUrl + (options.page === true ? 'index.html' : options.page);
if (Array.isArray(options.browser)) {
for (let i = 0; i < options.browser.length; i++)
opn(url, options.browser[i]);
}
else {
opn(url, options.browser);
}
}
return serverStartedPromise;
}
示例3: handleSignIn
/**
* Start the sign in process by opening CodeSandbox CLI login url, this page
* will show a token that the user will have to fill in in the CLI
*
* @returns
*/
async function handleSignIn() {
// Open specific url
info(`Opening ${CLI_LOGIN_URL}`);
opn(CLI_LOGIN_URL, { wait: false });
const { authToken } = await inquirer.prompt([
{
message: 'Token:',
name: 'authToken',
type: 'input',
},
]);
// We got the token! Ask the server on authorization
const spinner = ora('Fetching user...').start();
try {
const { token, user } = await api.verifyUser(authToken);
// Save definite token and user to config
spinner.text = 'Saving user...';
await cfg.saveUser(token, user);
spinner.stop();
return user;
} catch (e) {
spinner.stop();
throw e;
}
}
示例4: createMyServer
function createMyServer(port) {
const server = createSecureServer({ key: privateKey, cert: certificate });
const url = `https://localhost:${port}`;
server.addListener('request', request);
server.listen(port);
console.log(`Listen port ${port}...`);
console.log('Available urls:');
console.log(url);
const cachePath = join(process.cwd(), '.cache-download');
if (!existsSync(cachePath)){
mkdirSync(cachePath);
}
getLocales(cachePath).then(() => {
const localesTimer = setInterval(function() {
getLocales(cachePath)
.catch(err => console.log(err))
}, 60 * 10000);
localesTimer.unref();
});
if (args.openUrl) {
opn(url);
}
}
示例5: opn
server.get('/open', (req, res, next) => {
if (!req.query.url) {
res.send(200);
return;
}
opn(req.query.url);
res.send(200);
});
示例6: openWebPage
/**
* Open the given web page URL. If no browser keyword is provided, `opn` will use
* the user's default browser.
*/
function openWebPage(url: string, withBrowser?: string) {
let openOptions = {
app: withBrowser
};
opn(url, openOptions, (err) => {
if (err) {
// log error and continue
console.error(`ERROR: Problem launching "${openOptions.app || 'default web browser'}".`);
}
});
}
示例7: opn
return app.listen(function() {
app.emit('started');
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
}
opn( (baseUrl + explorerPath), { app: 'google chrome' } );
});
示例8: reject
server.listen(devServerOptions.port as number, devServerOptions.host as string, err => {
if (err) {
reject()
return console.log(err)
}
resolve()
/* 补充处理devServer.open配置 */
if (devServerOptions.open) {
opn(devUrl)
}
})
示例9: function
PullRequest.prototype.browser = function(user, repo, number) {
if (number) {
openUrl(`${config.github_host}${user}/${repo}/pull/${number}`, { wait: false })
} else {
openUrl(`${config.github_host}${user}/${repo}/pulls`, { wait: false })
}
}
示例10: function
Issue.prototype.browser = function(user, repo, number) {
if (!number) {
number = ''
}
openUrl(`${config.github_host}${user}/${repo}/issues/${number}`, { wait: false })
}