Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
newChildPackage.noderize = { languages: "typescript" };
}
// Write
await fs.writeJson(childPackagePath, newChildPackage, { spaces: "\t" });
} catch (error) {
log.error(`Error saving package.json.`);
log.error(error);
process.exit(1);
return;
}
// Move "gitignore" to ".gitignore"
try {
await fs.rename(resolve(path, "gitignore"), resolve(path, ".gitignore"));
} catch (error) {
log.error(`Error moving .gitignore.`);
log.error(error);
process.exit(1);
return;
}
if (typescript) {
// Setup TypeScript
try {
await fs.rename(
resolve(path, "src", "index.js"),
resolve(path, "src", "index.ts")
);
} catch (error) {
log.error(`Error moving src/index.js to src/index.ts.`);
log.error(error);
process.exit(1);
export default async function Statusfy () {
// Merge all option sources
const options = {}
try {
const response = await axios.get('https://opencollective.com/statusfy/members/all.json?TierId=6927')
const partners = response.data
.filter(p => p.isActive)
.map(p => pick(p, ['MemberId', 'website', 'image', 'name', 'description']))
options.partners = partners
} catch (error) {
consola.error(error)
}
// Register plugin
this.addPlugin({
src: resolve(__dirname, 'plugin.js.tpl'),
fileName: 'statusfy.js',
options
})
}
// Resolve handler setup as string (path)
if (typeof handler === 'string') {
try {
const requiredModuleFromHandlerPath = this.nuxt.resolver.requireModule(handler)
// In case the "handler" is not derived from an object but is a normal string, another object with
// path and handler could be the result
// If the required module has handler, treat the module as new "middleware" object
if (requiredModuleFromHandlerPath.handler) {
middleware = requiredModuleFromHandlerPath
}
handler = requiredModuleFromHandlerPath.handler || requiredModuleFromHandlerPath
} catch (err) {
consola.error(err)
// Throw error in production mode
if (!this.options.dev) {
throw err
}
}
}
// Resolve path
const path = (
(middleware.prefix !== false ? this.options.router.base : '') +
(typeof middleware.path === 'string' ? middleware.path : '')
).replace(/\/\//g, '/')
// Use middleware
this.app.use(path, handler)
}
// Answers
let options = rootOptions[migration.plugin.id]
if (!options) {
options = rootOptions[migration.plugin.id] = {}
}
consola.log(chalk.grey(`${migration.plugin.id} is prompting:`))
let answers = await inquirer.prompt(prompts)
// Check if answers are seriazable
try {
const oldAnswers = answers
answers = JSON.parse(JSON.stringify(answers))
if (Object.keys(answers).length !== Object.keys(oldAnswers).length) {
throw new Error(`Missing answers`)
}
} catch (e) {
consola.error(`Answers are not serializable into JSON for plugin ${migration.plugin.id} migration ${migration.options.id}`)
}
options[migration.options.id] = answers
}
}
return rootOptions
}
process.on('unhandledRejection', err => {
consola.error(err)
})
let customIndicator = false
if (!await fsExtra.exists(indicatorPath)) {
indicatorPath = this.nuxt.resolver.resolveAlias(
this.options.loadingIndicator.name
)
if (await fsExtra.exists(indicatorPath)) {
customIndicator = true
} else {
indicatorPath = null
}
}
if (!indicatorPath) {
consola.error(
`Could not fetch loading indicator: ${
this.options.loadingIndicator.name
}`
)
return
}
templateFiles.push({
src: indicatorPath,
dst: 'loading.html',
custom: customIndicator,
options: this.options.loadingIndicator
})
}
const log = (req, res, reqObj, resObj) => {
const diff = process.hrtime(req.startAt)
const resTime = (diff[0] * 1e3 + diff[1] * 1e-6).toFixed(2)
consola.log('\n')
consola.info('req:', reqObj)
consola.info('res:', resObj)
if (res.statusCode >= 400 && res.statusCode < 500) {
consola.warn(resObj.body)
} else if (res.statusCode >= 500) {
consola.error(resObj.body)
}
consola.log(`${getRequestColor(res.statusCode, req.httpVersion)} ${
getMethodColor(req.method)} ${req.originalUrl} - ${
getStatusColor(res.statusCode)} - ${resTime} ms`)
}
$axios.onError(errorValue => {
const code = parseInt(errorValue.response && errorValue.response.status);
if (code === 404) {
error({ statusCode: 404, message: "Not found" });
}
if (process.env.isDev) {
const consola = require("consola");
consola.error(errorValue);
}
});