當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ora類代碼示例

本文整理匯總了TypeScript中ora的典型用法代碼示例。如果您正苦於以下問題:TypeScript ora類的具體用法?TypeScript ora怎麽用?TypeScript ora使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ora類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: prepareQuickAppEnvironment

async function prepareQuickAppEnvironment (buildData: IBuildData) {
  let isReady = false
  let needDownload = false
  let needInstall = false
  const originalOutputDir = buildData.originalOutputDir
  console.log()
  if (fs.existsSync(path.join(buildData.originalOutputDir, 'sign'))) {
    needDownload = false
  } else {
    needDownload = true
  }
  if (needDownload) {
    const getSpinner = ora('開始下載快應用運行容器...').start()
    await downloadGithubRepoLatestRelease('NervJS/quickapp-container', buildData.appPath, originalOutputDir)
    await unzip(path.join(originalOutputDir, 'download_temp.zip'))
    getSpinner.succeed('快應用運行容器下載完成')
  } else {
    console.log(`${chalk.green('✔ ')} 快應用容器已經準備好`)
  }

  console.log()
  process.chdir(originalOutputDir)
  if (fs.existsSync(path.join(originalOutputDir, 'node_modules'))) {
    needInstall = false
  } else {
    needInstall = true
  }
  if (needInstall) {
    let command
    if (shouldUseYarn()) {
      command = 'NODE_ENV=development yarn install'
    } else if (shouldUseCnpm()) {
      command = 'NODE_ENV=development cnpm install'
    } else {
      command = 'NODE_ENV=development npm install'
    }
    const installSpinner = ora(`安裝快應用依賴環境, 需要一會兒...`).start()
    const install = shelljs.exec(command, { silent: true })
    if (install.code === 0) {
      installSpinner.color = 'green'
      installSpinner.succeed('安裝成功')
      console.log(`${install.stderr}${install.stdout}`)
      isReady = true
    } else {
      installSpinner.color = 'red'
      installSpinner.fail(chalk.red(`快應用依賴環境安裝失敗,請進入 ${path.basename(originalOutputDir)} 重新安裝!`))
      console.log(`${install.stderr}${install.stdout}`)
      isReady = false
    }
  } else {
    console.log(`${chalk.green('✔ ')} 快應用依賴已經安裝好`)
    isReady = true
  }
  return isReady
}
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:55,代碼來源:index.ts

示例2: return

 return () => {
   if (!spinner) spinner = ora(`Starting development server, please wait~`)
   return spinner
 }
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:4,代碼來源:logHelper.ts

示例3: ora

  commandObject.handler = argv => {
    // load env vars from .env file
    const envPath = argv['dotenv'] || '.env'
    dotenv.config({ path: envPath })

    // prepare context object
    const context: Context = {
      prompt: inquirer.createPromptModule(),
      spinner: ora(),
      async getProjectConfig() {
        let config: GraphQLProjectConfig | undefined
        while (!config) {
          try {
            config = argv['project']
              ? getGraphQLProjectConfig(process.cwd(), argv['project'])
              : (getGraphQLProjectConfig(process.cwd()) as GraphQLProjectConfig)

            config.config = resolveEnvsInValues(config.config, process.env)
            config = await patchGraphcoolEndpointsToConfig(
              config,
              process.cwd(),
            )
            config = await patchPrismaEndpointsToConfig(config, process.cwd())
            config = await patchOpenApiEndpointsToConfig(config)
          } catch (error) {
            const config: GraphQLConfig = getGraphQLConfig(process.cwd())
            const projectNames = Object.keys(config.getProjects() || {})
            if (projectNames) {
              if (error.message.includes('multiproject')) {
                console.log(chalk.yellow('No project name specified'))
              } else if (error.message.includes('not a valid project name')) {
                console.log(chalk.yellow('Invalid project name specified'))
              }
              const { projectName } = await inquirer.prompt({
                type: 'list',
                name: 'projectName',
                choices: projectNames,
                message: 'Select a project:',
              })
              argv['project'] = projectName
            } else {
              throw error
            }
          }
        }
        return config
      },
      async getConfig() {
        let config = getGraphQLConfig(process.cwd())
        config.config = resolveEnvsInValues(config.config, process.env)
        config = await patchGraphcoolEndpointsToConfig(config)
        config = await patchPrismaEndpointsToConfig(config)
        config = await patchOpenApiEndpointsToConfig(config)
        return config
      },
    }

    let result = new Promise((resolve, reject) => {
      try {
        resolve(originalHandler(context, argv))
      } catch (e) {
        reject(e)
      }
    })

    result.catch(e => {
      if (context.spinner['enabled']) {
        context.spinner.fail()
      }
      if (process.env.DEBUG === '*') {
        if (e.stack) {
          console.log(e.stack)
        } else {
          console.log(e)
        }
      } else {
        console.log(chalk.red(e.message))
      }

      if (e instanceof ConfigNotFoundError) {
        console.log(
          chalk.yellow(
            `\nRun ${chalk.green('graphql init')} to create new .graphqlconfig`,
          ),
        )
      }

      process.exitCode = 1
    })
  }
開發者ID:koddsson,項目名稱:graphql-cli,代碼行數:90,代碼來源:index.ts

示例4: locateElectronPrebuilt

(async () => {
  const electronPrebuiltPath = argv.e ? path.resolve(process.cwd(), argv.e) : locateElectronPrebuilt();
  let electronPrebuiltVersion = argv.v; 

  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;

  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.exists(rootDirectory) || !await fs.exists(path.resolve(rootDirectory, 'package.json'))) {
      // Then we try the CWD
      rootDirectory = process.cwd();
      if (!await fs.exists(rootDirectory) || !await fs.exists(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(rootDirectory, electronPrebuiltVersion, argv.a || process.arch, argv.w ? argv.w.split(',') : [], argv.f, argv.d, argv.t ? argv.t.split(',') : ['prod', 'dev'], argv.p ? 'parallel' : (argv.s ? 'sequential' : undefined));

  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();
})();
開發者ID:our-city-app,項目名稱:mobicage-desktop-client,代碼行數:72,代碼來源:cli.ts


注:本文中的ora類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。