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


TypeScript utilities.promisify函數代碼示例

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


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

示例1: createPromptModule

import { promisify } from "@civility/utilities"
import * as fs from "fs"
import { createPromptModule } from "inquirer"
import { dump } from "js-yaml"
import { join } from "path"
import { IConfig } from "../../definitions"
import * as q from "../questions"


const prompt = createPromptModule()
const mkdir = promisify(fs.mkdir)
const writeFile = promisify(fs.writeFile)
const ignoreText = `build/
.DS_Store
.Spotlight-V100
.Trashes
._*\n
`

const publisherQuestions: { [key: string]: any } = {
  fs: [ q.blogOut ],
  s3: [ q.s3Creds, q.s3Bucket ],
}

export async function blogGenerator() {
  console.log("\n😳😳🤖😳 WELCOME TO BLOG-O-MATIC! 😳😳🤖😳\n")

  const config = await prompt([
    q.blogAuthor,
    q.blogTitle,
    q.blogPublisher,
開發者ID:Blanket-Warriors,項目名稱:Blog-O-Matic,代碼行數:31,代碼來源:blogGenerator.ts

示例2: require

/**
 * Dev Server
 * This serves and reacts to the dev build of the blog.
 * It's not really meant for use in production, which is
 * why it's in the editor, rather than express.
 */

import { middleware } from "@blog-o-matic/editor-client"
import { promisify } from "@civility/utilities"
import * as express from "express"
import * as fs from "fs"
import { load } from "js-yaml"
import { resolve } from "path"

const opn = require("opn")
const readdir = promisify(fs.readdir)
export const readFile = promisify(fs.readFile)
export const stat = promisify(fs.stat)


export function startServer(previewDir: string) {
  const PORT = 3000
  const server = express()

  server.get("/index.json", async (req, res) => {
    const body = await readdir(resolve(previewDir, "posts"))
    const postData = await Promise.all(body.map(async (loc: string) => {
      const post = await readFile(resolve(previewDir, "posts", loc))
      const parsed = /(?:^---\n)([\s\S]*)(?:---\n)(([\s\S])*)/gm.exec(post) || []
      const frontmatter = load(parsed[1])
      return frontmatter
開發者ID:Blanket-Warriors,項目名稱:Blog-O-Matic,代碼行數:31,代碼來源:index.ts

示例3: promisify

import { promisify } from "@civility/utilities"
import * as fs from "fs"
import { prompt } from "inquirer"
import { dump, load } from "js-yaml"
import { join } from "path"
import { IPost } from "../../definitions"
import * as q from "../questions"
const writeFile = promisify(fs.writeFile)


export async function postGenerator() {
  console.log("\n😳 😳 🤖 😳  LET'S MAKE A BLOG POST! 😳 😳 🤖 😳 \n")

  const config = load(fs.readFileSync("./blog.config.yml", "utf8")) || {}

  const { author = "", title = "" } = await prompt([
    q.postTitle,
     { ...q.postAuthor, default: config.author || "" },
   ]) as IPost

  const id = title
    .replace(",", "")
    .replace(/[^a-zA-Z0-9_.@()-]/g, "-")
    .toLowerCase()

  const permalink = join("posts", `${id}.md`)
  const now = new Date()
  const postData = { author, id, permalink, title, created: now, updated: now }
  const frontmatter = `---\n${dump(postData)}---\n`
  await writeFile(permalink, frontmatter + `# ${title}\n`)
開發者ID:Blanket-Warriors,項目名稱:Blog-O-Matic,代碼行數:30,代碼來源:postGenerator.ts


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