Skip to content

Commit 0ef97ef

Browse files
committed
public vars is now a TS file
1 parent 0e2a9a0 commit 0ef97ef

File tree

7 files changed

+19
-31
lines changed

7 files changed

+19
-31
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ WORKDIR /usr/src/app
2323
# to execute the final Eleventy build step.
2424

2525
# External dependencies
26-
COPY public-vars.json package*.json tsconfig.base.json ./
26+
COPY package*.json tsconfig.base.json ./
2727
COPY packages/lit-dev-tools-cjs/package*.json ./packages/lit-dev-tools-cjs/
2828
COPY packages/lit-dev-tools-esm/package*.json ./packages/lit-dev-tools-esm/
2929
COPY packages/lit-dev-server/package*.json ./packages/lit-dev-server/

packages/lit-dev-content/.eleventy.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,9 @@ ${content}
451451
return `<script type="module">${script}</script>`;
452452
});
453453

454-
eleventyConfig.addShortcode('algoliaid', () => {
455-
const varsRaw = fsSync.readFileSync('../../public-vars.json', 'utf8');
456-
const vars = JSON.parse(varsRaw);
457-
return vars.algolia.appId;
454+
eleventyConfig.addNunjucksAsyncShortcode('algoliaid', async () => {
455+
const {publicVars} = await import('lit-dev-tools-esm/lib/configs.js');
456+
return publicVars.algolia.appId;
458457
});
459458

460459
// Source: https://github.com/11ty/eleventy-base-blog/blob/master/.eleventy.js

packages/lit-dev-content/package.json

+1-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"dev:build:eleventy": "wireit",
2323
"dev:build:eleventy:watch": "wireit",
2424
"dev:serve": "wireit",
25-
"copy-keys": "wireit",
2625
"prod:build": "wireit",
2726
"prod:build:assets": "wireit"
2827
},
@@ -137,7 +136,7 @@
137136
"lib"
138137
],
139138
"dependencies": [
140-
"copy-keys"
139+
"../lit-dev-tools-esm:build:ts"
141140
],
142141
"command": "../../node_modules/.bin/tsc --build --pretty",
143142
"clean": "if-file-deleted"
@@ -166,15 +165,6 @@
166165
"samples/js/**"
167166
],
168167
"command": "node ../lit-dev-tools-esm/lib/generate-js-samples.js"
169-
},
170-
"copy-keys": {
171-
"files": [
172-
"../../public-vars.json"
173-
],
174-
"output": [
175-
"src/public-vars.ts"
176-
],
177-
"command": "cp ../../public-vars.json public-vars.tsorig && echo 'export default ' > public-vars.tstemp && cat public-vars.tsorig >> public-vars.tstemp && cp public-vars.tstemp src/public-vars.ts && rm public-vars.tstemp && rm public-vars.tsorig"
178168
}
179169
},
180170
"devDependencies": {

packages/lit-dev-content/src/components/litdev-search.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import algoliasearch, {
2929
SearchIndex,
3030
} from 'algoliasearch/dist/algoliasearch-lite.esm.browser.js';
3131
import {Task, TaskStatus} from '@lit-labs/task';
32-
import vars from '../public-vars.js';
32+
import {publicVars} from 'lit-dev-tools-esm/lib/configs.js';
3333

3434
/**
3535
* Representation of each document indexed by Minisearch.
@@ -192,12 +192,12 @@ export class LitDevSearch extends LitElement {
192192
private _searchText: string = '';
193193

194194
private static _algoliaClient: SearchClient = algoliasearch(
195-
vars.algolia.appId,
196-
vars.algolia.searchOnlyKey
195+
publicVars.algolia.appId,
196+
publicVars.algolia.searchOnlyKey
197197
);
198198

199199
private static _algoliaIndex: SearchIndex =
200-
LitDevSearch._algoliaClient.initIndex(vars.algolia.index);
200+
LitDevSearch._algoliaClient.initIndex(publicVars.algolia.index);
201201

202202
private _searchTask: Task<string[], Suggestion[]> | null = null;
203203

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const publicVars = {
2+
algolia: {
3+
appId: 'OC866NN61X',
4+
searchOnlyKey: '33401c252374747a39ef3b42c9f701ac',
5+
index: 'lit.dev',
6+
},
7+
};

packages/lit-dev-tools-esm/src/upload-algolia-index.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
import algolia from 'algoliasearch';
88
import fs from 'fs';
9+
import {publicVars} from './configs.js';
910

10-
const varsRaw = fs.readFileSync('../../public-vars.json', 'utf8');
11-
const vars = JSON.parse(varsRaw);
1211
const searchIndexRaw = fs.readFileSync(
1312
'../lit-dev-content/_site/searchIndex.json',
1413
'utf8'
@@ -20,6 +19,6 @@ if (!ALGOLIA_WRITE_KEY) {
2019
throw new Error('ALGOLIA_WRITE_KEY environment variable is not set');
2120
}
2221

23-
const client = algolia(vars.algolia.appId, ALGOLIA_WRITE_KEY);
24-
const index = client.initIndex(vars.algolia.indexName);
22+
const client = algolia(publicVars.algolia.appId, ALGOLIA_WRITE_KEY);
23+
const index = client.initIndex(publicVars.algolia.index);
2524
await index.replaceAllObjects(searchIndex);

public-vars.json

-7
This file was deleted.

0 commit comments

Comments
 (0)