-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stylus): add initial stylus rule
- Loading branch information
Showing
14 changed files
with
312 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ module.exports = { | |
'karma', | ||
'labs', | ||
'protractor', | ||
'stylus', | ||
'rollup', | ||
'typescript', | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2017 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package") | ||
|
||
# Copy the license from our parent folder | ||
genrule( | ||
name = "copy_LICENSE", | ||
srcs = ["@build_bazel_rules_nodejs//:LICENSE"], | ||
outs = ["LICENSE"], | ||
cmd = "cp $< $@", | ||
) | ||
|
||
# Ugly genrule depending on local linux environment to build the README out of skylark doc generation. | ||
# Only referenced when we do a release. | ||
# TODO: This ought to be possible with stardoc alone. Need to coordinate with Chris Parsons. | ||
genrule( | ||
name = "generate_README", | ||
srcs = [ | ||
"//packages/stylus/docs:index.md", | ||
"//packages/stylus/docs:install.md", | ||
], | ||
outs = ["README.md"], | ||
cmd = """cat $(location //packages/stylus/docs:install.md) $(location //packages/stylus/docs:index.md) | sed 's/^##/\\\n##/' > $@""", | ||
) | ||
|
||
npm_package( | ||
name = "npm_package", | ||
srcs = [ | ||
"@npm_bazel_stylus//:package_contents", | ||
], | ||
vendor_external = [ | ||
"npm_bazel_stylus", | ||
], | ||
deps = [ | ||
":copy_LICENSE", | ||
":generate_README", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2019 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@io_bazel_skydoc//stardoc:stardoc.bzl", "stardoc") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
exports_files(["install.md"]) | ||
|
||
stardoc( | ||
name = "docs", | ||
testonly = True, | ||
out = "index.md", | ||
input = "@npm_bazel_stylus//:index.bzl", | ||
deps = [ | ||
"@npm_bazel_stylus//:bzl", | ||
# We need to restate local workspace dependencies here in `//foo:bzl` | ||
# format to work-around a bug in stardoc where .bzl files from | ||
# `@build_bazel_rules_nodejs//foo:bzl` style deps are not found | ||
# by the doc generator: | ||
# ``` | ||
# ``` | ||
"//:bzl", | ||
"//internal/common:bzl", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Stylus rules for Bazel | ||
|
||
**WARNING: this is beta-quality software. Breaking changes are likely. Not recommended for production use without expert support.** | ||
|
||
The Stylus rules run the Stylus CSS preprocessor with Bazel. | ||
|
||
## Installation | ||
|
||
Add the `@bazel/stylus` npm package to your `devDependencies` in `package.json`. | ||
|
||
Your `WORKSPACE` should declare a `yarn_install` or `npm_install` rule named `npm`. | ||
It should then install the rules found in the npm packages using the `install_bazel_dependencies' function. | ||
See https://github.com/bazelbuild/rules_nodejs/#quickstart | ||
|
||
This causes the `@bazel/stylus` package to be installed as a Bazel workspace named `npm_bazel_stylus`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2018 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("@npm_bazel_typescript//:defaults.bzl", "ts_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
bzl_library( | ||
name = "bzl", | ||
testonly = True, | ||
srcs = glob(["*.bzl"]), | ||
deps = [ | ||
"@build_bazel_rules_nodejs//:bzl", | ||
"@build_bazel_rules_nodejs//internal/common:bzl", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "package_contents", | ||
srcs = [ | ||
"index.bzl", | ||
"package.json", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2019 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
workspace(name = "npm_bazel_stylus") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Support running the stylus processor as a Bazel rule. | ||
""" | ||
|
||
def _stylus_binary(ctx): | ||
src = ctx.file.src | ||
|
||
# We want foo.styl to produce foo.css | ||
output = ctx.actions.declare_file(src.basename[:-5] + ".css") | ||
ctx.actions.run( | ||
outputs = [output], | ||
inputs = [src], | ||
executable = ctx.executable._compiler, | ||
arguments = [ | ||
"--out", | ||
ctx.bin_dir.path + "/" + ctx.label.package, | ||
src.path, | ||
], | ||
) | ||
return [ | ||
DefaultInfo(files = depset([output])), | ||
] | ||
|
||
stylus_binary = rule( | ||
implementation = _stylus_binary, | ||
attrs = { | ||
"src": attr.label( | ||
mandatory = True, | ||
allow_single_file = True, | ||
), | ||
"_compiler": attr.label( | ||
default = Label("@npm//stylus/bin:stylus"), | ||
cfg = "host", | ||
executable = True, | ||
), | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@bazel/stylus", | ||
"dependencies": { | ||
"stylus": "~0.54.5" | ||
}, | ||
"description": "Run Stylus CSS preprocessor under Bazel", | ||
"license": "Apache-2.0", | ||
"version": "0.0.0-PLACEHOLDER", | ||
"repository": { | ||
"type" : "git", | ||
"url" : "https://github.com/bazelbuild/rules_nodejs.git", | ||
"directory": "packages/stylus" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/bazelbuild/rules_nodejs/issues" | ||
}, | ||
"keywords": [ | ||
"stylus", | ||
"bazel" | ||
], | ||
"bazelWorkspaces": { | ||
"npm_bazel_stylus": { | ||
"rootPath": "." | ||
} | ||
}, | ||
"scripts": { | ||
"test": "bazel test //..." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load("@npm_bazel_stylus//:index.bzl", "stylus_binary") | ||
|
||
stylus_binary( | ||
name = "styles", | ||
src = "file.styl", | ||
) | ||
|
||
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test") | ||
|
||
nodejs_test( | ||
name = "test", | ||
data = [ | ||
"stylus_binary_spec.js", | ||
":styles", | ||
], | ||
entry_point = ":stylus_binary_spec.js", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
body { | ||
font: 14px/1.5 Helvetica, arial, sans-serif; | ||
#logo { | ||
border-radius: 5px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
console.log(process.cwd()); | ||
const cssPath = require.resolve('build_bazel_rules_nodejs/packages/stylus/test/file.css'); | ||
const content = require('fs').readFileSync(cssPath, {encoding: 'utf-8'}); | ||
if (content.indexOf('body #logo') < 0) { | ||
console.error('Expected the css file to be transformed'); | ||
process.exitCode = 1; | ||
} |
Oops, something went wrong.