mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 00:37:19 +00:00
Auto generate client tsconfig
This commit is contained in:
@@ -171,6 +171,7 @@ export default function () {
|
|||||||
'lazy-app',
|
'lazy-app',
|
||||||
'feature-meta',
|
'feature-meta',
|
||||||
);
|
);
|
||||||
|
const clientBasePath = path.join(process.cwd(), 'src', 'client');
|
||||||
|
|
||||||
const joinedMetas = metas.flat().join();
|
const joinedMetas = metas.flat().join();
|
||||||
|
|
||||||
@@ -193,6 +194,13 @@ export default function () {
|
|||||||
const preprocessorMetaTsNames = preprocessorMetas.map((tsImport) =>
|
const preprocessorMetaTsNames = preprocessorMetas.map((tsImport) =>
|
||||||
getTsName(tsImport),
|
getTsName(tsImport),
|
||||||
);
|
);
|
||||||
|
const tsConfigEncoderPaths = encoderMetas.flatMap((tsImport) => [
|
||||||
|
path.relative(clientBasePath, tsImport.replace(/\/meta$/, '')),
|
||||||
|
path.relative(
|
||||||
|
clientBasePath,
|
||||||
|
tsImport.replace(/shared\/meta$/, 'client'),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
const featureMeta = [
|
const featureMeta = [
|
||||||
autoGenComment,
|
autoGenComment,
|
||||||
@@ -200,6 +208,13 @@ export default function () {
|
|||||||
encoderMetaTsNames.map(
|
encoderMetaTsNames.map(
|
||||||
([path, name]) => `import * as ${name}EncoderMeta from '${path}';`,
|
([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 =`,
|
`export type EncoderState =`,
|
||||||
encoderMetaTsNames.map(
|
encoderMetaTsNames.map(
|
||||||
([_, name]) =>
|
([_, name]) =>
|
||||||
@@ -212,10 +227,12 @@ export default function () {
|
|||||||
),
|
),
|
||||||
`;`,
|
`;`,
|
||||||
`export const encoderMap = {`,
|
`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 type EncoderType = keyof typeof encoderMap`,
|
||||||
`export const encoders = [...Object.values(encoderMap)];`,
|
|
||||||
// Processor stuff
|
// Processor stuff
|
||||||
processorMetaTsNames.map(
|
processorMetaTsNames.map(
|
||||||
([path, name]) => `import * as ${name}ProcessorMeta from '${path}';`,
|
([path, name]) => `import * as ${name}ProcessorMeta from '${path}';`,
|
||||||
@@ -250,10 +267,29 @@ export default function () {
|
|||||||
.flat(Infinity)
|
.flat(Infinity)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
await fsp.writeFile(
|
const lazyTsConfig = {
|
||||||
path.join(featureMetaBasePath, 'index.ts'),
|
extends: '../../generic-tsconfig.json',
|
||||||
featureMeta,
|
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 {
|
return {
|
||||||
|
|||||||
@@ -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" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -43,4 +43,4 @@ Encoders must have the following:
|
|||||||
|
|
||||||
And returns (a promise for) an `ArrayBuffer`.
|
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.
|
||||||
|
|||||||
@@ -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 = {};
|
|
||||||
@@ -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" />
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../../../../../generic-tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"lib": ["webworker", "esnext"]
|
|
||||||
},
|
|
||||||
"references": [{ "path": "../../../" }]
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user