Skip to content

Commit

Permalink
commit auto formatting of files with the new prettier config
Browse files Browse the repository at this point in the history
  • Loading branch information
Totto16 committed Mar 28, 2024
1 parent 357ac99 commit d120707
Show file tree
Hide file tree
Showing 74 changed files with 477 additions and 589 deletions.
35 changes: 17 additions & 18 deletions examples/hello-world/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { build } from "esbuild";
import { copyFileSync } from "fs";
import { resolve, dirname } from "path";
import { build } from 'esbuild';
import { copyFileSync } from 'fs';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
import AdmZip from "adm-zip";
import metadata from "./src/metadata.json" assert { type: 'json' };
import AdmZip from 'adm-zip';
import metadata from './src/metadata.json' assert { type: 'json' };

const __dirname = dirname(fileURLToPath(import.meta.url));

Expand All @@ -20,34 +20,33 @@ build({
// firefox78 // Since GJS 1.65.90
// firefox91 // Since GJS 1.71.1
// firefox102 // Since GJS 1.73.2
target: "firefox78",
platform: "neutral",
platform: "node",
target: 'firefox78',
platform: 'neutral',
platform: 'node',
// mainFields: ['main'],
// conditions: ['require', 'default'],
format: 'esm',
external: ['gi://*', 'resource://*', 'system', 'gettext', 'cairo'],
}).then(() => {
const metaSrc = resolve(__dirname, "src/metadata.json");
const metaDist = resolve(__dirname, "dist/metadata.json");
const metaSrc = resolve(__dirname, 'src/metadata.json');
const metaDist = resolve(__dirname, 'dist/metadata.json');
const zipFilename = `${metadata.uuid}.zip`;
const zipDist = resolve(__dirname, zipFilename);
copyFileSync(metaSrc, metaDist);

const zip = new AdmZip();
zip.addLocalFolder(resolve(__dirname, "dist"));
zip.addLocalFolder(resolve(__dirname, 'dist'));
zip.writeZip(zipDist);

console.log(`Build complete. Zip file: ${zipFilename}\n`);
console.log(`Install with: gnome-extensions install ${zipFilename}`)
console.log(`Update with: gnome-extensions install --force ${zipFilename}`)
console.log(`Enable with: gnome-extensions enable ${metadata.uuid}`)
console.log(`Install with: gnome-extensions install ${zipFilename}`);
console.log(`Update with: gnome-extensions install --force ${zipFilename}`);
console.log(`Enable with: gnome-extensions enable ${metadata.uuid}`);
console.log('');
console.log(`Disable with: gnome-extensions disable ${metadata.uuid}`)
console.log(`Remove with: gnome-extensions uninstall ${metadata.uuid}`)
console.log(`Disable with: gnome-extensions disable ${metadata.uuid}`);
console.log(`Remove with: gnome-extensions uninstall ${metadata.uuid}`);
console.log('');
console.log('To check if the extension has been recognized, you can execute the following: gnome-extensions list.')
console.log('To check if the extension has been recognized, you can execute the following: gnome-extensions list.');
console.log(`If ${metadata.uuid} is listed in the output, you should be able to activate the extension.`);
console.log('Otherwise, you will need to restart the GNOME Shell.');
});

5 changes: 2 additions & 3 deletions examples/hello-world/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import '@girs/gjs'; // For global types like `log()`
import St from '@girs/st-14';

import "@girs/gnome-shell/extensions/global"; // For global shell types
import '@girs/gnome-shell/extensions/global'; // For global shell types
import { Extension, gettext as _ } from '@girs/gnome-shell/extensions/extension';
import PanelMenu from '@girs/gnome-shell/ui/panelMenu';
import * as Main from '@girs/gnome-shell/ui/main';

