mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 08:47:31 +00:00
Auto generate client tsconfig
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user