* chore(NA): first custom rules for jsts_transpiler * chore(NA): update jsts_transpiler macro * chore(NA): moving @elastic/datemath to babel transpiler * chore(NA): change gitignore rules for bazel Co-authored-by: Tiago Costa <tiagoffcc@hotmail.com>
This commit is contained in:
parent
cfa379fd68
commit
69d0a7aa30
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -82,6 +82,6 @@ report.asciidoc
|
|||
.yarn-local-mirror
|
||||
|
||||
# Bazel
|
||||
bazel
|
||||
bazel-*
|
||||
/bazel
|
||||
/bazel-*
|
||||
.bazelrc.user
|
||||
|
|
3
packages/elastic-datemath/.babelrc
Normal file
3
packages/elastic-datemath/.babelrc
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"presets": ["@kbn/babel-preset/node_preset"]
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
|
||||
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")
|
||||
load("//src/dev/bazel:index.bzl", "jsts_transpiler")
|
||||
|
||||
PKG_BASE_NAME = "elastic-datemath"
|
||||
PKG_REQUIRE_NAME = "@elastic/datemath"
|
||||
|
@ -20,15 +21,18 @@ NPM_MODULE_EXTRA_FILES = [
|
|||
"README.md",
|
||||
]
|
||||
|
||||
SRC_DEPS = [
|
||||
"@npm//moment",
|
||||
]
|
||||
|
||||
TYPES_DEPS = [
|
||||
"@npm//moment",
|
||||
"@npm//@types/node",
|
||||
]
|
||||
|
||||
DEPS = SRC_DEPS + TYPES_DEPS
|
||||
DEPS = TYPES_DEPS
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_node",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
|
@ -39,14 +43,15 @@ ts_config(
|
|||
)
|
||||
|
||||
ts_project(
|
||||
name = "tsc",
|
||||
name = "tsc_types",
|
||||
args = ['--pretty'],
|
||||
srcs = SRCS,
|
||||
deps = DEPS,
|
||||
declaration = True,
|
||||
declaration_map = True,
|
||||
incremental = True,
|
||||
out_dir = "target",
|
||||
emit_declaration_only = True,
|
||||
incremental = False,
|
||||
out_dir = "target_types",
|
||||
source_map = True,
|
||||
root_dir = "src",
|
||||
tsconfig = ":tsconfig",
|
||||
|
@ -55,7 +60,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = DEPS + [":tsc"],
|
||||
deps = DEPS + [":target_node", ":tsc_types"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
"version": "5.0.3",
|
||||
"description": "elasticsearch datemath parser, used in kibana",
|
||||
"license": "Apache-2.0",
|
||||
"main": "./target/index.js",
|
||||
"types": "./target/index.d.ts",
|
||||
"main": "./target_node/index.js",
|
||||
"types": "./target_types/index.d.ts",
|
||||
"peerDependencies": {
|
||||
"moment": "^2.24.0"
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"incremental": true,
|
||||
"outDir": "target",
|
||||
"emitDeclarationOnly": true,
|
||||
"incremental": false,
|
||||
"outDir": "target_types",
|
||||
"rootDir": "src",
|
||||
"sourceMap": true,
|
||||
"sourceRoot": "../../../../packages/elastic-datemath/src",
|
||||
|
|
1
src/dev/bazel/BUILD.bazel
Normal file
1
src/dev/bazel/BUILD.bazel
Normal file
|
@ -0,0 +1 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
15
src/dev/bazel/index.bzl
Normal file
15
src/dev/bazel/index.bzl
Normal file
|
@ -0,0 +1,15 @@
|
|||
#
|
||||
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License
|
||||
# 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
# in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
# Side Public License, v 1.
|
||||
#
|
||||
|
||||
"""Public API interface for Bazel custom rules.
|
||||
Please do not import from any other files when looking to use a custom rule
|
||||
"""
|
||||
|
||||
load("//src/dev/bazel:jsts_transpiler.bzl", _jsts_transpiler = "jsts_transpiler")
|
||||
|
||||
jsts_transpiler = _jsts_transpiler
|
36
src/dev/bazel/jsts_transpiler.bzl
Normal file
36
src/dev/bazel/jsts_transpiler.bzl
Normal file
|
@ -0,0 +1,36 @@
|
|||
"Simple wrapper over @babel/cli so we can quickly re-use the same configurations over packages"
|
||||
|
||||
load("@npm//@babel/cli:index.bzl", _babel = "babel")
|
||||
|
||||
def jsts_transpiler(name, srcs, build_pkg_name, root_input_dir = "src", config_file = ".babelrc", additional_args = ["--quiet"], **kwargs):
|
||||
"""A macro around the autogenerated babel rule.
|
||||
|
||||
Args:
|
||||
name: target name
|
||||
srcs: list of sources
|
||||
root_input_dir: defines the root input dir to transpile files from, defaults to "src"
|
||||
config_file: transpiler config file, it defaults to a package local .babelrc
|
||||
additional_args: Any additional extra arguments, defaults to --quiet
|
||||
**kwargs: the rest
|
||||
"""
|
||||
args = [
|
||||
"./%s/%s" % (build_pkg_name, root_input_dir),
|
||||
"--config-file",
|
||||
"./%s/%s" % (build_pkg_name, config_file),
|
||||
"--out-dir",
|
||||
"$(@D)",
|
||||
"--extensions",
|
||||
".ts,.tsx,.js",
|
||||
] + additional_args
|
||||
|
||||
data = [config_file] + srcs + [
|
||||
"//packages/kbn-babel-preset",
|
||||
]
|
||||
|
||||
_babel(
|
||||
name = name,
|
||||
data = data,
|
||||
output_dir = True,
|
||||
args = args,
|
||||
**kwargs
|
||||
)
|
Loading…
Reference in a new issue