Skip to content

Commit ec82a20

Browse files
committed
Add a stub client lib
1 parent dc32c9a commit ec82a20

File tree

5 files changed

+79
-4
lines changed

5 files changed

+79
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
lib/**/*
2+
lib_client/**/*
23
node_modules/
34
*.tgz
45
testdata/*/output

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
"bin": {
1313
"lit-localize": "bin/lit-localize.js"
1414
},
15+
"main": "lib_client/index.js",
1516
"scripts": {
16-
"clean": "rimraf 'lib/*' 'lib/.*' 'testdata/*/output'",
17-
"build": "npm run clean && npm run generate-json-schema && tsc",
17+
"clean": "rimraf 'lib/*' 'lib/.*' 'lib_client/*' 'lib_client/.*' 'testdata/*/output'",
18+
"build": "npm run clean && npm run generate-json-schema && tsc && tsc --project tsconfig.client.json",
1819
"generate-json-schema": "typescript-json-schema tsconfig.schema.json ConfigFile --include=src/config.ts --required --noExtraProps > config.schema.json",
1920
"test": "npm run build && ava --verbose && npm run test:check-tsc && npm run test:check-eslint",
2021
"test:update-goldens": "npm run build && UPDATE_TEST_GOLDENS=true ava --verbose",
2122
"test:check-tsc": "ls testdata/*/output/tsconfig.json | xargs -n 1 tsc --noEmit --project",
2223
"test:check-eslint": "eslint 'testdata/*/output/*.ts' 'testdata/*/output/**/*.ts' --max-warnings 0",
23-
"lint": "eslint 'src/*.ts' 'src/**/*.ts' --max-warnings 0",
24-
"prettier": "prettier 'src/**/*.ts'",
24+
"lint": "eslint 'src/*.ts' 'src/**/*.ts' 'src_client/*.ts' 'src_client/**/*.ts' --max-warnings 0",
25+
"prettier": "prettier 'src/**/*.ts' 'src_client/**/*.ts'",
2526
"format:check": "npm run prettier -- --check",
2627
"format": "npm run prettier -- --write",
2728
"watch": "scripts/watch.sh",

scripts/watch.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ trap "kill 0" EXIT
77

88
npm run clean
99
npx tsc --watch --noEmitOnError &
10+
npx tsc --watch --noEmitOnError --project tsconfig.client.json &
1011
npx chokidar "src/**/*.ts" .eslintrc.json -c "npm run lint" &
1112
npx chokidar "src/config.ts" -c "npm run generate-json-schema" &
1213

src_client/index.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2020 The Polymer Project Authors. All rights reserved.
4+
* This code may only be used under the BSD style license found at
5+
* http://polymer.github.io/LICENSE.txt The complete set of authors may be found
6+
* at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
7+
* be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
8+
* Google as part of the polymer project is also subject to an additional IP
9+
* rights grant found at http://polymer.github.io/PATENTS.txt
10+
*/
11+
12+
import {TemplateResult} from 'lit-html';
13+
14+
/* eslint-disable @typescript-eslint/no-explicit-any */
15+
16+
export function msg(id: string, template: string): string;
17+
18+
export function msg(id: string, template: TemplateResult): TemplateResult;
19+
20+
export function msg<F extends (...args: any[]) => string>(
21+
id: string,
22+
fn: F,
23+
...params: Parameters<F>
24+
): string;
25+
26+
export function msg<F extends (...args: any[]) => TemplateResult>(
27+
id: string,
28+
fn: F,
29+
...params: Parameters<F>
30+
): TemplateResult;
31+
32+
/**
33+
* TODO(aomarks) This is a temporary stub implementation of the msg function. It
34+
* does not yet support actual localization, and is only used by the "transform"
35+
* output mode, since the user needs something to import.
36+
*
37+
* It may actually make more sense to move most of the generated code from
38+
* "runtime" mode into this library, so that users can
39+
* `import {msg} from 'lit-localize'` and tell it where to fetch translation
40+
* (this will make more sense after the planned revamp to support runtime async
41+
* locale loading and re-rendering).
42+
*/
43+
export function msg(
44+
_id: string,
45+
template: string | TemplateResult | (() => string | TemplateResult),
46+
...params: any[]
47+
): string | TemplateResult {
48+
if (typeof template === 'function') {
49+
return (template as any)(...params);
50+
}
51+
return template;
52+
}

tsconfig.client.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "esnext",
5+
"moduleResolution": "node",
6+
"lib": ["es2018", "DOM"],
7+
"strict": true,
8+
"noUnusedLocals": true,
9+
"noUnusedParameters": true,
10+
"preserveConstEnums": true,
11+
"forceConsistentCasingInFileNames": true,
12+
"rootDir": "src_client/",
13+
"outDir": "lib_client/",
14+
"declaration": true,
15+
"sourceMap": true,
16+
"incremental": true,
17+
"tsBuildInfoFile": "lib_client/.tsbuildinfo"
18+
},
19+
"include": ["src_client/**/*"]
20+
}

0 commit comments

Comments
 (0)