• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript co类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中co的典型用法代码示例。如果您正苦于以下问题:TypeScript co类的具体用法?TypeScript co怎么用?TypeScript co使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了co类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: Promise

    return new Promise((resolve, reject) => {
        let comp = location.split("/");

        // If the length is 1 then only the one file needs to be created
        if (comp.length === 1) {
            fs.writeFile(`${currentLocation}/${location}.${type}`, file,
                err => reject(err),
                () => resolve("Created successfully")
            );
        }

        else {

            let path = `${currentLocation}/`,
                fileName = `${comp[comp.length - 1]}.${type}`;

            // Add all of the other params to the path except for the last one which is the name of the file
            for (let i = 0; i < comp.length - 1; i++) path += `${comp[i]}/`;

            co(function* (){
                yield mkdirp(path);
            })
                .catch(err => console.log(err.stack))
                .then(() => {
                        fs.writeFile(`${currentLocation}/${location}.${type}`, file,
                            (err) => reject(err),
                            () => resolve("Created successfully")
                        )
                    })
        }
    })
开发者ID:flauc,项目名称:angular2-generator,代码行数:31,代码来源:filer.ts


示例2: createDefaultDbDocs

export function createDefaultDbDocs(db) {
    co(function *() {
        let users = yield db.collection('users').find({}).toArray();

        // If the users array is empty
        if (users.length === 0) {

            console.log('No users in the database. Creating default users now...');

            let users = [
                {username: '[email protected]', password: 'filip', status: 'offline', profileImage: 0},
                {username: '[email protected]', password: 'wojtek', status: 'offline', profileImage: 0},
                {username: '[email protected]', password: 'suguru', status: 'offline', profileImage: 0},
                {username: '[email protected]', password: 'mary', status: 'offline', profileImage: 0},
                {username: '[email protected]', password: 'ran', status: 'offline', profileImage: 0}
            ];

            for (let i = 0; i < users.length; i++) {
                users[i].profileImage = generateRandomInt(1, 49);
                users[i].password = yield hashPass(users[i].password);
            }

            let r = yield db.collection('users').insertMany(users);
            
            if (r.insertedCount === users.length) console.log('...users created successfully.')

        }
    }).catch((err) => console.log(err))
}
开发者ID:andreyZavrazhnov,项目名称:angular2-edge-app,代码行数:29,代码来源:commonHelpers.ts


示例3: Promise

        return new Promise((resolve, reject) => {
            if (!doInject) return resolve(value);

            co(function *() {
                let data;

                try {
                    data = yield promiseFsReadFile(location)
                } catch (err) {
                    throw err;
                }

                data = data.toString().split('\n');
                data.splice(lineNumber, 0, items[item].types[type].html);
                
                let full = data.join('\n');

                return yield promiseFsWriteFile(location, full)
            })
                .then(res => resolve(value))
                .catch(err => reject(err))
        })
开发者ID:flauc,项目名称:ui-gen,代码行数:22,代码来源:generate.ts


示例4: co

        }).then(values => {

            if (values.generateApp) {
                co(function *() {
                    let appArray = [];

                        // TODO Finish flag implementation
                        // Files per flag
                        // flagsForType = {
                        //     "standard": {
                        //         t: [createFile(flags[values.json.appType].t, "tslint", "json")],
                        //         g: [createFile(flags[values.json.appType].g, "gulpfile", "js")]
                        //     },
                        //     "npm library": {
                        //         t: [createFile(flags[values.json.appType].t, "tslint", "json")],
                        //         g: [createFile(flags[values.json.appType].g, "gulpfile", "js")]
                        //     }
                        // };

                    switch (values.json.appType) {
                        case "standard":
                            appArray = [
                                createFile(createTemplateStringFromObject(values.json), "ng2config", "json"),
                                createFile(index(values.json.appFolder, values.json.bootLocation.slice(0, -3), values.json.appName), "index", "html"),
                                createFile(createTemplateStringFromObject(tsconfig), "tsconfig", "json"),
                                createFile(createTemplateStringFromObject(packageJson(values.json.appName)), "package", "json"),
                                createFile(createTemplateStringFromObject(typings), "typings", "json"),
                                createFile(boot, `${values.json.appFolder}/boot`, "ts"),
                                createFile(appComponent, `${values.json.appFolder}/app.component`, "ts")
                            ];
                            break;
                        case "npm library":
                            break;
                    }

                    // If flags were provided create the reguired files 
                    if (values.appFlags) values.appFlags.split("").forEach(a => flagsForType[values.appType][a].forEach(b => appArray.push(b)));

                    yield appArray
                })
                    .catch(err => reject(err.stack))
                    .then(() => {
                        console.log(chalk.green(`\nApplication created. Attempting to run scripts now.`));
                        resolve(false)
                    });
            }

            else {
                createFile(createTemplateStringFromObject(values.json), "ng2config", "json")
                    .catch(err => reject(err))
                    .then(() => {
                        console.log(chalk.green(`\nng2config.json created successfully.`));
                        resolve(true)
                    });
            }

        })
