From 7713ab2309bd18b0ca5914d7342fb63b79a54013 Mon Sep 17 00:00:00 2001 From: Pascal Garber Date: Fri, 19 Jul 2024 12:06:51 +0200 Subject: [PATCH] Template files: Removed enviroment directory --- .ts-for-gir.packages-gtk4.rc.js | 5 ++- .../src/template-processor.ts | 18 +--------- .../src/type-definition-generator.ts | 34 +++++++++---------- .../templates/{gjs => }/README-GJS.md | 0 .../templates/{gjs => }/gio-2.0.d.ts | 0 .../templates/{gjs => }/gobject-2.0.d.ts | 0 .../templates/{gjs => }/index.d.ts | 0 .../templates/{gjs => }/index.js | 0 .../templates/{gjs => }/module-ambient.d.ts | 0 .../templates/{gjs => }/module-ambient.js | 0 .../templates/{gjs => }/module-import.d.ts | 0 .../templates/{gjs => }/module-import.js | 0 .../templates/{gjs => }/module.append.d.ts | 0 .../templates/{gjs => }/module.d.ts | 0 .../templates/{gjs => }/module.js | 0 15 files changed, 20 insertions(+), 37 deletions(-) rename packages/generator-typescript/templates/{gjs => }/README-GJS.md (100%) rename packages/generator-typescript/templates/{gjs => }/gio-2.0.d.ts (100%) rename packages/generator-typescript/templates/{gjs => }/gobject-2.0.d.ts (100%) rename packages/generator-typescript/templates/{gjs => }/index.d.ts (100%) rename packages/generator-typescript/templates/{gjs => }/index.js (100%) rename packages/generator-typescript/templates/{gjs => }/module-ambient.d.ts (100%) rename packages/generator-typescript/templates/{gjs => }/module-ambient.js (100%) rename packages/generator-typescript/templates/{gjs => }/module-import.d.ts (100%) rename packages/generator-typescript/templates/{gjs => }/module-import.js (100%) rename packages/generator-typescript/templates/{gjs => }/module.append.d.ts (100%) rename packages/generator-typescript/templates/{gjs => }/module.d.ts (100%) rename packages/generator-typescript/templates/{gjs => }/module.js (100%) diff --git a/.ts-for-gir.packages-gtk4.rc.js b/.ts-for-gir.packages-gtk4.rc.js index 270adcb24..7f0e13664 100644 --- a/.ts-for-gir.packages-gtk4.rc.js +++ b/.ts-for-gir.packages-gtk4.rc.js @@ -1,7 +1,6 @@ -import allPackagesConfig from './.ts-for-gir.packages-all.rc.js'; +import gtk4PackagesConfig from './.ts-for-gir.gtk4.rc.js'; export default { - ...allPackagesConfig, - modules: ['Gtk-4.0', 'Adw-1.0'], + ...gtk4PackagesConfig, package: true, } diff --git a/packages/generator-typescript/src/template-processor.ts b/packages/generator-typescript/src/template-processor.ts index 050492e9b..8878d66bc 100644 --- a/packages/generator-typescript/src/template-processor.ts +++ b/packages/generator-typescript/src/template-processor.ts @@ -25,7 +25,6 @@ import type { OptionsGeneration, Dependency, TemplateData } from '@ts-for-gir/li const TEMPLATE_DIR = join(__dirname, './templates') export class TemplateProcessor { - protected environmentTemplateDir: string protected log: Logger protected transformation: Transformation constructor( @@ -56,24 +55,9 @@ export class TemplateProcessor { join, dirname, } - this.environmentTemplateDir = this.getEnvironmentDir(TEMPLATE_DIR) this.log = new Logger(config.verbose, `TemplateProcessor (${this.packageName})`) } - /** - * Get the output or input directory of the environment - * @param environment The environment to get the directory for - * @param baseDir The base directory - * @returns The path to the directory - */ - protected getEnvironmentDir = (baseDir: string): string => { - if (!baseDir.endsWith('/gjs')) { - return join(baseDir, 'gjs') - } - - return baseDir - } - protected getAppendTemplateName(templateFilename: string) { let appendTemplateFilename = templateFilename @@ -252,7 +236,7 @@ export class TemplateProcessor { * @param templateFilename */ public async exists(templateFilename: string): Promise { - const fullEnvironmentTemplatePath = join(this.environmentTemplateDir, templateFilename) + const fullEnvironmentTemplatePath = join(TEMPLATE_DIR, templateFilename) const fullGeneralTemplatePath = join(TEMPLATE_DIR, templateFilename) if (await fileExists(fullEnvironmentTemplatePath)) { return fullEnvironmentTemplatePath diff --git a/packages/generator-typescript/src/type-definition-generator.ts b/packages/generator-typescript/src/type-definition-generator.ts index 84587d2bb..0eda82593 100644 --- a/packages/generator-typescript/src/type-definition-generator.ts +++ b/packages/generator-typescript/src/type-definition-generator.ts @@ -49,47 +49,47 @@ export class TypeDefinitionGenerator implements Generator { name: gjs.importName, }) - await templateProcessor.create('gjs.d.ts', config.outdir, 'gjs.d.ts') - await templateProcessor.create('gjs.js', config.outdir, 'gjs.js') + await templateProcessor.create('gjs/gjs.d.ts', config.outdir, 'gjs.d.ts') + await templateProcessor.create('gjs/gjs.js', config.outdir, 'gjs.js') // Additional DOM types supported by GJS - await templateProcessor.create('dom.d.ts', config.outdir, 'dom.d.ts') - await templateProcessor.create('dom.js', config.outdir, 'dom.js') + await templateProcessor.create('gjs/dom.d.ts', config.outdir, 'dom.d.ts') + await templateProcessor.create('gjs/dom.js', config.outdir, 'dom.js') - await templateProcessor.create('gettext.d.ts', config.outdir, 'gettext.d.ts') - await templateProcessor.create('gettext.js', config.outdir, 'gettext.js') + await templateProcessor.create('gjs/gettext.d.ts', config.outdir, 'gettext.d.ts') + await templateProcessor.create('gjs/gettext.js', config.outdir, 'gettext.js') - await templateProcessor.create('system.d.ts', config.outdir, 'system.d.ts') - await templateProcessor.create('system.js', config.outdir, 'system.js') + await templateProcessor.create('gjs/system.d.ts', config.outdir, 'system.d.ts') + await templateProcessor.create('gjs/system.js', config.outdir, 'system.js') - await templateProcessor.create('cairo.d.ts', config.outdir, 'cairo.d.ts') - await templateProcessor.create('cairo.js', config.outdir, 'cairo.js') + await templateProcessor.create('gjs/cairo.d.ts', config.outdir, 'cairo.d.ts') + await templateProcessor.create('gjs/cairo.js', config.outdir, 'cairo.js') // Import ambient types - await templateProcessor.create('gjs-ambient.d.ts', config.outdir, 'gjs-ambient.d.ts') - await templateProcessor.create('gjs-ambient.js', config.outdir, 'gjs-ambient.js') + await templateProcessor.create('gjs/gjs-ambient.d.ts', config.outdir, 'gjs-ambient.d.ts') + await templateProcessor.create('gjs/gjs-ambient.js', config.outdir, 'gjs-ambient.js') const pkg = new NpmPackage(config, dependencyManager, gjs, await dependencyManager.core()) await pkg.exportNPMPackage() } else { - const gjsContent = await templateProcessor.load('gjs.d.ts') + const gjsContent = await templateProcessor.load('gjs/gjs.d.ts') await templateProcessor.write(gjsContent.prepend + '\n' + gjsContent.append, config.outdir, 'gjs.d.ts') - const gettextContent = await templateProcessor.load('gettext.d.ts') + const gettextContent = await templateProcessor.load('gjs/gettext.d.ts') const gettextContentAmbient = wrapIntoAmbientModule('gettext', null, [ gettextContent.prepend, gettextContent.append, ]) await templateProcessor.write(gettextContentAmbient.join('\n'), config.outdir, 'gettext.d.ts') - const systemContent = await templateProcessor.load('system.d.ts') + const systemContent = await templateProcessor.load('gjs/system.d.ts') const systemContentAmbient = wrapIntoAmbientModule('system', null, [ systemContent.prepend, systemContent.append, ]) await templateProcessor.write(systemContentAmbient.join('\n'), config.outdir, 'system.d.ts') - const cairoContent = await templateProcessor.load('cairo.d.ts') + const cairoContent = await templateProcessor.load('gjs/cairo.d.ts') const cairoContentAmbient = wrapIntoAmbientModule('cairo', null, [ cairoContent.prepend, cairoContent.append, @@ -97,7 +97,7 @@ export class TypeDefinitionGenerator implements Generator { await templateProcessor.write(cairoContentAmbient.join('\n'), config.outdir, 'cairo.d.ts') // Additional DOM types supported by GJS - const domContent = await templateProcessor.load('dom.d.ts') + const domContent = await templateProcessor.load('gjs/dom.d.ts') await templateProcessor.write(domContent.prepend + '\n' + domContent.append, config.outdir, 'dom.d.ts') } } diff --git a/packages/generator-typescript/templates/gjs/README-GJS.md b/packages/generator-typescript/templates/README-GJS.md similarity index 100% rename from packages/generator-typescript/templates/gjs/README-GJS.md rename to packages/generator-typescript/templates/README-GJS.md diff --git a/packages/generator-typescript/templates/gjs/gio-2.0.d.ts b/packages/generator-typescript/templates/gio-2.0.d.ts similarity index 100% rename from packages/generator-typescript/templates/gjs/gio-2.0.d.ts rename to packages/generator-typescript/templates/gio-2.0.d.ts diff --git a/packages/generator-typescript/templates/gjs/gobject-2.0.d.ts b/packages/generator-typescript/templates/gobject-2.0.d.ts similarity index 100% rename from packages/generator-typescript/templates/gjs/gobject-2.0.d.ts rename to packages/generator-typescript/templates/gobject-2.0.d.ts diff --git a/packages/generator-typescript/templates/gjs/index.d.ts b/packages/generator-typescript/templates/index.d.ts similarity index 100% rename from packages/generator-typescript/templates/gjs/index.d.ts rename to packages/generator-typescript/templates/index.d.ts diff --git a/packages/generator-typescript/templates/gjs/index.js b/packages/generator-typescript/templates/index.js similarity index 100% rename from packages/generator-typescript/templates/gjs/index.js rename to packages/generator-typescript/templates/index.js diff --git a/packages/generator-typescript/templates/gjs/module-ambient.d.ts b/packages/generator-typescript/templates/module-ambient.d.ts similarity index 100% rename from packages/generator-typescript/templates/gjs/module-ambient.d.ts rename to packages/generator-typescript/templates/module-ambient.d.ts diff --git a/packages/generator-typescript/templates/gjs/module-ambient.js b/packages/generator-typescript/templates/module-ambient.js similarity index 100% rename from packages/generator-typescript/templates/gjs/module-ambient.js rename to packages/generator-typescript/templates/module-ambient.js diff --git a/packages/generator-typescript/templates/gjs/module-import.d.ts b/packages/generator-typescript/templates/module-import.d.ts similarity index 100% rename from packages/generator-typescript/templates/gjs/module-import.d.ts rename to packages/generator-typescript/templates/module-import.d.ts diff --git a/packages/generator-typescript/templates/gjs/module-import.js b/packages/generator-typescript/templates/module-import.js similarity index 100% rename from packages/generator-typescript/templates/gjs/module-import.js rename to packages/generator-typescript/templates/module-import.js diff --git a/packages/generator-typescript/templates/gjs/module.append.d.ts b/packages/generator-typescript/templates/module.append.d.ts similarity index 100% rename from packages/generator-typescript/templates/gjs/module.append.d.ts rename to packages/generator-typescript/templates/module.append.d.ts diff --git a/packages/generator-typescript/templates/gjs/module.d.ts b/packages/generator-typescript/templates/module.d.ts similarity index 100% rename from packages/generator-typescript/templates/gjs/module.d.ts rename to packages/generator-typescript/templates/module.d.ts diff --git a/packages/generator-typescript/templates/gjs/module.js b/packages/generator-typescript/templates/module.js similarity index 100% rename from packages/generator-typescript/templates/gjs/module.js rename to packages/generator-typescript/templates/module.js