From 0fe2b5b3397681b13494e66064bba05bc5b365ed Mon Sep 17 00:00:00 2001 From: Vladimir Kubantsev Date: Wed, 15 Jul 2026 10:26:53 +0300 Subject: [PATCH] feat: assets ambient types from app-builder Updated app-builder version Dropped assets type definitions from templates Added app-builder ui ambient types in typescript template Refs: gravity-ui/app-builder#333 --- README.md | 10 ++++------ scripts/readme/readme.hbs | 10 ++++------ src/generators/appBuilder.test.ts | 2 +- src/generators/appBuilder.ts | 7 +------ src/generators/templates/src/ui/types/assets.d-ts.hbs | 2 -- src/generators/typescript.test.ts | 1 + src/generators/typescript.ts | 1 + 7 files changed, 12 insertions(+), 21 deletions(-) delete mode 100644 src/generators/templates/src/ui/types/assets.d-ts.hbs diff --git a/README.md b/README.md index 98574ba..990fc94 100644 --- a/README.md +++ b/README.md @@ -98,12 +98,10 @@ Three shapes: app-builder layout (frontend and/or backend selected), plain TS en |-- tsconfig.json |-- entries/ | `-- my-app-app.tsx # entry (>=1 allowed); name from project; ext/case by react+language - |-- components/ # only if react enabled - | |-- index.ts # re-exports App; ext by language - | `-- App/ - | `-- App.tsx # demo component; ext by language - `-- types/ - `-- assets.d.ts # only ts+react + `-- components/ # only if react enabled + |-- index.ts # re-exports App; ext by language + `-- App/ + `-- App.tsx # demo component; ext by language ``` **Neither frontend nor backend, TypeScript** — plain `src/index.ts`, no app-builder, straight `tsc` compile. diff --git a/scripts/readme/readme.hbs b/scripts/readme/readme.hbs index 3225381..e0df393 100644 --- a/scripts/readme/readme.hbs +++ b/scripts/readme/readme.hbs @@ -51,12 +51,10 @@ Three shapes: app-builder layout (frontend and/or backend selected), plain TS en |-- tsconfig.json |-- entries/ | `-- my-app-app.tsx # entry (>=1 allowed); name from project; ext/case by react+language - |-- components/ # only if react enabled - | |-- index.ts # re-exports App; ext by language - | `-- App/ - | `-- App.tsx # demo component; ext by language - `-- types/ - `-- assets.d.ts # only ts+react + `-- components/ # only if react enabled + |-- index.ts # re-exports App; ext by language + `-- App/ + `-- App.tsx # demo component; ext by language ``` **Neither frontend nor backend, TypeScript** — plain `src/index.ts`, no app-builder, straight `tsc` compile. diff --git a/src/generators/appBuilder.test.ts b/src/generators/appBuilder.test.ts index 9b9a648..7184c39 100644 --- a/src/generators/appBuilder.test.ts +++ b/src/generators/appBuilder.test.ts @@ -154,7 +154,7 @@ document.querySelector('#root')?.append(header); 'NODE_ENV=production app-builder build --target server', ); t.assert.equal(model.scripts.start, 'node dist/server/index.js'); - t.assert.equal(model.packages.devDependencies['@gravity-ui/app-builder'], '^0.48.0'); + t.assert.equal(model.packages.devDependencies['@gravity-ui/app-builder'], '^0.49.0'); t.assert.ok(file('app-builder.config.ts')); t.assert.equal(file('src/ui/entries/my-app-app.ts'), null); diff --git a/src/generators/appBuilder.ts b/src/generators/appBuilder.ts index b16f1cd..f4c5677 100644 --- a/src/generators/appBuilder.ts +++ b/src/generators/appBuilder.ts @@ -16,7 +16,6 @@ import renderEntryJs from './templates/src/ui/entries/entry.js.hbs.js'; import renderEntryJsx from './templates/src/ui/entries/entry.jsx.hbs.js'; import renderEntryTs from './templates/src/ui/entries/entry.ts.hbs.js'; import renderEntryTsx from './templates/src/ui/entries/entry.tsx.hbs.js'; -import renderAssetsTypes from './templates/src/ui/types/assets.d-ts.hbs.js'; export async function generateAppBuilder(model: ProjectModel, fs: FileSystem): Promise { const {hasFrontend, hasReact, hasAppBuilder} = calculateFlags(model); @@ -33,7 +32,7 @@ export async function generateAppBuilder(model: ProjectModel, fs: FileSystem): P target = ' --target client'; } - addDevDep(model, '@gravity-ui/app-builder', '^0.48.0'); + addDevDep(model, '@gravity-ui/app-builder', '^0.49.0'); if (model.hasBackend) { addScript(model, 'start', 'node dist/server/index.js'); @@ -93,10 +92,6 @@ async function writeReactFiles( barrelFile, isTs ? renderComponentsIndexTs({}) : renderComponentsIndexJs({}), ); - - if (isTs) { - await fs.writeFile(path.join(uiDir, 'types', 'assets.d.ts'), renderAssetsTypes({})); - } } async function writeEntryFile( diff --git a/src/generators/templates/src/ui/types/assets.d-ts.hbs b/src/generators/templates/src/ui/types/assets.d-ts.hbs deleted file mode 100644 index 875203d..0000000 --- a/src/generators/templates/src/ui/types/assets.d-ts.hbs +++ /dev/null @@ -1,2 +0,0 @@ -declare module '*.css'; -declare module '*.scss'; diff --git a/src/generators/typescript.test.ts b/src/generators/typescript.test.ts index fbd857b..ce40b4f 100644 --- a/src/generators/typescript.test.ts +++ b/src/generators/typescript.test.ts @@ -40,6 +40,7 @@ test.describe('typescript generator', () => { t.assert.ok(ui); t.assert.equal(ui.content.compilerOptions.composite, true); t.assert.equal(ui.content.compilerOptions.jsx, 'react-jsx'); + t.assert.deepEqual(ui.content.compilerOptions.types, ['@gravity-ui/app-builder/ui']); const server = file('src/server/tsconfig.json'); t.assert.ok(server); diff --git a/src/generators/typescript.ts b/src/generators/typescript.ts index c4aac81..ea458ff 100644 --- a/src/generators/typescript.ts +++ b/src/generators/typescript.ts @@ -19,6 +19,7 @@ export async function generateTypeScript(model: ProjectModel, fs: FileSystem): P composite: true, outDir: '../../dist/ui', rootDir: '.', + types: ['@gravity-ui/app-builder/ui'], }, include: ['**/*'], };