How to use consola - 10 common examples

To help you get started, weโ€™ve selected a few consola examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Cretezy / Noderize / packages / create / src / run.js View on Github external
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);
github nuxt / press / packages / core / src / autoregister.js View on Github external
let pressInstances = {}
  for (const mode of modes) {
    try {
      const { Blueprint } = await importModule(`@nuxt-press/${mode}`)

      const modeInstances = await Blueprint.register(this, config)
      if (modeInstances) {
        pressInstances = {
          ...pressInstances,
          ...modeInstances
        }
      }
    } catch (error) {
      // TODO: improve message
      if (error.code === 'MODULE_NOT_FOUND') {
        consola.warn(`Please install @nuxt-press/${mode}`, error)
      } else {
        consola.error(error)
      }
    }
  }

  // first run all setups
  const setupPromises = Object.values(pressInstances).map(modeInstance => modeInstance.setup())
  await Promise.all(setupPromises)

  // then init the mode instances
  const initPromises = Object.values(pressInstances).map(modeInstance => modeInstance.init())
  await Promise.all(initPromises)

  return pressInstances
}
github Akryum / nodepack / packages / @nodepack / cli / src / lib / PluginAddJob.js View on Github external
// Installation
          if (isTestOrDebug) {
            pkg.devDependencies = pkg.devDependencies || {}
            pkg.devDependencies[packageName] = await getPackageTaggedVersion(packageName).then(version => version && `^${version}`) || 'latest'
            writePkg(cwd, pkg)
          } else if ((!alreadyInPkg || cliOptions.forceInstall) && !cliOptions.noInstall) {
            await shouldCommitState(`[nodepack] before add ${packageName}`, true)
            consola.log('')
            consola.log(`๐Ÿ“ฆ  Installing ${chalk.cyan(packageName)}...`)
            consola.log('')

            const packageManager = loadGlobalOptions().packageManager || getPkgCommand(cwd)
            await installPackage(cwd, packageManager, cliOptions.registry, packageName)

            consola.log(`${chalk.green('โœ”')}  Successfully installed plugin: ${chalk.cyan(packageName)}`)
            consola.log('')
          }

          if (!alreadyInPkg) {
            plugins.push(packageName)
          }

          if (!plugins.includes(packageName)) {
            consola.error(`${packageName} is not installed, can't continue the installation`)
            process.exit(1)
          }
        },
        after: async ({ shouldCommitState }) => {
github Akryum / nodepack / packages / @nodepack / cli / src / lib / ProjectCreateJob.js View on Github external
if (shouldInitGit) {
            const { success } = await commitOnGit(cwd, cliOptions, isTestOrDebug, `[nodepack] create project`)
            gitCommitSuccess = success
          }
          stopSpinner()

          // save preset
          if (this.isPresetManual) {
            await this.askSavePreset(finalPreset)
          }

          // log instructions
          if (!cliOptions.skipGetStarted) {
            consola.log('')
            consola.success(`๐ŸŽ‰  Successfully created project ${chalk.yellow(projectName)}.`)
            consola.log(
              `๐Ÿ‘‰  Get started with the following commands:\n\n` +
              (cwd === process.cwd() ? `` : chalk.cyan(` ${chalk.gray('$')} cd ${projectName}\n`)) +
              chalk.cyan(` ${chalk.gray('$')} nodepack`),
            )
            consola.log('')
          }

          if (!gitCommitSuccess) {
            consola.warn(
              `Skipped git commit due to missing username and email in git config.\n` +
              `You will need to perform the initial commit yourself.\n`,
            )
          }
        },
      },
github Developmint / nuxt-svg-loader / lib / module.js View on Github external
const logger = require('consola').withScope('nuxt-svg-loader')

export default function nuxtSvgLoader() {
  const { svgLoader: options } = this.options

  if (options && options.svgo && !options.svgoConfig) {
    options.svgoConfig = options.svgo
  }

  this.extendBuild(setupVueSvgLoader(options))
}

