Skip to content

Commit 0be3416

Browse files
authored
Merge pull request #26 from Totto16/add-prettier-rc
Proposal: add prettier config
2 parents f2b543c + d120707 commit 0be3416

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+568
-593
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ jobs:
3333
- run: yarn install
3434
- name: Build Types
3535
run: yarn run build:types
36+
- name: Validate Formatting
37+
run: yarn run prettier:check
3638
- name: Validate Types
3739
run: NODE_OPTIONS=--max_old_space_size=9216 yarn run validate:types
3840
- name: Build Example
3941
run: yarn run build:example
4042
- name: Validate Example Typescript
41-
run: NODE_OPTIONS=--max_old_space_size=9216 yarn run validate:example
43+
run: NODE_OPTIONS=--max_old_space_size=9216 yarn run validate:example

.prettierignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.vscode/
2+
.github/
3+
.yarn/
4+
packages/gnome-shell/dist/
5+
*.md
6+
.prettierrc
7+
.yarnrc.yml
8+
package.json

.prettierrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"printWidth": 256,
3+
"tabWidth": 4,
4+
"singleQuote": true,
5+
"arrowParens": "always",
6+
"semi": true,
7+
"trailingComma": "es5",
8+
"useTabs": false,
9+
"quoteProps": "as-needed",
10+
"bracketSpacing": true,
11+
"endOfLine": "lf"
12+
}

.vscode/extensions.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"recommendations": [
3-
"arcanis.vscode-zipfs"
3+
"arcanis.vscode-zipfs",
4+
"esbenp.prettier-vscode"
45
]
56
}

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
// "typescript.tsserver.experimental.enableProjectDiagnostics": true,
1111
"cSpell.words": [
1212
"girs"
13-
]
13+
],
14+
"prettier.prettierPath": ".yarn/sdks/prettier/index.cjs"
1415
}

.yarn/sdks/prettier/bin/prettier.cjs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env node
2+
3+
const {existsSync} = require(`fs`);
4+
const {createRequire} = require(`module`);
5+
const {resolve} = require(`path`);
6+
7+
const relPnpApiPath = "../../../../.pnp.cjs";
8+
9+
const absPnpApiPath = resolve(__dirname, relPnpApiPath);
10+
const absRequire = createRequire(absPnpApiPath);
11+
12+
if (existsSync(absPnpApiPath)) {
13+
if (!process.versions.pnp) {
14+
// Setup the environment to be able to require prettier/bin/prettier.cjs
15+
require(absPnpApiPath).setup();
16+
}
17+
}
18+
19+
// Defer to the real prettier/bin/prettier.cjs your application uses
20+
module.exports = absRequire(`prettier/bin/prettier.cjs`);

.yarn/sdks/prettier/index.cjs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env node
2+
3+
const {existsSync} = require(`fs`);
4+
const {createRequire} = require(`module`);
5+
const {resolve} = require(`path`);
6+
7+
const relPnpApiPath = "../../../.pnp.cjs";
8+
9+
const absPnpApiPath = resolve(__dirname, relPnpApiPath);
10+
const absRequire = createRequire(absPnpApiPath);
11+
12+
if (existsSync(absPnpApiPath)) {
13+
if (!process.versions.pnp) {
14+
// Setup the environment to be able to require prettier
15+
require(absPnpApiPath).setup();
16+
}
17+
}
18+
19+
// Defer to the real prettier your application uses
20+
module.exports = absRequire(`prettier`);

.yarn/sdks/prettier/package.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "prettier",
3+
"version": "3.2.5-sdk",
4+
"main": "./index.cjs",
5+
"type": "commonjs",
6+
"bin": "./bin/prettier.cjs"
7+
}

examples/hello-world/esbuild.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { build } from "esbuild";
2-
import { copyFileSync } from "fs";
3-
import { resolve, dirname } from "path";
1+
import { build } from 'esbuild';
2+
import { copyFileSync } from 'fs';
3+
import { resolve, dirname } from 'path';
44
import { fileURLToPath } from 'url';
5-
import AdmZip from "adm-zip";
6-
import metadata from "./src/metadata.json" assert { type: 'json' };
5+
import AdmZip from 'adm-zip';
6+
import metadata from './src/metadata.json' assert { type: 'json' };
77

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

@@ -20,34 +20,33 @@ build({
2020
// firefox78 // Since GJS 1.65.90
2121
// firefox91 // Since GJS 1.71.1
2222
// firefox102 // Since GJS 1.73.2
23-
target: "firefox78",
24-
platform: "neutral",
25-
platform: "node",
23+
target: 'firefox78',
24+
platform: 'neutral',
25+
platform: 'node',
2626
// mainFields: ['main'],
2727
// conditions: ['require', 'default'],
2828
format: 'esm',
2929
external: ['gi://*', 'resource://*', 'system', 'gettext', 'cairo'],
3030
}).then(() => {
31-
const metaSrc = resolve(__dirname, "src/metadata.json");
32-
const metaDist = resolve(__dirname, "dist/metadata.json");
31+
const metaSrc = resolve(__dirname, 'src/metadata.json');
32+
const metaDist = resolve(__dirname, 'dist/metadata.json');
3333
const zipFilename = `${metadata.uuid}.zip`;
3434
const zipDist = resolve(__dirname, zipFilename);
3535
copyFileSync(metaSrc, metaDist);
3636

3737
const zip = new AdmZip();
38-
zip.addLocalFolder(resolve(__dirname, "dist"));
38+
zip.addLocalFolder(resolve(__dirname, 'dist'));
3939
zip.writeZip(zipDist);
4040

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

examples/hello-world/src/extension.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import '@girs/gjs'; // For global types like `log()`
22
import St from '@girs/st-14';
33

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

99
export default class ExampleExtension extends Extension {
10-
1110
_indicator: PanelMenu.Button;
1211

1312
enable() {
@@ -29,4 +28,4 @@ export default class ExampleExtension extends Extension {
2928
this._indicator?.destroy();
3029
this._indicator = null;
3130
}
32-
}
31+
}
+7-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
2-
"name": "Hello World",
3-
"description": "Simple Gnome Shell Hello World Extension example",
4-
"uuid": "[email protected]",
5-
"settings-schema": "gnome-shell.gjsify.hello-world-example",
6-
"shell-version": [
7-
"45"
8-
],
9-
"url": "https://github.com/gjsify/gnome-shell/tree/main/examples/hello-world"
10-
}
2+
"name": "Hello World",
3+
"description": "Simple Gnome Shell Hello World Extension example",
4+
"uuid": "[email protected]",
5+
"settings-schema": "gnome-shell.gjsify.hello-world-example",
6+
"shell-version": ["45"],
7+
"url": "https://github.com/gjsify/gnome-shell/tree/main/examples/hello-world"
8+
}