开发者ID:flauc,项目名称:angular2-generator,代码行数:57,代码来源:init.ts


示例5: Promise

    return new Promise((resolve, reject) => {
        // Display the intro text
        console.log(initPrompt.intro);

        co(function *() {

            // Match paths of this format: app/path/path
            let pathValidator = /^(([A-z0-9\-]+\/)*[A-z0-9\-]+$)/g,
                // Match paths of the same format that end with .ts
                pathFileValidator = /^(([A-z0-9\-]+\/)*[A-z0-9\-]+(.ts)+$)/g,
                ynValidator = /^([yn]|(yes)|(no))$/ig,

                appName,
                toReturn,
                introMessage = (format) => `\nPlease enter a path matching the following format: ${chalk.green(format)}\nDon't add a leading or trailing slash to the path.\n`,

                prompts = [
                    {
                        name: "appFolder",
                        question: "App Folder: (app) ",
                        value: "app",
                        message: "something/foo/bar",
                        validator: pathValidator
                    },
                    {
                        name: "bootFile",
                        question: "Location of bootstrap file: (boot.ts) ",
                        value: "boot.ts",
                        message: "something/foo/bar.ts",
                        validator: pathFileValidator
                    },
                    {
                        name: "componentsFolder",
                        question: "Components Folder: (common/components) ",
                        value: "common/components",
                        message: "something/foo/bar",
                        validator: pathValidator
                    },
                    {
                        name: "servicesFolder",
                        question: "Services Folder: (common/services) ",
                        value: "common/services",
                        message: "something/foo/bar",
                        validator: pathValidator
                    },
                    {
                        name: "directivesFolder",
                        question: "Directives Folder: (common/directives) ",
                        value: "common/directives",
                        message: "something/foo/bar",
                        validator: pathValidator
                    },
                    {
                        name: "pipesFolder",
                        question: "Pipes Folder: (common/pipes) ",
                        value: "common/pipes",
                        message: "something/foo/bar",
                        validator: pathValidator
                    }
                ],

                values = {
                    appFolder: "app",
                    bootFile: "boot.ts",
                    componentsFolder: "common/components",
                    servicesFolder: "common/services",
                    directivesFolder: "common/directives",
                    pipesFolder: "common/pipes"

                },


                generateApp = (yield prompt("Create starter app? (Y/n) ")) || "Y";

            while (generateApp.search(ynValidator) === -1) {
                console.log(chalk.red("\nOnly Y,N,yes and no are valid inputs.\n"));
                generateApp = (yield prompt("Create starter app? (Y/n) ")) || "Y";
            }

            generateApp =  /^(y|(yes))$/ig.test(generateApp);

            if (generateApp) {
                let appTypeQuestion = `What kind of starting structure do you want to generate?\n(input the number associated with the app type)\n\n    1 - standard\n    2 - npm library\n\nStructure (1): `,
                    appNameQuestion = `App name: (test-app) `,
                    appType = (yield prompt(appTypeQuestion)) || "1",
                    appTypeName,
                    allowedFlagsValidator,
                    allowedFlags = {
                        "standard": [["t", "tslint"], ["g", "gulpfile"], ["a", "standard api service"], ["r", "basic routing"], ["l", "basic login"], ["s", "basic signup"]],
                        "npmLibrary": [["t", "tslint"], ["g", "gulpfile"]]
                    };

                while (appType.search(/^(1|2)$/g) === -1) {
                    console.log(chalk.red("\nPlease provide a number between 1 and 2\n"));
                    appType = (yield prompt(appTypeQuestion)) || "1";
                }

                appTypeName = appType === "1" ? "standard" : "npmLibrary";

                appName = (yield prompt(appNameQuestion)) || "test-app";
//.........这里部分代码省略.........
开发者ID:flauc,项目名称:angular2-generator,代码行数:101,代码来源:init.ts



注:本文中的co类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript co-body类代码示例发布时间:2022-05-28
下一篇:
TypeScript clone类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap