Skip to content

Commit a19598b

Browse files
authored
Merge pull request #402 from penge/esm
Use ES modules
2 parents 4dad263 + 97f9dbc commit a19598b

30 files changed

+5634
-3417
lines changed

.eslintignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
out/*
2-
jest.config.js
3-
build.js
4-
set-client-id.js
1+
dist/*
2+
jest.config.ts
3+
build.ts
4+
set-client-id.ts

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v2
1313
- uses: actions/setup-node@v2
1414
with:
15-
node-version: '16'
15+
node-version: 16
1616
- run: npm ci
1717
- run: npm run lint
1818
- run: npm run test

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.DS_Store
22
.vscode
33
node_modules/
4-
out/
4+
dist/

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<img src="https://badgen.net/github/license/penge/my-notes" />
66
<img src="https://badgen.net/chrome-web-store/users/lkeeogfaiembcblonahillacpaabmiop" />
77
<br><br>
8-
<img src="static/images/my-notes.png" width="760" /><br>
8+
<img src="public/images/my-notes.png" width="760" /><br>
99
<strong>My Notes</strong> – <a href="https://chrome.google.com/webstore/detail/my-notes/lkeeogfaiembcblonahillacpaabmiop">Chrome extension</a> for simple and fast note-taking
1010
</p>
1111

@@ -88,7 +88,7 @@ Custom theme allows you to customize My Notes styles in many ways.
8888

8989
To use a Custom theme, open Options, select **"Custom"** theme, and click on the **"Customize"** button to start creating your own theme.
9090

91-
To start, paste into the editor content of [<ins>light.css</ins>](static/themes/light.css) or [<ins>dark.css</ins>](static/themes/dark.css).
91+
To start, paste into the editor content of [<ins>light.css</ins>](public/themes/light.css) or [<ins>dark.css</ins>](public/themes/dark.css).
9292
Then, modify CSS variables as you like to change background colors, text colors, etc.
9393
You can add any valid CSS as well to make further changes.
9494
Click on the **"Save"** button to save the custom theme.
@@ -178,7 +178,7 @@ Develop:
178178
```
179179
$ npm install
180180
$ export MY_NOTES_CLIENT_ID=<CLIENT_ID> # needed when developing Google Drive Sync
181-
$ npm run develop-watch # see "out" folder
181+
$ npm run develop-watch # see "dist" folder
182182
```
183183

184184
`MY_NOTES_CLIENT_ID` can be created at [<ins>Google Cloud</ins>](https://console.cloud.google.com) / APIs & Services / Credentials / OAuth 2.0 Client IDs.
@@ -198,17 +198,17 @@ $ npm test
198198
Build:
199199

200200
```
201-
$ npm run build # see "out" folder
201+
$ npm run build # see "dist" folder
202202
```
203203

204204
<br><br>
205205

206206
## Folder structure
207207

208208
```
209-
env/ # Helpers for environment variables
209+
env/ # Environment helpers
210210
211-
out/ # Bundled My Notes (excluded from Git)
211+
dist/ # Bundled My Notes (excluded from Git)
212212
213213
src/
214214
background/
@@ -255,15 +255,15 @@ src/
255255
notes.ts # Main script for notes
256256
options.ts # Main script for options
257257
258-
static/ # All static files (images, icons, HTML, CSS) copied to out/
258+
public/ # All public files (images, icons, HTML, CSS) copied to dist/
259259
260260
261261
.editorconfig # To enforce same editor configuration
262262
.eslintrc # To enforce code quality and same coding style with ESLint
263263
.eslintignore # Files excluded from ESLint checking
264264
.gitignore # Files excluded from Git
265265
266-
jest.config.js # Jest configuration
266+
jest.config.ts # Jest configuration
267267
tsconfig.json # Typescript configuration
268268
269269
package-lock.json
@@ -272,6 +272,8 @@ package.json
272272
LICENSE # MIT
273273
manifest.json # Main extension file
274274
275+
build.ts # Produces /dist folder
276+
275277
README.md
276278
```
277279

@@ -334,7 +336,7 @@ After a successful review, the new version is available on Web Store.
334336

335337
Yes, My Notes can be installed manually by downloading it from GitHub, but keep in mind, that Google Drive Sync works only if My Notes is installed from [<ins>Web Store</ins>](https://chrome.google.com/webstore/detail/my-notes/lkeeogfaiembcblonahillacpaabmiop).
336338
To install My Notes manually, download the zip file of the latest version which you can find [<ins>here</ins>](https://github.com/penge/my-notes/releases). Then, unpack the downloaded file and install NPM packages followed by `npm run build`.
337-
Finally, open `chrome://extensions` address in Google Chrome and click the **"Load unpacked"** button to load the unpacked extension from your drive by selecting the `out` directory.
339+
Finally, open `chrome://extensions` address in Google Chrome and click the **"Load unpacked"** button to load the unpacked extension from your drive by selecting the `dist` folder.
338340

339341
<br>
340342

build.js renamed to build.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
require("esbuild").build({
1+
import esbuild from "esbuild";
2+
3+
esbuild.build({
24
entryPoints: [
35
"./src/background.ts",
46
"./src/notes.tsx",
57
"./src/options.tsx",
68
"./src/themes/custom/custom.tsx",
79
...(process.env.NODE_ENV === "development" ? ["./src/integration/index.ts"] : []),
810
],
11+
chunkNames: "chunks/[name]-[hash]",
912
bundle: true,
13+
outdir: "./dist",
14+
outExtension: { ".js": ".mjs" },
15+
splitting: true,
16+
format: "esm",
1017
define: {
1118
"process.env.LOG_LEVEL": '"ALL"',
1219
},
1320
loader: {
1421
".svg": "text",
1522
},
1623
minify: process.env.NODE_ENV === "production",
17-
outdir: "./out",
1824
sourcemap: process.env.NODE_ENV === "development" ? "inline" : false,
1925
logLevel: "info"
2026
});

env/set-client-id.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

env/set-client-id.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import fs from "fs";
2+
3+
(() => {
4+
const manifestPath = process.argv.slice(2)[0];
5+
if (!manifestPath) {
6+
return;
7+
}
8+
9+
const clientId = process.env.MY_NOTES_CLIENT_ID;
10+
if (!clientId) {
11+
return;
12+
}
13+
14+
const manifestContent = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
15+
manifestContent.oauth2.client_id = clientId;
16+
fs.writeFileSync(manifestPath, JSON.stringify(manifestContent, null, 2));
17+
})();
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
module.exports = {
1+
import type { Config } from "@jest/types";
2+
3+
const config: Config.InitialOptions = {
24
preset: "ts-jest",
35
testEnvironment: "jsdom",
46
testMatch: [
57
"**/__tests__/**/*.test.ts?(x)"
68
],
79
moduleDirectories: ["node_modules", "src"]
810
};
11+
12+
export default config;

manifest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
]
2828
},
2929
"background": {
30-
"service_worker": "background.js"
30+
"service_worker": "background.mjs",
31+
"type": "module"
3132
},
3233
"action": {
3334
"default_icon": "images/icon128.png"
@@ -42,6 +43,6 @@
4243
"description": "Open My Notes"
4344
}
4445
},
45-
"minimum_chrome_version": "88",
46+
"minimum_chrome_version": "92",
4647
"offline_enabled": true
4748
}

0 commit comments

Comments
 (0)