closure-tools-helper
Provides utility functionalities to call closure tools in nodejs.
Last updated a year ago by theseanl .
LGPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install closure-tools-helper 
SYNC missed versions from official npm registry.

Closure Tools Helper

This module contains closure tools compiled jars and various helper function to make dependency management easier.

This module exports 4 functions:

const closureTools = require('closure-tools-helper');

closureTools.compiler(...);
closureTools.templates(...);
closureTools.stylesheets(...);
closuretools.extractTemplateMsg(...);

Closure Compiler api

The closure compiler api abstracts the module system of closure compiler to something based on entry points, much similar to rollup.

(await closureTools.compiler(baseCompilerFlags, sourceGlob, entryPoints)).src()
    .pipe(...)

Note the requirements of await, due to building compiler flag being an async operation. The plugin controls --module and -js compiler flags. All the other flags must be provided with baseCompilerFlags argument.

sourceGlob is a glob pattern that provides js sources to the compiler. All files referenced by entryPoints must be provided by the glob.

entryPoints is an array where each element follows the below interface.

interface ICompilerEntryPoint {
    /**
     * This is what is used in `goog.require()`.
     * `null` means there is no entry module, but it can have some extraSources.
     */
    id:string|null,
    /**
     * module name, used in specifying dependencies, and also used in output file name.
     */
    name:string,
    /**
     * Array of module names that this bundle depends on.
     */
    deps:string[],
    /**
     * Any files that are not reachable via `goog.require`s but still need to be provided
     * to the compiler.
     */
    extraSources?:string[]
}

Closure Templates api

const compiler = require('closure-tools-helper');

gulp.task('build-soy', () => {
    return compiler.templates([.../* Command line args passed to SoyToJsSrcCompiler.jar */])
        .src()
        .pipe(gulp.dest('build'));
});

gulp.task('extract-soy-messages', () => {
    return compiler.extractTemplateMsg([.../* Command line args passed to SoyMsgExtractor.jar */])
        .src();
});

Compiler apis returns a readable stream of the stdout. Users of the package should explicitly call .src() in order to turn the stream into flowing mode (same as google-closure-compiler gulp plugin).

Runtime i18n

Closure templates by default supports compile-time i18n. Provide a second argument TemplatesI18nOptions to post-process js files generated by soy compiler to enable i18n. Its interface is what follows:

interface ITemplatesI18nOptions {
    /**
     * This is a string to replace `goog.getMsg` with.
     */
    googGetMsg:string
    /**
     * This is a string that will be appended right after the `goog.module(..)` expression.
     */
    header?:string
    /**
     * This must match files generated by the compiler jar.
     */
    inputGlob:string|string[]
    outputPath?:string // If provided, files will be written to `outputPath/fileName`.
}

If runtime i18n is enabled, it will additionally transform legacy-style goog.provide modules into goog.module, so that a consumer can import the compiled templates by using const templates = goog.require('namespace.to.the.template'), or import templates from 'goog:namespace.to.the.template' if the consumer is using tsickle.

SoyUtils

Import or reference ./third-party/soyutils.js or ./third-party/soyutils_usegoog.js.

Closure Stylesheets api

const compiler = require('closure-tools-helper');

gulp.task('build-gss', () => {
    return compiler.stylesheets([.../* Command line args passed to closure-stylesheets.jar */])
        .src()
})

Compiler apis returns a readable stream of the stdout. User of the package should explicitly call .src() to turn the stream into a flowing mode.

Installation

yarn add https://github.com/seanl-adg/closure-tools-helper.git
yarn add https://github.com/seanl-adg/closure-tools-helper.git#<specific-tag>

Build

tsc

Current Tags

  • 1.0.0                                ...           latest (a year ago)

1 Versions

  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (9)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |