From 4083f168480eb8a215ce86c91198d980bf939697 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sun, 3 Oct 2021 22:59:39 +0200 Subject: [PATCH] Create own directory for i18n --- ts/.prettierignore | 4 +- ts/lib/BUILD.bazel | 58 ++++++++++++--------- ts/lib/genfluent.py | 2 +- ts/lib/i18n-modules.ts | 1 - ts/lib/i18n-translate.ts | 1 - ts/lib/{i18n-bundles.ts => i18n/bundles.ts} | 0 ts/lib/i18n/index.ts | 3 ++ ts/lib/i18n/modules.ts | 1 + ts/lib/i18n/translate.ts | 1 + ts/lib/{i18n.ts => i18n/utils.ts} | 7 +-- ts/lib/tsconfig.json | 2 +- ts/typescript.bzl | 3 +- 12 files changed, 47 insertions(+), 36 deletions(-) delete mode 120000 ts/lib/i18n-modules.ts delete mode 120000 ts/lib/i18n-translate.ts rename ts/lib/{i18n-bundles.ts => i18n/bundles.ts} (100%) create mode 100644 ts/lib/i18n/index.ts create mode 120000 ts/lib/i18n/modules.ts create mode 120000 ts/lib/i18n/translate.ts rename ts/lib/{i18n.ts => i18n/utils.ts} (91%) diff --git a/ts/.prettierignore b/ts/.prettierignore index 74bfe61c1..559e142e9 100644 --- a/ts/.prettierignore +++ b/ts/.prettierignore @@ -1,5 +1,5 @@ licenses.json vendor -i18n-translate.ts -i18n-modules.ts +lib/i18n/translate.ts +lib/i18n/modules.ts backend_proto.d.ts diff --git a/ts/lib/BUILD.bazel b/ts/lib/BUILD.bazel index 19d0b493a..8e7de8ccb 100644 --- a/ts/lib/BUILD.bazel +++ b/ts/lib/BUILD.bazel @@ -1,26 +1,11 @@ +load("@rules_python//python:defs.bzl", "py_binary") load("//ts:prettier.bzl", "prettier_test") load("//ts:eslint.bzl", "eslint_test") load("//ts:protobuf.bzl", "protobufjs_library") load("//ts:typescript.bzl", "typescript") -load("@rules_python//python:defs.bzl", "py_binary") load("@py_deps//:requirements.bzl", "requirement") load("//ts:jest.bzl", "jest_test") -_i18n_files = [ - "i18n-translate.ts", - "i18n-modules.ts", -] - -_generated = _i18n_files + [ - "backend_proto.d.ts", -] - -protobufjs_library( - name = "backend_proto", - proto = "//proto:backend_proto_lib", - visibility = ["//visibility:public"], -) - py_binary( name = "genfluent", srcs = [ @@ -31,10 +16,14 @@ py_binary( requirement("stringcase"), ], ) +_i18n_generated = [ + "i18n/translate.ts", + "i18n/modules.ts", +] genrule( name = "fluent_gen", - outs = _i18n_files, + outs = _i18n_generated, cmd = "$(location genfluent) $(location //rslib/i18n:strings.json) $(OUTS)", tools = [ "genfluent", @@ -42,13 +31,24 @@ genrule( ], ) +protobufjs_library( + name = "backend_proto", + proto = "//proto:backend_proto_lib", + visibility = ["//visibility:public"], +) + +_generated = [ + "backend_proto.d.ts", +] + _i18n_generated + typescript( name = "lib", - srcs = glob( - ["*.ts"], - exclude = _generated, - ), - generated = [":" + file for file in _generated], + exclude = _generated, + generated = [ + ":backend_proto.d.ts", + ":i18n/translate.ts", + ":i18n/modules.ts", + ], deps = [ ":backend_proto", "@npm//@fluent/bundle", @@ -63,9 +63,19 @@ typescript( # Tests ################ -prettier_test(exclude = _generated) +prettier_test( + srcs = glob( + ["**/*.ts"], + exclude = _generated, + ), +) -eslint_test(exclude = _generated) +eslint_test( + srcs = glob( + ["**/*.ts"], + exclude = _generated, + ), +) jest_test( deps = [ diff --git a/ts/lib/genfluent.py b/ts/lib/genfluent.py index bdbf779e6..568a440ba 100644 --- a/ts/lib/genfluent.py +++ b/ts/lib/genfluent.py @@ -17,7 +17,7 @@ class Variable(TypedDict): def methods() -> str: - out = [ 'import { translate } from "./i18n-bundles";' ] + out = [ 'import { translate } from "./bundles";' ] for module in modules: for translation in module["translations"]: key = stringcase.camelcase(translation["key"].replace("-", "_")) diff --git a/ts/lib/i18n-modules.ts b/ts/lib/i18n-modules.ts deleted file mode 120000 index 4255166e6..000000000 --- a/ts/lib/i18n-modules.ts +++ /dev/null @@ -1 +0,0 @@ -../../bazel-bin/ts/lib/i18n-modules.ts \ No newline at end of file diff --git a/ts/lib/i18n-translate.ts b/ts/lib/i18n-translate.ts deleted file mode 120000 index 960a367e6..000000000 --- a/ts/lib/i18n-translate.ts +++ /dev/null @@ -1 +0,0 @@ -../../bazel-bin/ts/lib/i18n-translate.ts \ No newline at end of file diff --git a/ts/lib/i18n-bundles.ts b/ts/lib/i18n/bundles.ts similarity index 100% rename from ts/lib/i18n-bundles.ts rename to ts/lib/i18n/bundles.ts diff --git a/ts/lib/i18n/index.ts b/ts/lib/i18n/index.ts new file mode 100644 index 000000000..37eb7abd9 --- /dev/null +++ b/ts/lib/i18n/index.ts @@ -0,0 +1,3 @@ +export * from "./utils"; +export * as tr from "./translate"; +export { ModuleName } from "./modules"; diff --git a/ts/lib/i18n/modules.ts b/ts/lib/i18n/modules.ts new file mode 120000 index 000000000..4a9d825e8 --- /dev/null +++ b/ts/lib/i18n/modules.ts @@ -0,0 +1 @@ +../../../bazel-bin/ts/lib/i18n/modules.ts \ No newline at end of file diff --git a/ts/lib/i18n/translate.ts b/ts/lib/i18n/translate.ts new file mode 120000 index 000000000..d3982da39 --- /dev/null +++ b/ts/lib/i18n/translate.ts @@ -0,0 +1 @@ +../../../bazel-bin/ts/lib/i18n/translate.ts \ No newline at end of file diff --git a/ts/lib/i18n.ts b/ts/lib/i18n/utils.ts similarity index 91% rename from ts/lib/i18n.ts rename to ts/lib/i18n/utils.ts index d3bcd692c..18295a50d 100644 --- a/ts/lib/i18n.ts +++ b/ts/lib/i18n/utils.ts @@ -4,8 +4,8 @@ import "intl-pluralrules"; import { FluentBundle, FluentResource } from "@fluent/bundle"; -import { firstLanguage, setBundles } from "./i18n-bundles"; -import type { ModuleName } from "./i18n-modules"; +import { firstLanguage, setBundles } from "./bundles"; +import type { ModuleName } from "./modules"; export function supportsVerticalText(): boolean { const firstLang = firstLanguage(); @@ -79,6 +79,3 @@ export async function setupI18n(args: { modules: ModuleName[] }): Promise setBundles(...newBundles); langs.splice(0, langs.length, ...json.langs); } - -export { ModuleName } from "./i18n-modules"; -export * as tr from "./i18n-translate"; diff --git a/ts/lib/tsconfig.json b/ts/lib/tsconfig.json index 587e87472..39f73a570 100644 --- a/ts/lib/tsconfig.json +++ b/ts/lib/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.json", - "include": ["*"], + "include": ["*", "i18n/*"], "references": [], "compilerOptions": { "types": ["jest"] diff --git a/ts/typescript.bzl b/ts/typescript.bzl index 26dce9894..69ecadc09 100644 --- a/ts/typescript.bzl +++ b/ts/typescript.bzl @@ -4,12 +4,13 @@ load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "js_library") def typescript( name, srcs = None, + exclude = [], generated = [], tsconfig = "tsconfig.json", visibility = ["//visibility:public"], **kwargs): if not srcs: - srcs = native.glob(["**/*.ts"]) + srcs = native.glob(["**/*.ts"], exclude = exclude) # all tsconfig files must be in the bazel-out folder copy_to_bin(