forked from bazelbuild/rules_postcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TypeScript dependencies and copy of example plugin (bazelbuild#7)
- Loading branch information
Showing
9 changed files
with
315 additions
and
11 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
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,62 @@ | ||
# Copyright 2019 The Bazel Authors | ||
# | ||
# 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 | ||
# | ||
# https://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_rules_sass//:defs.bzl", "sass_binary") | ||
load("@npm_bazel_typescript//:index.bzl", "ts_library") | ||
load("//:defs.bzl", "postcss_binary", "postcss_plugin") | ||
|
||
package(default_visibility = ["//tests:__subpackages__"]) | ||
|
||
AUTO_PREFIXER_BROWSERS = "ie >= 9, edge >= 12, firefox >= 42, chrome >= 32, safari >= 8, opera >= 38, ios_saf >= 9.2, android >= 4.3, and_uc >= 9.9" | ||
|
||
ts_library( | ||
name = "unquote_ts", | ||
srcs = ["unquote.ts"], | ||
deps = [ | ||
"@npm//@types", | ||
"@npm//postcss", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "unquote_js", | ||
srcs = [":unquote_ts"], | ||
output_group = "es5_sources", | ||
) | ||
|
||
postcss_plugin( | ||
name = "unquote", | ||
srcs = [ | ||
":unquote_js", | ||
], | ||
) | ||
|
||
sass_binary( | ||
name = "style", | ||
src = "style.scss", | ||
output_style = "expanded", | ||
) | ||
|
||
postcss_binary( | ||
name = "style_processed", | ||
src = ":style", | ||
plugins = { | ||
"autoprefixer": "[{ browsers: '%s' }]" % AUTO_PREFIXER_BROWSERS, | ||
"build_bazel_rules_postcss/examples/custom_plugin_ts/unquote.js": "", | ||
}, | ||
deps = [ | ||
":unquote", | ||
"@npm//autoprefixer", | ||
], | ||
) |
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,12 @@ | ||
@function mediaSafe($expr) { | ||
@return unquote('unquote("' + $expr + '")'); | ||
} | ||
|
||
$sidebar-max-width-toggleable: 42px; | ||
|
||
@media screen and (max-width: mediaSafe($sidebar-max-width-toggleable)) { | ||
body { | ||
font: 42px 'Comic Sans MS'; | ||
flex: 42 -42 auto; | ||
} | ||
} |
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,47 @@ | ||
/** | ||
* Copyright 2019 The Bazel Authors | ||
* | ||
* 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
/** | ||
* @fileoverview Example PostCSS plugin that introduces an "unquote" function | ||
* to stylesheets. | ||
*/ | ||
|
||
import * as postcss from 'postcss'; | ||
|
||
// Replaces all "unquote('hello')" found with "hello", supporting | ||
// both ' and ". Doesn't do quote escaping. | ||
module.exports = postcss.plugin('unquote', () => { | ||
/** | ||
* Unquote implementation. http://stackoverflow.com/a/19584742 | ||
* @param str | ||
* @return The string with unquote instances handled. | ||
*/ | ||
const unquoteStr = (str: string) => { | ||
if (str.indexOf('unquote(') !== -1) { | ||
return str.replace(/unquote\((["'])(.+?)\1\)/g, '$2'); | ||
} | ||
return str; | ||
}; | ||
|
||
return (css: postcss.Root) => { | ||
// Handle declaration values in rules. | ||
css.walkRules(rule => { | ||
rule.walkDecls((decl, i) => decl.value = unquoteStr(decl.value)); | ||
}); | ||
// Handle params in @rules. | ||
css.walkAtRules(rule => rule.params = unquoteStr(rule.params)); | ||
}; | ||
}); |
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
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,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": [ | ||
"es5", | ||
"es6", | ||
"es2015.collection", | ||
"es2015.iterable", | ||
"es2015.core", | ||
"dom" | ||
], | ||
"types": [ | ||
"node" | ||
], | ||
"target": "es2015", | ||
"strict": true | ||
}, | ||
"include": [ | ||
"examples/*.ts", | ||
] | ||
} |
Oops, something went wrong.