Auto generate client tsconfig

This commit is contained in:
Jake Archibald
2020-11-08 13:15:25 +00:00
parent a360191759
commit 6dbb182f7b
6 changed files with 43 additions and 58 deletions

View File

@@ -171,6 +171,7 @@ export default function () {
'lazy-app',
'feature-meta',
);
const clientBasePath = path.join(process.cwd(), 'src', 'client');
const joinedMetas = metas.flat().join();
@@ -193,6 +194,13 @@ export default function () {
const preprocessorMetaTsNames = preprocessorMetas.map((tsImport) =>
getTsName(tsImport),
);
const tsConfigEncoderPaths = encoderMetas.flatMap((tsImport) => [
path.relative(clientBasePath, tsImport.replace(/\/meta$/, '')),
path.relative(
clientBasePath,
tsImport.replace(/shared\/meta$/, 'client'),
),
]);
const featureMeta = [
autoGenComment,
@@ -200,6 +208,13 @@ export default function () {
encoderMetaTsNames.map(
([path, name]) => `import * as ${name}EncoderMeta from '${path}';`,
),
encoderMetaTsNames.map(
([path, name]) =>
`import * as ${name}EncoderEntry from '${path.replace(
/shared\/meta$/,
'client',
)}';`,
),
`export type EncoderState =`,
encoderMetaTsNames.map(
([_, name]) =>
@@ -212,10 +227,12 @@ export default function () {
),
`;`,
`export const encoderMap = {`,
encoderMetaTsNames.map(([_, name]) => ` ${name}: ${name}EncoderMeta,`),
encoderMetaTsNames.map(
([_, name]) =>
` ${name}: { meta: ${name}EncoderMeta, ...${name}EncoderEntry },`,
),
`};`,
`export type EncoderType = keyof typeof encoderMap`,
`export const encoders = [...Object.values(encoderMap)];`,
// Processor stuff
processorMetaTsNames.map(
([path, name]) => `import * as ${name}ProcessorMeta from '${path}';`,
@@ -250,10 +267,29 @@ export default function () {
.flat(Infinity)
.join('\n');
await fsp.writeFile(
path.join(featureMetaBasePath, 'index.ts'),
featureMeta,
);
const lazyTsConfig = {
extends: '../../generic-tsconfig.json',
compilerOptions: {
lib: ['esnext', 'dom', 'dom.iterable'],
types: [],
},
references: [
{ path: '../features-worker' },
{ path: '../shared' },
{ path: '../features/processors/resize/client' },
...tsConfigEncoderPaths.map((projectPath) => ({
path: projectPath,
})),
],
};
await Promise.all([
fsp.writeFile(
path.join(process.cwd(), 'src', 'client', 'tsconfig.json'),
autoGenComment + JSON.stringify(lazyTsConfig, null, ' '),
),
fsp.writeFile(path.join(featureMetaBasePath, 'index.ts'), featureMeta),
]);
}
return {

View File

@@ -1,16 +0,0 @@
{
"extends": "../../generic-tsconfig.json",
"compilerOptions": {
"lib": ["esnext", "dom", "dom.iterable"],
"types": []
},
"references": [
{ "path": "../features-worker" },
{ "path": "../shared" },
{ "path": "../features/encoders/identity/shared" },
{ "path": "../features/encoders/browserGIF/shared" },
{ "path": "../features/encoders/browserJPEG/shared" },
{ "path": "../features/encoders/browserPNG/shared" },
{ "path": "../features/processors/resize/client" }
]
}

View File

@@ -43,4 +43,4 @@ Encoders must have the following:
And returns (a promise for) an `ArrayBuffer`.
Optionally it may include a method `featureTest`, which returns a boolean for support for this decoder.
Optionally it may include a method `featureTest`, which returns a boolean indicating support for this decoder.

View File

@@ -1,15 +0,0 @@
/**
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface EncodeOptions {}
export const label = 'Original image';
export const defaultOptions: EncodeOptions = {};

View File

@@ -1,13 +0,0 @@
/**
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/// <reference path="../../../../../missing-types.d.ts" />

View File

@@ -1,7 +0,0 @@
{
"extends": "../../../../../generic-tsconfig.json",
"compilerOptions": {
"lib": ["webworker", "esnext"]
},
"references": [{ "path": "../../../" }]
}