export default class ExampleExtension extends Extension {

_indicator: PanelMenu.Button;

enable() {
Expand All @@ -29,4 +28,4 @@ export default class ExampleExtension extends Extension {
this._indicator?.destroy();
this._indicator = null;
}
}
}
16 changes: 7 additions & 9 deletions examples/hello-world/src/metadata.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "Hello World",
"description": "Simple Gnome Shell Hello World Extension example",
"uuid": "hello-world-example@gjsify.gnome-shell",
"settings-schema": "gnome-shell.gjsify.hello-world-example",
"shell-version": [
"45"
],
"url": "https://github.com/gjsify/gnome-shell/tree/main/examples/hello-world"
}
"name": "Hello World",
"description": "Simple Gnome Shell Hello World Extension example",
"uuid": "hello-world-example@gjsify.gnome-shell",
"settings-schema": "gnome-shell.gjsify.hello-world-example",
"shell-version": ["45"],
"url": "https://github.com/gjsify/gnome-shell/tree/main/examples/hello-world"
}
20 changes: 9 additions & 11 deletions examples/hello-world/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"types": [],
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler"
},
"include": [],
"files": [
"src/extension.ts",
]
"compilerOptions": {
"lib": ["ESNext"],
"types": [],
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler"
},
"include": [],
"files": ["src/extension.ts"]
}
4 changes: 2 additions & 2 deletions packages/gnome-shell/scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';

export const __dirname = globalThis.__dirname || dirname(fileURLToPath(import.meta.url));
export const SRC_DIR = resolve(__dirname,'../src');
export const DIST_DIR = resolve(__dirname,'../dist');
export const SRC_DIR = resolve(__dirname, '../src');
export const DIST_DIR = resolve(__dirname, '../dist');
28 changes: 14 additions & 14 deletions packages/gnome-shell/scripts/generate-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { loadJsonFile, writeJsonFile } from './utils/json.js';
import { DIST_DIR, __dirname } from './config.js';
import { resolve, extname, basename } from 'path';

const IGNORE_FILENAMES = ['sharedInternals.d.ts', 'global.d.ts']
const IGNORE_DIRS = ['types']
const IGNORE_FILENAMES = ['sharedInternals.d.ts', 'global.d.ts'];
const IGNORE_DIRS = ['types'];

/** */
const generateExport = (filePath) => {
Expand All @@ -17,47 +17,47 @@ const generateExport = (filePath) => {
const cjsJsPath = pathWithoutExtension + '.cjs';
const ambientPath = pathWithoutExtension + '-ambient.d.ts';

if(IGNORE_FILENAMES.includes(fileName)) return;
if(fileName.endsWith('ambient.d.ts')) return;
if (IGNORE_FILENAMES.includes(fileName)) return;
if (fileName.endsWith('ambient.d.ts')) return;

let exportName = pathWithoutExtension;
exportName = basename(exportName) === 'index' ? '.' + resolve(exportName, '..') : '.' + exportName;
if(exportName.endsWith('/')) exportName = exportName.substring(0, exportName.length - 1);
if (exportName.endsWith('/')) exportName = exportName.substring(0, exportName.length - 1);

const exp = {};

exp[exportName] = {
import: {
types: `./dist${relativePath}`,
default: `./dist${esmJsPath}`
default: `./dist${esmJsPath}`,
},
require: {
types: `./dist${relativePath}`,
default: `./dist${cjsJsPath}`
}
}
default: `./dist${cjsJsPath}`,
},
};

exp[exportName + '/ambient'] = `./dist${ambientPath}`;

return exp
}
return exp;
};

const start = async () => {
const pkg = await loadJsonFile(resolve(__dirname, '../package.json'));

const typeFiles = await getAllFiles(DIST_DIR, ['.ts'], IGNORE_DIRS);

let exports = {
"./extensions/global": "./dist/extensions/global.d.ts"
'./extensions/global': './dist/extensions/global.d.ts',
};

for (const absolutePath of typeFiles) {
exports = { ...exports, ...generateExport(absolutePath) }
exports = { ...exports, ...generateExport(absolutePath) };
}

pkg.exports = exports;

writeJsonFile(resolve(__dirname, '../package.json'), pkg);
}
};

