Skip to content

Commit

Permalink
overall qol changes, added workflows, manifest control and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mAmineChniti committed Mar 23, 2024
1 parent 76ba5cc commit 09cb72f
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 33 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
env: {
browser: true,
node: true,
es2021: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
overrides: [
{
files: ['.eslintrc.{js,cjs}'],
parserOptions: {
sourceType: 'script',
},
},
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
ignorePatterns: ['node_modules/', 'github-repo-size-extension/'],
rules: {},
};
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'weekly'
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Extension Build CI

on:
push:
branches: ['**']
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: |
bun install
- name: Build extension
run: |
bun run build
27 changes: 27 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Extension Format CI

on:
push:
branches: ['**']
pull_request:
branches: [main]

jobs:
format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: |
bun install
- name: Check code formatting
run: bun run checkFormat
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Extension Lint CI

on:
push:
branches: ['**']
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: bun install

- name: Check code linting
run: bun run lint
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
node_modules/
package-lock.json
pnpm-lock.yaml
bun.lockb
4 changes: 0 additions & 4 deletions .vscode/extensions.json

This file was deleted.

11 changes: 0 additions & 11 deletions .vscode/launch.json

This file was deleted.

22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ You can use Bun to quickly initialize a new project:
```bash
bun create catonaut [AppName]
```

OR

```bash
Expand All @@ -52,10 +53,10 @@ For more information, refer to [create-catonaut](https://github.com/AminoffZ/cre

![image](https://github.com/AminoffZ/catonaut/assets/55880031/261b38a7-09d5-417a-a908-807c29bf37fb)

Use the template or clone the project, navigate into the project folder and run:
Use the template, clone the project or use the create-catonaut command, navigate into the project folder and run:

```bash
bun i
bun install
```

### The manifest
Expand Down Expand Up @@ -174,6 +175,14 @@ To build the extension, run:
bun run build
```

Or

```bash
bun run build:firefox
```

This will build the extension in the dist folder.

## 🏗️ Project structure

<pre>
Expand Down Expand Up @@ -224,6 +233,15 @@ To format with the provided configuration, run:
bun run format
```

## 👕 Linting

There's an .eslintrc.cjs for the linting configuration.
To lint with the provided configuration, run:

```bash
bun run lint
```

## LICENSE

Catonaut is under [MIT License](https://github.com/AminoffZ/catonaut/blob/main/LICENSE).
4 changes: 2 additions & 2 deletions build-tools/create-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const filename = 'example.png';
* Sizes: 16, 32, 48, 128
*/
function createIcons() {
for (let size of [16, 32, 48, 128]) {
for (const size of [16, 32, 48, 128]) {
imagemagick.resize(
{
srcPath: `${root}${filename}`,
dstPath: `${root}icon${size}.png`,
width: size,
height: size,
},
(err, res) => {
(err /* ,res */) => {
if (err) throw err;
}
);
Expand Down
2 changes: 1 addition & 1 deletion build-tools/extract-inline.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* The purpose of this file is to remove inline scripts
* and styles from the HTML files generated by Astro.
* For more information, see:
* For more information, see:
* https://github.com/withastro/roadmap/discussions/377
*/

Expand Down
2 changes: 1 addition & 1 deletion build-tools/hash.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* This file is used to generate unique hashes for the
/* This file is used to generate unique hashes for the
* extracted inline scripts and styles.
* 🤓 will 😂
*/
Expand Down
Binary file modified bun.lockb
Binary file not shown.
32 changes: 20 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,37 @@
"name": "catonaut",
"module": "bundler.ts",
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "bun run manifest && astro build && cd build-tools && bun run csp && bun bundler.ts",
"build:firefox": "bun run manifest firefox && astro build && cd build-tools && bun run csp && bun bundler.ts firefox",
"preview": "astro preview",
"astro": "astro",
"csp": "bun -b extract-inline.ts",
"icons": "cd build-tools && bun create-icons.ts",
"manifest": "bun -b updateManifest.ts",
"format": "prettier --write .",
"check": "prettier --check .",
"lint": "eslint ."
},
"dependencies": {
"astro": "^3.2.1"
},
"devDependencies": {
"@types/chrome": "^0.0.246",
"@types/imagemagick": "^0.0.33",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"bun-types": "latest",
"chalk": "4.1.2",
"eslint": "^8.57.0",
"imagemagick": "^0.1.3",
"prettier": "^3.0.3",
"tiny-glob": "^0.2.9"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build && cd build-tools && bun run csp && bun bundler.ts",
"preview": "astro preview",
"astro": "astro",
"format": "prettier --write '**/*.{js,jsx,ts,tsx,json,md}' '!build/**' '!node_modules/**'",
"csp": "bun extract-inline.ts",
"icons": "cd build-tools && bun create-icons.ts"
},
"type": "module"
}
}
50 changes: 50 additions & 0 deletions updateManifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { join } from 'path';
import { readFile, writeFile } from 'fs/promises';
import chalk from 'chalk';

export async function updateManifest() {
try {
const arg = process.argv[2];
const browser = arg && arg === 'firefox' ? 'firefox' : 'chrome';

const packageJsonPath = join(import.meta.dir, 'package.json');
const { version } = await import(packageJsonPath);

const manifestPath = join(import.meta.dir, 'public', 'manifest.json');
const manifestData = await readFile(manifestPath, 'utf-8');
const manifest = JSON.parse(manifestData);

manifest.version = version;

if (browser && browser === 'firefox') {
manifest.background = {
scripts: ['background.js'],
};

manifest.browser_specific_settings = {
gecko: {
id: 'github-repo-size@gmail.com',
strict_min_version: '42.0',
},
};
} else {
manifest.background = {
service_worker: 'background.js',
};
delete manifest.browser_specific_settings;
}
await writeFile(manifestPath, JSON.stringify(manifest, null, 2));

console.log(
chalk.green(
'Version updated successfully in manifest.json for ' +
browser +
' Browser!'
)
);
} catch (error) {
console.error(chalk.red('Error updating version: ' + error));
process.exit(1);
}
}
updateManifest();

0 comments on commit 09cb72f

Please sign in to comment.