1.0.1 • Published 4 years ago

closure-stylesheets v1.0.1

Weekly downloads
4
License
AGPL-3.0
Repository
github
Last release
4 years ago

closure-stylesheets

npm version

closure-stylesheets is A Node API to Closure Stylesheets.

yarn add closure-stylesheets

Table Of Contents

API

The package is available by importing its default function:

import closureStylesheets, { closureStylesheetsSync } from 'closure-stylesheets'

async compileStylesheets(  css: (string|!Array<string>),  config: !ClosureStylesheetsConfig,  log=: !Function,): ClosureReturn

Compiles stylesheets asynchronously.

  • css* (string | !Array<string>): The resolved path to the CSS file to compile.
  • config* !ClosureStylesheetsConfig: Additional configuration to transform into arguments to Java. Requires at list path to the JAR file.
  • log !Function (optional): The logging function.

ClosureStylesheetsConfig: Configuration options.

ClosureReturn: Returns stylesheet and rename map if successful, or parsed info, stderr and status otherwise.

For example, we can compile this simple stylesheet:

.MyElement {
  color: green;
}
import compileStylesheets from 'closure-stylesheets'
import path from 'closure-stylesheets-java'

(async () => {
  const res = await compileStylesheets('example/style.css', {
    path,
    rootSelector: '.Example',
  }, console.error)
  console.log(res)
})()
{
  renameMap: { MyElement: 'a' },
  stylesheet: '.Example .a{color:green}'
}

Logging of the executed command will be done into console.error since it was passed as the third argument.

java -jar /Users/zavr/node_modules/closure-stylesheets-java/target/closure-stylesheets-1.12.1-SNAPSHOT-jar-with-dependencies.jar "example/style.css" --root-selector .Example --output-renaming-map temp-rename-map.json --output-renaming-map-format JSON --rename SIMPLE

The sync version with the same API is also available.

compileStylesheetsSync(  css: (string|!Array<string>),  config: !ClosureStylesheetsConfig,  log=: !Function,): ClosureReturn

Compiles stylesheets in a sync manner.

  • css* (string | !Array<string>): The resolved path to the CSS file to compile.
  • config* !ClosureStylesheetsConfig: Additional configuration to transform into arguments to Java. Requires at list path to the JAR file.
  • log !Function (optional): The logging function.
import { compileStylesheetsSync } from 'closure-stylesheets'
import path from 'closure-stylesheets-java'

const resSync = compileStylesheetsSync('example/style.css', {
  path,
  rootSelector: '.HelloWorld',
  whitelist: ['MyElement'],
}, console.error)
console.log(resSync)
{ renameMap: {}, stylesheet: '.HelloWorld .MyElement{color:green}' }

Copyright