await start();
39 changes: 17 additions & 22 deletions packages/gnome-shell/scripts/generate-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { DIST_DIR, __dirname } from './config.js';
import { extname, basename } from 'path';
import { writeFile } from 'fs/promises';

const RESOURCE_PATH = (path, fileName) => `${path}/${fileName}` === "/extensions/prefs"
? `resource:///org/gnome/Shell/Extensions/js${path}/${fileName}.js`
: `resource:///org/gnome/shell${path}/${fileName}.js`;
const RESOURCE_PATH = (path, fileName) => (`${path}/${fileName}` === '/extensions/prefs' ? `resource:///org/gnome/Shell/Extensions/js${path}/${fileName}.js` : `resource:///org/gnome/shell${path}/${fileName}.js`);

const AMBIENT_TEMPLATE = (path, fileName) => `declare module "${RESOURCE_PATH(path, fileName)}" {
export * from "@girs/gnome-shell${path}/${fileName}";
}`
}`;

const ESM_TEMPLATE = (path, fileName) => `export * from '${RESOURCE_PATH(path, fileName)}';`;
const CJS_TEMPLATE = (path, fileName) => `module.exports = imports${path.replaceAll('/', '.')}.${fileName};`;
Expand All @@ -20,41 +18,38 @@ const IGNORE_FILENAMES = ['index.d.ts', 'index.ts', 'sharedInternals.d.ts', 'glo

const IGNORE_DIRS = ['types'];


const generateFiles = async (absolutePath) => {
const relativePath = absolutePath.replace(DIST_DIR, '');
const fileName = basename(relativePath);

if(IGNORE_FILENAMES.includes(fileName)) return;
if (IGNORE_FILENAMES.includes(fileName)) return;

if(fileName.endsWith('ambient.d.ts')) return;
if (fileName.endsWith('ambient.d.ts')) return;

const relativeWithoutExtension = relativePath.replace(extname(relativePath), '').replace('.d', '');

const fileNameWithoutExt = basename(relativeWithoutExtension);
const relativeFilePath = relativePath.split('/').slice(0, -1).join('/')
const relativeFilePath = relativePath.split('/').slice(0, -1).join('/');

const ambientDestPath = absolutePath.replace(fileName, `${fileNameWithoutExt}-ambient.d.ts`)
const esmDestPath = absolutePath.replace(fileName, `${fileNameWithoutExt}.js`)
const cjsDestPath = absolutePath.replace(fileName, `${fileNameWithoutExt}.cjs`)
const ambientDestPath = absolutePath.replace(fileName, `${fileNameWithoutExt}-ambient.d.ts`);
const esmDestPath = absolutePath.replace(fileName, `${fileNameWithoutExt}.js`);
const cjsDestPath = absolutePath.replace(fileName, `${fileNameWithoutExt}.cjs`);

const ambientContent = AMBIENT_TEMPLATE(relativeFilePath, fileNameWithoutExt)
const esmContent = ESM_TEMPLATE(relativeFilePath, fileNameWithoutExt)
const cjsContent = CJS_TEMPLATE(relativeFilePath, fileNameWithoutExt)
const ambientContent = AMBIENT_TEMPLATE(relativeFilePath, fileNameWithoutExt);
const esmContent = ESM_TEMPLATE(relativeFilePath, fileNameWithoutExt);
const cjsContent = CJS_TEMPLATE(relativeFilePath, fileNameWithoutExt);

await writeFile(ambientDestPath, ambientContent, 'utf-8')
await writeFile(esmDestPath, esmContent, 'utf-8')
await writeFile(cjsDestPath, cjsContent, 'utf-8')
}
await writeFile(ambientDestPath, ambientContent, 'utf-8');
await writeFile(esmDestPath, esmContent, 'utf-8');
await writeFile(cjsDestPath, cjsContent, 'utf-8');
};

const start = async () => {
const typeFiles = await getAllFiles(DIST_DIR, ['.ts'], IGNORE_DIRS);

for (const absolutePath of typeFiles) {
await generateFiles(absolutePath)
await generateFiles(absolutePath);
}


}
};

await start();
29 changes: 13 additions & 16 deletions packages/gnome-shell/scripts/generate-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { DIST_DIR, __dirname } from './config.js';
import { resolve, extname, basename } from 'path';
import { writeFile } from 'fs/promises';

const IGNORE_DIRS = ['types']
const IGNORE_FILENAMES = ['index.d.ts', 'index.ts', 'sharedInternals.d.ts', 'global.d.ts']
const IGNORE_DIRS = ['types'];
const IGNORE_FILENAMES = ['index.d.ts', 'index.ts', 'sharedInternals.d.ts', 'global.d.ts'];
const EXPORT_ESM_TEMPLATE = (exportName, fileName) => `export * as ${exportName} from './${fileName}.js';`;
const EXPORT_CJS_TEMPLATE = (exportName, fileName) => `module.exports.${exportName} = require('./${fileName}.cjs');`;
const IMPORT_AMBIENT_TEMPLATE = (fileName) => `import './${fileName}-ambient.d.ts';`;
Expand All @@ -21,7 +21,7 @@ const appendDir = async (dirPath, data) => {
data.ambient += IMPORT_AMBIENT_TEMPLATE(dirIndexName) + '\n';

return data;
}
};

const appendFile = async (filePath, data) => {
const fileName = basename(filePath);
Expand All @@ -32,54 +32,51 @@ const appendFile = async (filePath, data) => {
data.ambient += IMPORT_AMBIENT_TEMPLATE(withoutExtension) + '\n';

return data;
}

};

const start = async () => {
const dirs = await getAllDirs(DIST_DIR, IGNORE_DIRS, true);

for (const absoluteDir of dirs) {
const childDirs = await getAllDirs(absoluteDir, IGNORE_DIRS, false);
const files = (await getAllFiles(absoluteDir, ['.ts'], IGNORE_DIRS, false))
.filter((file) => !file.endsWith('ambient.d.ts') && !IGNORE_FILENAMES.includes(basename(file)));
const files = (await getAllFiles(absoluteDir, ['.ts'], IGNORE_DIRS, false)).filter((file) => !file.endsWith('ambient.d.ts') && !IGNORE_FILENAMES.includes(basename(file)));

const data = {
esm: '',
cjs: '',
ambient: ''
}
ambient: '',
};

for (const file of files) {
appendFile(file, data)
appendFile(file, data);
}

for (const childDir of childDirs) {
appendDir(childDir, data)
appendDir(childDir, data);
}

await writeFile(resolve(absoluteDir, 'index.d.ts'), data.esm, 'utf-8');
await writeFile(resolve(absoluteDir, 'index.js'), data.esm, 'utf-8');
await writeFile(resolve(absoluteDir, 'index.cjs'), data.cjs, 'utf-8');
await writeFile(resolve(absoluteDir, 'index-ambient.d.ts'), data.ambient, 'utf-8');

}

const rootDirs = await getAllDirs(DIST_DIR, IGNORE_DIRS, false);

const data = {
esm: '',
cjs: '',
ambient: ''
}
ambient: '',
};

for (const rootDir of rootDirs) {
appendDir(rootDir, data)
appendDir(rootDir, data);
}

await writeFile(resolve(DIST_DIR, 'index.d.ts'), data.esm, 'utf-8');
await writeFile(resolve(DIST_DIR, 'index.js'), data.esm, 'utf-8');
await writeFile(resolve(DIST_DIR, 'index.cjs'), data.cjs, 'utf-8');
await writeFile(resolve(DIST_DIR, 'index-ambient.d.ts'), data.ambient, 'utf-8');
}
};

await start();
2 changes: 1 addition & 1 deletion packages/gnome-shell/scripts/generate-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ const start = async () => {
await mkdir(destFile.split('/').slice(0, -1).join('/'), { recursive: true });
await copyFile(srcFile, destFile);
}
}
};

await start();
Loading

0 comments on commit d120707

Please sign in to comment.