Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ jobs:
- *restore_cache
- *copy_bazel_config

# TODO(jelbourn): Update this command to run all tests if the Bazel issues have been fixed.
- run: bazel build src/...
- run: bazel test src/...
Copy link
Member Author

@devversion devversion Nov 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I don't want to build everything that is also outside of src. Running with //... seems to break our CI build, so I'll try to revisit that in a follow-up


Expand Down
8 changes: 8 additions & 0 deletions guides/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package(default_visibility=["//visibility:public"])

load("//tools/markdown-to-html:index.bzl", "markdown_to_html")

markdown_to_html(
name = "guides",
srcs = glob(["**/*.md"]),
)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"karma-sauce-launcher": "^1.2.0",
"karma-sourcemap-loader": "^0.3.7",
"magic-string": "^0.22.4",
"marked": "^0.5.1",
"minimatch": "^3.0.4",
"minimist": "^1.2.0",
"mock-fs": "^4.7.0",
Expand Down
24 changes: 24 additions & 0 deletions tools/markdown-to-html/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package(default_visibility = ["//visibility:public"])

load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "transform-markdown",
srcs = [":transform-markdown.ts"],
deps = ["@matdeps//@types/node"],
tsconfig = ":tsconfig.json",
)

nodejs_binary(
name = "markdown-to-html",
entry_point = "angular_material/tools/markdown-to-html/transform-markdown.js",
data = [
"@matdeps//highlight.js",
"@matdeps//marked",
"@matdeps//source-map-support",
":transform-markdown",
],
)


48 changes: 48 additions & 0 deletions tools/markdown-to-html/index.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Implementation of the "markdown_to_html" rule. The implementation runs the transform
executable in order to create the outputs for the specified source files.
"""
def _markdown_to_html(ctx):
input_files = ctx.files.srcs;
args = ctx.actions.args()
expected_outputs = [];

for input_file in input_files:
basename = input_file.basename.replace('.md', '')
output_file = ctx.actions.declare_file("%s.html" % basename)
expected_outputs += [output_file]

# Add the input file and it's related output to the arguments that
# will be passed to the transformer executable.
args.add("%s=%s" % (input_file.path, output_file.path))

# Run the transform markdown executable that transforms the specified source files.
# Note that we should specify the outputs here because Bazel can then throw an error
# if the script didn't generate the required outputs.
ctx.actions.run(
inputs = input_files,
executable = ctx.executable._transform_markdown,
outputs = expected_outputs,
arguments = [args],
)

return DefaultInfo(files = depset(expected_outputs))

"""
Rule definition for the "markdown_to_html" rule that can accept arbritary source files
that will be transformed into HTML files. The outputs can be referenced through the
default output provider.
"""
markdown_to_html = rule(
implementation = _markdown_to_html,
attrs = {
"srcs": attr.label_list(allow_files = [".md"]),

# Executable for this rule that is responsible for converting the specified
# markdown files into HTML files.
"_transform_markdown": attr.label(
default = Label("//tools/markdown-to-html"),
executable = True,
cfg = "host"
)},
)
37 changes: 37 additions & 0 deletions tools/markdown-to-html/transform-markdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Script that will be used by the markdown_to_html Bazel rule in order to transform
* multiple markdown files into the equivalent HTML output.
*/

import {readFileSync, writeFileSync} from 'fs';

// These types lack type definitions.
const marked = require('marked');
const highlightJs = require('highlight.js');

// Setup the default options for converting markdown to HTML.
marked.setOptions({
// Implement a highlight function that converts the code block into a highlighted
// HTML snippet that uses HighlightJS.
highlight: (code: string, language: string): string => {
if (language) {
return highlightJs.highlight(
language.toLowerCase() === 'ts' ? 'typescript' : language, code).value;
}
return code;
}
});

if (require.main === module) {
// The script expects the input files to be specified in the following format:
// {input_file_path}={output_file_path}
// We have to know the output paths because the input path and output path differ
// fundamentally within the Bazel sandbox.
const inputFiles = process.argv.slice(2).map(argument => argument.split('='));

// Walk through each input file and write transformed markdown output to the specified
// output path.
inputFiles.forEach(([inputPath, outputPath]) => {
writeFileSync(outputPath, marked(readFileSync(inputPath, 'utf8')));
});
}
12 changes: 12 additions & 0 deletions tools/markdown-to-html/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"lib": ["es2015"],
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"types": ["node"]
},
"bazelOptions": {
"suppressTsconfigOverrideWarnings": true
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7469,6 +7469,11 @@ marked@^0.3.2:
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.19.tgz#5d47f709c4c9fc3c216b6d46127280f40b39d790"
integrity sha512-ea2eGWOqNxPcXv8dyERdSr/6FmzvWwzjMxpfGB/sbMccXoct+xY+YukPD+QTUZwyvK7BZwcr4m21WBOW41pAkg==

marked@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/marked/-/marked-0.5.1.tgz#062f43b88b02ee80901e8e8d8e6a620ddb3aa752"
integrity sha512-iUkBZegCZou4AdwbKTwSW/lNDcz5OuRSl3qdcl31Ia0B2QPG0Jn+tKblh/9/eP9/6+4h27vpoh8wel/vQOV0vw==

matchdep@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/matchdep/-/matchdep-2.0.0.tgz#c6f34834a0d8dbc3b37c27ee8bbcb27c7775582e"
Expand Down