examples/hello-world/tsconfig.json

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
{
2-
"compilerOptions": {
3-
"lib": ["ESNext"],
4-
"types": [],
5-
"target": "ESNext",
6-
"module": "ESNext",
7-
"moduleResolution": "Bundler"
8-
},
9-
"include": [],
10-
"files": [
11-
"src/extension.ts",
12-
]
2+
"compilerOptions": {
3+
"lib": ["ESNext"],
4+
"types": [],
5+
"target": "ESNext",
6+
"module": "ESNext",
7+
"moduleResolution": "Bundler"
8+
},
9+
"include": [],
10+
"files": ["src/extension.ts"]
1311
}

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
"publish:next": "yarn workspace @girs/gnome-shell npm publish --tolerate-republish --tag next --access public",
2121
"build": "yarn build:types && yarn build:example",
2222
"build:example": "yarn workspace @gjsify/gnome-shell-hello-world-example build",
23-
"build:types": "yarn workspace @girs/gnome-shell build"
23+
"build:types": "yarn workspace @girs/gnome-shell build",
24+
"prettier:check": "prettier --check .",
25+
"prettier:fix": "prettier --write ."
26+
},
27+
"gitHooks": {
28+
"pre-commit": "npm run prettier:check"
2429
},
2530
"workspaces": [
2631
"packages/*",
@@ -49,6 +54,7 @@
4954
"homepage": "https://github.com/gjsify/gnome-shell#readme",
5055
"packageManager": "[email protected]",
5156
"devDependencies": {
57+
"prettier": "^3.2.5",
5258
"typescript": "5.4.3"
5359
}
5460
}

packages/gnome-shell/scripts/config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { dirname, resolve } from 'path';
22
import { fileURLToPath } from 'url';
33

44
export const __dirname = globalThis.__dirname || dirname(fileURLToPath(import.meta.url));
5-
export const SRC_DIR = resolve(__dirname,'../src');
6-
export const DIST_DIR = resolve(__dirname,'../dist');
5+
export const SRC_DIR = resolve(__dirname, '../src');
6+
export const DIST_DIR = resolve(__dirname, '../dist');

packages/gnome-shell/scripts/generate-exports.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { loadJsonFile, writeJsonFile } from './utils/json.js';
55
import { DIST_DIR, __dirname } from './config.js';
66
import { resolve, extname, basename } from 'path';
77

8-
const IGNORE_FILENAMES = ['sharedInternals.d.ts', 'global.d.ts']
9-
const IGNORE_DIRS = ['types']
8+
const IGNORE_FILENAMES = ['sharedInternals.d.ts', 'global.d.ts'];
9+
const IGNORE_DIRS = ['types'];
1010

1111
/** */
1212
const generateExport = (filePath) => {
@@ -17,47 +17,47 @@ const generateExport = (filePath) => {
1717
const cjsJsPath = pathWithoutExtension + '.cjs';
1818
const ambientPath = pathWithoutExtension + '-ambient.d.ts';
1919

20-
if(IGNORE_FILENAMES.includes(fileName)) return;
21-
if(fileName.endsWith('ambient.d.ts')) return;
20+
if (IGNORE_FILENAMES.includes(fileName)) return;
21+
if (fileName.endsWith('ambient.d.ts')) return;
2222

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

2727
const exp = {};
2828

2929
exp[exportName] = {
3030
import: {
3131
types: `./dist${relativePath}`,
32-
default: `./dist${esmJsPath}`
32+
default: `./dist${esmJsPath}`,
3333
},
3434
require: {
3535
types: `./dist${relativePath}`,
36-
default: `./dist${cjsJsPath}`
37-
}
38-
}
36+
default: `./dist${cjsJsPath}`,
37+
},
38+
};
3939

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

42-
return exp
43-
}
42+
return exp;
43+
};
4444

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

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

5050
let exports = {
51-
"./extensions/global": "./dist/extensions/global.d.ts"
51+
'./extensions/global': './dist/extensions/global.d.ts',
5252
};
5353

5454
for (const absolutePath of typeFiles) {
55-
exports = { ...exports, ...generateExport(absolutePath) }
55+
exports = { ...exports, ...generateExport(absolutePath) };
5656
}
5757

5858
pkg.exports = exports;
5959

6060
writeJsonFile(resolve(__dirname, '../package.json'), pkg);
61-
}
61+
};
6262

6363
await start();

0 commit comments

Comments
 (0)