const svgRulePredicate = rule => rule.test && rule.test.test('.svg')

const setupVueSvgLoader = options => (config) => {
  // https://github.com/egoist/svg-to-vue-component#nuxtjs-2
  const imageLoaderRule = config.module.rules.find(svgRulePredicate)
github Accretion-dev / Accretion / brainhole / server / models / index.js View on Github external
status = await adminDB.command({replSetGetStatus:{}})
    }
    globals.db = globals.conn.db('accretion')

    await mongoose.connect(`mongodb://${ip}:${port}/accretion`, { useNewUrlParser: true })
    globals.history = globals.db.collection('History')
  } catch (e) {
    console.error(e)
    let msg = 'Database connetion error, do you really start the mongodb using the configs/mongod.yml config file???'
    consola.error(msg)
  }

  // clean database if test database and unittest
  if (databaseName === "test") {
    if (config.demoData || config.unittest) {
      consola.ready({
        message: `clean database`,
        badge: true
      })
      let dropResult = await mongoose.connection.db.dropDatabase()
    }
  }

  // if unittest, active all plugin by default
  await initPlugins({allActive: databaseName === "test" && config.unittest})
  initModels()
  if (databaseName === "test") {
    await initTestDatabase({config})
  } else {
    await initProductDatabase()
  }
}
github 44uk / nem2-faucet / server / index.ts View on Github external
await builder.build()
  } else {
    await nuxt.ready()
  }

  const appConfig = await bootstrap.init()

  app.get('/', faucetHandler(appConfig))
  app.post('/claims', claimsHandler(appConfig))

  // Give nuxt middleware to express
  app.use(nuxt.render)

  // Listen the server
  app.listen(port, host)
  consola.ready({
    message: `Server listening on http://${host}:${port}`,
    badge: true
  })

  const { API_URL, FAUCET_ACCOUNT } = appConfig
  monitor(API_URL, FAUCET_ACCOUNT.address)
}
start()
github Cretezy / Noderize / packages / create / src / run.js View on Github external
log.warn(`No path given!`);
		process.exit(1);
		return;
	}

	// Get absolute path
	const path = resolve(await fs.realpath(process.cwd()), name);

	// Check if exist
	if (await fs.exists(path)) {
		log.warn(`Path exists!`);
		process.exit(1);
		return;
	}

	log.start(`Copying...`);

	// Copy from template
	try {
		await fs.copy(resolve(__dirname, "..", "template"), path);
	} catch (error) {
		error(`Error copying.`, error);
		process.exit(1);
		return;
	}

	log.info(`Setting up...`);

	// Set the "name" field in package.json
	try {
		const childPackagePath = resolve(path, "package.json");
		// Read
github nuxt / nuxt.js / packages / cli / src / setup.js View on Github external
}

  if (_setup) {
    return
  }
  _setup = true

  // Global error handler
  /* istanbul ignore next */
  process.on('unhandledRejection', (err) => {
    consola.error(err)
  })

  // Exit process on fatal errors
  /* istanbul ignore next */
  consola.addReporter({
    log (logObj) {
      if (logObj.type === 'fatal') {
        const errorMessage = String(logObj.args[0])
        process.stderr.write(fatalBox(errorMessage))
        exit(1)
      }
    }
  })

  // Wrap all console logs with consola for better DX
  consola.wrapConsole()
}
github nuxt / nuxt.js / packages / cli / src / setup.js View on Github external
})

  // Exit process on fatal errors
  /* istanbul ignore next */
  consola.addReporter({
    log (logObj) {
      if (logObj.type === 'fatal') {
        const errorMessage = String(logObj.args[0])
        process.stderr.write(fatalBox(errorMessage))
        exit(1)
      }
    }
  })

  // Wrap all console logs with consola for better DX
  consola.wrapConsole()
}