npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

closure-tools-helper

v1.0.0

Published

Provides utility functionalities to call closure tools in nodejs.

Downloads

12

Readme

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