Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update dev and build process and improvements #560

Merged
merged 17 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
- name: Install modules
run: npm install
- name: Run ESLint
run: npm run lint-js
run: npm run lint:js
- name: Run Stylelint
run: npm run lint-css
run: npm run lint:css
14 changes: 14 additions & 0 deletions entry-app-webview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self'"> -->
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="color-scheme" content="dark">
<title>Userscripts App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/app/main.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion entry-popup.html → entry-ext-action-popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
<body>
<noscript>Please enable Javascript to use this app</noscript>
<div id="app"></div>
<script type="module" src="/src/popup/main.js"></script>
<script type="module" src="/src/ext/action-popup/main.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions entry-page.html → entry-ext-extension-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>
<noscript>Please enable Javascript to use this app</noscript>
<div id="app"></div>
<script type="module" src="/src/page/main.js"></script>
<script src="/page/jshint.min.js"></script>
<script type="module" src="/src/ext/extension-page/main.js"></script>
<script src="extension-page/jshint.min.js"></script>
</body>
</html>
Binary file removed etc/App-iOS-WebView.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
<script type="module" src="/src/dev/main.js"></script>
<script>
function notice() {
if (!app.hasChildNodes()) {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint-js": "eslint ./",
"lint-css": "stylelint '**/*.{css,svelte}'"
"build": "pnpm build:app && pnpm build:ext",
"build:app": "node scripts/build-app.js",
"build:ext": "node scripts/build-ext-v4.js",
"lint:js": "eslint ./",
"lint:css": "stylelint '**/*.{css,svelte}'"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.4.3",
Expand Down
File renamed without changes.
36 changes: 36 additions & 0 deletions scripts/build-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @file Build App WebView resources using the Vite JavaScript API
* @see {@link https://vitejs.dev/guide/api-javascript.html|JavaScript API}
*
* All build processes start at the same time due to asynchronous calls
* The assets name is irrelevant, just need to determine the entry path
*/

import {build} from "vite";
import {svelte} from "@sveltejs/vite-plugin-svelte";

/**
* Define default vite config options
* Disable auto resolving {@link vite.config.js}
* @see {@link https://vitejs.dev/config/|Config}
* @see {@link https://vitejs.dev/guide/api-javascript.html#inlineconfig|configFile}
*/
const defineConfig = {
base: "./",
configFile: false
};

/**
* Build App-Shared WebView resources to xcode dist
*/
build({
...defineConfig,
plugins: [svelte()],
build: {
outDir: "xcode/App-Shared/Resources/dist/",
copyPublicDir: false,
rollupOptions: {
input: "entry-app-webview.html"
}
}
});
72 changes: 72 additions & 0 deletions scripts/build-ext-v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* @file Build Safari extension resources using the Vite JavaScript API
* @see {@link https://vitejs.dev/guide/api-javascript.html|JavaScript API}
ACTCD marked this conversation as resolved.
Show resolved Hide resolved
*
* Safari supports for modules in background since 16.4
* @see {@link https://developer.apple.com/documentation/safari-release-notes/safari-16_4-release-notes#Safari-Extensions}
* @see {@link https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/background#browser_compatibility}
* To ensure forward compatibility, background script use independent builds in v4
*
* Content scripts not support import modules, and due to their privileges and the
* speed of injecting user scripts, use a independent build currently
*
* All build processes start at the same time due to asynchronous calls
* The assets name is irrelevant, just need to determine the entry path
*/

import {build} from "vite";
import {svelte} from "@sveltejs/vite-plugin-svelte";

/**
* Define default vite config options
* Disable auto resolving {@link vite.config.js}
* @see {@link https://vitejs.dev/config/|Config}
* @see {@link https://vitejs.dev/guide/api-javascript.html#inlineconfig|configFile}
*/
const defineConfig = {
base: "./",
configFile: false
};

/**
* Build shared modules for safari
* These multiple entry files will share the same modules
* Using a subdirectory avoid emptying other built files
*/
build({
...defineConfig,
plugins: [svelte()],
build: {
outDir: "xcode/Ext-Safari/Resources/dist/s/",
rollupOptions: {
input: [
"entry-ext-action-popup.html",
"entry-ext-extension-page.html"
]
}
}
});

/**
* Build independent scripts for safari
* Each entry in the array will generate a separate script
*/
[
{background: "src/ext/background/main.js"},
{content: "src/ext/content-scripts/main.js"}
].forEach(input => {
build({
...defineConfig,
build: {
outDir: "xcode/Ext-Safari/Resources/dist/",
emptyOutDir: false,
copyPublicDir: false,
rollupOptions: {
input,
output: {
entryFileNames: "[name].js"
}
}
}
});
});
74 changes: 74 additions & 0 deletions scripts/build-ext-v5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @file Build Safari extension resources using the Vite JavaScript API
* @see {@link https://vitejs.dev/guide/api-javascript.html|JavaScript API}
ACTCD marked this conversation as resolved.
Show resolved Hide resolved
*
* Safari supports for modules in background since 16.4
* @see {@link https://developer.apple.com/documentation/safari-release-notes/safari-16_4-release-notes#Safari-Extensions}
* @see {@link https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/background#browser_compatibility}
*
* Content scripts not support import modules, and due to their privileges and the
* speed of injecting user scripts, use a independent build currently
*
* All build processes start at the same time due to asynchronous calls
* The assets name is irrelevant, just need to determine the entry path
*/

import {build} from "vite";
import {svelte} from "@sveltejs/vite-plugin-svelte";

/**
* Define default vite config options
* Disable auto resolving {@link vite.config.js}
* @see {@link https://vitejs.dev/config/|Config}
* @see {@link https://vitejs.dev/guide/api-javascript.html#inlineconfig|configFile}
*/
const defineConfig = {
base: "./",
configFile: false
};

/**
* Build shared modules for safari
* These multiple entry files will share the same modules
* Using a subdirectory avoid emptying other built files
*/
build({
...defineConfig,
plugins: [svelte()],
build: {
outDir: "xcode/Ext-Safari/Resources/dist/s/",
rollupOptions: {
input: {
background: "src/ext/background/main.js",
"action-popup": "entry-ext-action-popup.html",
"extension-page": "entry-ext-extension-page.html"
},
output: {
entryFileNames: "[name].js"
}
}
}
});

/**
* Build independent scripts for safari
* Each entry in the array will generate a separate script
*/
[
{content: "src/ext/content-scripts/main.js"}
].forEach(input => {
build({
...defineConfig,
build: {
outDir: "xcode/Ext-Safari/Resources/dist/",
emptyOutDir: false,
copyPublicDir: false,
rollupOptions: {
input,
output: {
entryFileNames: "[name].js"
}
}
}
});
});
34 changes: 34 additions & 0 deletions scripts/preview-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @file Preview App WebView resources using the Vite JavaScript API
* @see {@link https://vitejs.dev/guide/api-javascript.html|JavaScript API}
*/

import {preview} from "vite";

/**
* Define default vite config options
* Disable auto resolving {@link vite.config.js}
* @see {@link https://vitejs.dev/config/|Config}
* @see {@link https://vitejs.dev/guide/api-javascript.html#inlineconfig|configFile}
*/
const defineConfig = {
base: "./",
configFile: false
};

/**
* Preview App-Shared WebView resources from xcode dist
*/
(async () => {
const previewServer = await preview({
...defineConfig,
preview: {
// port: 4173,
open: "entry-app-webview.html"
},
build: {
outDir: "xcode/App-Shared/Resources/dist/"
}
});
previewServer.printUrls();
})();
Loading
Loading