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


TypeScript task.Task類代碼示例

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


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

示例1: generate

    generate (helpers: unknown) {
        const self = this;
        const tasks: Task<unknown, NodeJS.ErrnoException | UnknownError>[] = [];

        if (self.generatorSettings.copyAssets) {
            tasks.push(self.copyAssets());
        }

        // TODO: Remove the files settings, probably walk the dir for .tpl files
        for (let i = 0; i < self.generatorSettings.files.length; i++) {
            // Create the object in charge of rendering the html
            const renderObject = new HtmlWriterFile({
                inputFile: self.generatorSettings.files[i] + '.tpl',
                outputFile: self.generatorSettings.outputDir + '/' + self.generatorSettings.files[i] + '.html',
                renderer: self.renderer
            });

            // ...
            renderObject.setHelpers(helpers);

            // Generate the html
            tasks.push(renderObject.render());
        }

        return Task.all(tasks);
    }
開發者ID:hrajchert,項目名稱:mddoc,代碼行數:26,代碼來源:custom-generator.ts

示例2: generate

    generate () {
        const self = this;
        const tasks: ReturnType<typeof writeFileCreateDir>[] = [];

        self.metadata.renderedFragments = {};

        // For each markdown, create the html fragment
        for (const mdTemplate in self.metadata.jsonml) {
            try {
                const tree = markdown.toHTMLTree(self.metadata.jsonml[mdTemplate]);
                const html = markdown.renderJsonML(tree);

                const outputFilename = self.generatorSettings.outputDir + '/' + mdTemplate + '.html';
                // mhmhmh TODO: This is sooo hardcoded
                self.metadata.renderedFragments[mdTemplate] = 'fragment/' + mdTemplate + '.html';

                tasks.push(writeFileCreateDir(outputFilename, html));

            } catch (e) {
                // TODO: Catch this better
                console.log(red('Problem with ') + mdTemplate);
                throw e;
            }
        }

        return Task.all(tasks);
    }
開發者ID:hrajchert,項目名稱:mddoc,代碼行數:27,代碼來源:html-fragment-generator.ts

示例3: render

 render () {
     const self = this;
     return Task.resolve(this)
         .map(({inputFile, helpers}) => this.renderer.render(inputFile, {mddoc: helpers}))
         .chain(html => writeFileCreateDir(self.outputFile, html))
         .map(tap(_ => console.log(green('We wrote ') + grey(self.outputFile))));
 }
開發者ID:hrajchert,項目名稱:mddoc,代碼行數:7,代碼來源:custom-generator.ts

示例4: mkdir

 .catch(err => {
     if (err.code === 'ENOENT') {
         return mkdir(path);
     } else {
         return Task.reject(err);
     }
 });
開發者ID:hrajchert,項目名稱:mddoc,代碼行數:7,代碼來源:write-file-create-dir.ts

示例5: taskReducer

 const loop = (index: number) => (curr: A): Task<A, E | UnknownError> => {
     if (index >= items.length) {
         return Task.resolve(curr);
     } else {
         return taskReducer(curr, items[index])
             .chain(loop(index + 1));
     }
 };
開發者ID:hrajchert,項目名稱:mddoc,代碼行數:8,代碼來源:task-reduce.ts

示例6: function

 return function (stat: fs.Stats) {
     // If its not a directory, resolve it on the spot with the name of the file
     if (!stat.isDirectory()) {
         return Task.resolve([filename]);
     }
     // If it is, resolve it once its subdirectory is resolved
     else {
         return doWalkDir(filename, options);
     }
 };
開發者ID:hrajchert,項目名稱:mddoc,代碼行數:10,代碼來源:walk-dir.ts

示例7: nextStep

export function sequence<E1> (steps: Step<E1>[]): Task<void, E1> {
    // clone the steps
    const newSteps = [...steps] as [Step<any>];
    // Remove the next step from the array
    const nextStep = newSteps.shift();
    // If there are any left, resolve inmediatly
    if (!nextStep) {
        return Task.resolve(void 0);
    } else {
        // If there is a step invoke it
        return nextStep().chain(
            () => sequence(newSteps)
        );
    }
}
開發者ID:hrajchert,項目名稱:mddoc,代碼行數:15,代碼來源:sequence.ts

示例8:

export function traverseDictionary<T, E> (objOfTasks: Dictionary<Task<T, E>>): Task<Dictionary<T>, UnknownError | E> {
    // Create an array of task with a tuple containing the key and the value
    const tasks =
        Object.keys(objOfTasks)
            .map(key => objOfTasks[key]
                        .map(value => ({key, value}))
            );
    // Wait until all tasks are resolved
    return Task.all(tasks)
                // And transform the array back into an object
                .map(pairs => {
                    const ans: Dictionary<T> = {};
                    pairs.forEach(({key, value}) => ans[key] = value);
                    return ans;
                });
}
開發者ID:hrajchert,項目名稱:mddoc,代碼行數:16,代碼來源:traverse-dictionary.ts

示例9:

        .chain(function (files) {
            const promises: ReturnType<typeof copyFile>[] = [];

            for (let i = 0; i < files.length; i++) {
                const m = files[i].match(matchRe);
                if (m) {
                    const inputFilename = files[i];
                    const outputFilename = dst + '/' + files[i].substr(dirNameLength + 1);
                    // console.log(inputFilename.grey + " => ".green + outputFilename.grey);

                    // Copy the file
                    promises.push(copyFile(inputFilename, outputFilename));
                }
            }
            return Task.all(promises);
        });
開發者ID:hrajchert,項目名稱:mddoc,代碼行數:16,代碼來源:copy-dir.ts


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