feat(build): refactor gulpfile to use gulp-execa (#323)
* feat(build): refactor gulpfile to use gulp-execa * chore: fix PR comments * chore(deps): update deps
This commit is contained in:
107
gulpfile.js
107
gulpfile.js
@@ -1,48 +1,93 @@
|
|||||||
// (Thanks go to https://github.com/pnd280/complexity/blob/alpha/gulpfile.js)
|
import chalk from 'chalk';
|
||||||
|
|
||||||
import cp from 'child_process';
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import gulp from 'gulp';
|
import { dest, series, src } from 'gulp';
|
||||||
import gulpZip from 'gulp-zip';
|
import { exec } from 'gulp-execa';
|
||||||
import { createRequire } from 'module';
|
import zip from 'gulp-zip';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
const DIST_DIR = 'dist';
|
||||||
|
const PACKAGE_DIR = 'package';
|
||||||
|
const DATABASE_DIR = path.join(DIST_DIR, 'database');
|
||||||
|
|
||||||
|
// Custom log functions
|
||||||
|
const log = message => console.log(chalk.blue(`[${new Date().toTimeString().split(' ')[0]}]`), chalk.white(message));
|
||||||
|
const logWarn = message =>
|
||||||
|
console.warn(
|
||||||
|
chalk.blue(`[${new Date().toTimeString().split(' ')[0]}]`),
|
||||||
|
chalk.yellow(' [WARN]'),
|
||||||
|
chalk.white(message)
|
||||||
|
);
|
||||||
|
const logError = message =>
|
||||||
|
console.error(
|
||||||
|
chalk.blue(`[${new Date().toTimeString().split(' ')[0]}]`),
|
||||||
|
chalk.red(' [ERROR]'),
|
||||||
|
chalk.white(message)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Remove extra database folder
|
||||||
|
function removeExtraDatabaseDir(cb) {
|
||||||
|
fs.rmSync(DATABASE_DIR, { recursive: true, force: true });
|
||||||
|
log('Extra database directory removed.');
|
||||||
|
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Instrument with Sentry
|
||||||
// Make sure sentry is configured https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/typescript/#2-configure-sentry-cli
|
// Make sure sentry is configured https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/typescript/#2-configure-sentry-cli
|
||||||
function instrumentWithSentry() {
|
async function instrumentWithSentry(cb) {
|
||||||
return cp.exec('sentry-cli sourcemaps inject dist/ && sentry-cli sourcemaps upload dist/');
|
await exec(`sentry-cli sourcemaps inject ${DIST_DIR}`);
|
||||||
|
await exec(`sentry-cli sourcemaps upload ${DIST_DIR}`);
|
||||||
|
log('Sentry instrumentation completed.');
|
||||||
|
|
||||||
|
cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zip the dist folder
|
||||||
function zipDist() {
|
function zipDist() {
|
||||||
const require = createRequire(import.meta.url);
|
const packageInfo = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
||||||
const manifest = require('./package.json');
|
const zipFileName = `${packageInfo.name.replace(/ /g, '-')}-${packageInfo.version}.zip`;
|
||||||
const zipFileName = `${manifest.name.replaceAll(' ', '-')}-${manifest.version}.zip`;
|
|
||||||
|
|
||||||
return gulp
|
return src(`${DIST_DIR}/**`, {
|
||||||
.src('dist/**', {
|
base: DIST_DIR,
|
||||||
encoding: false,
|
encoding: false, // Disable encoding to handle binary files correctly
|
||||||
})
|
})
|
||||||
.pipe(gulpZip(zipFileName))
|
.pipe(zip(zipFileName))
|
||||||
.pipe(gulp.dest('package'));
|
.pipe(dest(PACKAGE_DIR))
|
||||||
|
.on('end', () => log(`Zip file created: ${path.join(PACKAGE_DIR, zipFileName)}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
const zip = gulp.series(instrumentWithSentry, zipDist);
|
|
||||||
|
|
||||||
// Temp fix for CSP on Chrome 130
|
// Temp fix for CSP on Chrome 130
|
||||||
// Manually remove them because there is no option to disable use_dynamic_url on @crxjs/vite-plugin
|
// Manually remove them because there is no option to disable use_dynamic_url on @crxjs/vite-plugin
|
||||||
function forceDisableUseDynamicUrl(done) {
|
// Force disable use_dynamic_url in manifest.json
|
||||||
const require = createRequire(import.meta.url);
|
function forceDisableUseDynamicUrl(cb) {
|
||||||
const manifest = require('./dist/manifest.json');
|
const manifestPath = path.join(DIST_DIR, 'manifest.json');
|
||||||
|
|
||||||
manifest.web_accessible_resources.forEach(resource => {
|
if (!fs.existsSync(manifestPath)) {
|
||||||
delete resource.use_dynamic_url;
|
logWarn('manifest.json not found. Skipping modification.');
|
||||||
});
|
return cb();
|
||||||
|
|
||||||
if (!fs.existsSync('./dist/manifest.json')) {
|
|
||||||
return done();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync('./dist/manifest.json', JSON.stringify(manifest, null, 2));
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
||||||
|
let modified = false;
|
||||||
|
|
||||||
done();
|
manifest.web_accessible_resources.forEach(resource => {
|
||||||
|
if (resource.use_dynamic_url) {
|
||||||
|
delete resource.use_dynamic_url;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (modified) {
|
||||||
|
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
||||||
|
log('use_dynamic_url removed from manifest.json');
|
||||||
|
} else {
|
||||||
|
log('No use_dynamic_url found in manifest.json. No changes made.');
|
||||||
|
}
|
||||||
|
|
||||||
|
cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
export { forceDisableUseDynamicUrl, zip };
|
// Main build task
|
||||||
|
const zipProdBuild = series(removeExtraDatabaseDir, instrumentWithSentry, zipDist);
|
||||||
|
|
||||||
|
export { forceDisableUseDynamicUrl, zipProdBuild };
|
||||||
|
|||||||
80
package.json
80
package.json
@@ -10,7 +10,7 @@
|
|||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"build:watch": "NODE_ENV='development' vite build --mode development -w",
|
"build:watch": "NODE_ENV='development' vite build --mode development -w",
|
||||||
"zip": "PROD=true pnpm build && pnpm gulp zip",
|
"zip": "PROD=true pnpm build && pnpm gulp zipProdBuild",
|
||||||
"prettier": "prettier src --check",
|
"prettier": "prettier src --check",
|
||||||
"prettier:fix": "prettier src --write",
|
"prettier:fix": "prettier src --write",
|
||||||
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives",
|
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives",
|
||||||
@@ -27,12 +27,12 @@
|
|||||||
"prepare": "husky"
|
"prepare": "husky"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@headlessui/react": "^2.1.10",
|
"@headlessui/react": "^2.2.0",
|
||||||
"@hello-pangea/dnd": "^17.0.0",
|
"@hello-pangea/dnd": "^17.0.0",
|
||||||
"@octokit/rest": "^21.0.2",
|
"@octokit/rest": "^21.0.2",
|
||||||
"@sentry/react": "^8.34.0",
|
"@sentry/react": "^8.36.0",
|
||||||
"@unocss/vite": "^0.63.4",
|
"@unocss/vite": "^0.63.6",
|
||||||
"@vitejs/plugin-react": "^4.3.2",
|
"@vitejs/plugin-react": "^4.3.3",
|
||||||
"chrome-extension-toolkit": "^0.0.54",
|
"chrome-extension-toolkit": "^0.0.54",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"conventional-changelog": "^6.0.0",
|
"conventional-changelog": "^6.0.0",
|
||||||
@@ -41,14 +41,14 @@
|
|||||||
"html-to-image": "^1.11.11",
|
"html-to-image": "^1.11.11",
|
||||||
"husky": "^9.1.6",
|
"husky": "^9.1.6",
|
||||||
"kc-dabr-wasm": "^0.1.2",
|
"kc-dabr-wasm": "^0.1.2",
|
||||||
"nanoid": "^5.0.7",
|
"nanoid": "^5.0.8",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-loading-skeleton": "^3.5.0",
|
"react-loading-skeleton": "^3.5.0",
|
||||||
"react-markdown": "^9.0.1",
|
"react-markdown": "^9.0.1",
|
||||||
"react-syntax-highlighter": "^15.5.0",
|
"react-syntax-highlighter": "^15.6.1",
|
||||||
"remark-gfm": "^4.0.0",
|
"remark-gfm": "^4.0.0",
|
||||||
"sass": "^1.79.5",
|
"sass": "^1.80.6",
|
||||||
"simple-git": "^3.27.0",
|
"simple-git": "^3.27.0",
|
||||||
"sql.js": "1.11.0"
|
"sql.js": "1.11.0"
|
||||||
},
|
},
|
||||||
@@ -59,27 +59,27 @@
|
|||||||
"@commitlint/types": "^19.5.0",
|
"@commitlint/types": "^19.5.0",
|
||||||
"@crxjs/vite-plugin": "2.0.0-beta.21",
|
"@crxjs/vite-plugin": "2.0.0-beta.21",
|
||||||
"@iconify-json/bi": "^1.2.1",
|
"@iconify-json/bi": "^1.2.1",
|
||||||
"@iconify-json/iconoir": "^1.2.2",
|
"@iconify-json/iconoir": "^1.2.3",
|
||||||
"@iconify-json/material-symbols": "^1.2.4",
|
"@iconify-json/material-symbols": "^1.2.6",
|
||||||
"@iconify-json/ri": "^1.2.1",
|
"@iconify-json/ri": "^1.2.3",
|
||||||
"@semantic-release/exec": "^6.0.3",
|
"@semantic-release/exec": "^6.0.3",
|
||||||
"@sentry/types": "^8.34.0",
|
"@sentry/types": "^8.36.0",
|
||||||
"@storybook/addon-designs": "^8.0.3",
|
"@storybook/addon-designs": "^8.0.4",
|
||||||
"@storybook/addon-essentials": "^8.3.5",
|
"@storybook/addon-essentials": "^8.4.1",
|
||||||
"@storybook/addon-links": "^8.3.5",
|
"@storybook/addon-links": "^8.4.1",
|
||||||
"@storybook/blocks": "^8.3.5",
|
"@storybook/blocks": "^8.4.1",
|
||||||
"@storybook/react": "^8.3.5",
|
"@storybook/react": "^8.4.1",
|
||||||
"@storybook/react-vite": "^8.3.5",
|
"@storybook/react-vite": "^8.4.1",
|
||||||
"@storybook/test": "^8.3.5",
|
"@storybook/test": "^8.4.1",
|
||||||
"@svgr/core": "^8.1.0",
|
"@svgr/core": "^8.1.0",
|
||||||
"@svgr/plugin-jsx": "^8.1.0",
|
"@svgr/plugin-jsx": "^8.1.0",
|
||||||
"@types/chrome": "^0.0.273",
|
"@types/chrome": "^0.0.273",
|
||||||
"@types/conventional-changelog": "^3.1.5",
|
"@types/conventional-changelog": "^3.1.5",
|
||||||
"@types/gulp": "^4.0.17",
|
"@types/gulp": "^4.0.17",
|
||||||
"@types/gulp-zip": "^4.0.4",
|
"@types/gulp-zip": "^4.0.4",
|
||||||
"@types/node": "^22.7.5",
|
"@types/node": "^22.8.7",
|
||||||
"@types/prompts": "^2.4.9",
|
"@types/prompts": "^2.4.9",
|
||||||
"@types/react": "^18.3.11",
|
"@types/react": "^18.3.12",
|
||||||
"@types/react-dom": "^18.3.1",
|
"@types/react-dom": "^18.3.1",
|
||||||
"@types/react-syntax-highlighter": "^15.5.13",
|
"@types/react-syntax-highlighter": "^15.5.13",
|
||||||
"@types/semantic-release": "^20.0.6",
|
"@types/semantic-release": "^20.0.6",
|
||||||
@@ -87,20 +87,21 @@
|
|||||||
"@types/sql.js": "^1.4.9",
|
"@types/sql.js": "^1.4.9",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
||||||
"@typescript-eslint/parser": "^7.18.0",
|
"@typescript-eslint/parser": "^7.18.0",
|
||||||
"@unocss/eslint-config": "^0.63.4",
|
"@unocss/eslint-config": "^0.63.6",
|
||||||
"@unocss/postcss": "^0.63.4",
|
"@unocss/postcss": "^0.63.6",
|
||||||
"@unocss/preset-uno": "^0.63.4",
|
"@unocss/preset-uno": "^0.63.6",
|
||||||
"@unocss/preset-web-fonts": "^0.63.4",
|
"@unocss/preset-web-fonts": "^0.63.6",
|
||||||
"@unocss/reset": "^0.63.4",
|
"@unocss/reset": "^0.63.6",
|
||||||
"@unocss/transformer-directives": "^0.63.4",
|
"@unocss/transformer-directives": "^0.63.6",
|
||||||
"@unocss/transformer-variant-group": "^0.63.4",
|
"@unocss/transformer-variant-group": "^0.63.6",
|
||||||
"@vitejs/plugin-react-swc": "^3.7.1",
|
"@vitejs/plugin-react-swc": "^3.7.1",
|
||||||
"@vitest/coverage-v8": "^2.1.2",
|
"@vitest/coverage-v8": "^2.1.4",
|
||||||
"@vitest/ui": "^2.1.2",
|
"@vitest/ui": "^2.1.4",
|
||||||
"chalk": "^5.3.0",
|
"chalk": "^5.3.0",
|
||||||
"chromatic": "^11.12.5",
|
"chromatic": "^11.16.5",
|
||||||
"cssnano": "^7.0.6",
|
"cssnano": "^7.0.6",
|
||||||
"cssnano-preset-advanced": "^7.0.6",
|
"cssnano-preset-advanced": "^7.0.6",
|
||||||
|
"del": "^8.0.0",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"es-module-lexer": "^1.5.4",
|
"es-module-lexer": "^1.5.4",
|
||||||
"eslint": "^8.57.1",
|
"eslint": "^8.57.1",
|
||||||
@@ -111,29 +112,30 @@
|
|||||||
"eslint-import-resolver-typescript": "^3.6.3",
|
"eslint-import-resolver-typescript": "^3.6.3",
|
||||||
"eslint-plugin-import": "^2.31.0",
|
"eslint-plugin-import": "^2.31.0",
|
||||||
"eslint-plugin-import-essentials": "^0.2.1",
|
"eslint-plugin-import-essentials": "^0.2.1",
|
||||||
"eslint-plugin-jsdoc": "^50.3.2",
|
"eslint-plugin-jsdoc": "^50.4.3",
|
||||||
"eslint-plugin-prettier": "^5.2.1",
|
"eslint-plugin-prettier": "^5.2.1",
|
||||||
"eslint-plugin-react": "^7.37.1",
|
"eslint-plugin-react": "^7.37.2",
|
||||||
"eslint-plugin-react-hooks": "^4.6.2",
|
"eslint-plugin-react-hooks": "^4.6.2",
|
||||||
"eslint-plugin-react-prefer-function-component": "^3.3.0",
|
"eslint-plugin-react-prefer-function-component": "^3.3.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.12",
|
"eslint-plugin-react-refresh": "^0.4.14",
|
||||||
"eslint-plugin-simple-import-sort": "^12.1.1",
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||||
"eslint-plugin-storybook": "^0.9.0",
|
"eslint-plugin-storybook": "^0.9.0",
|
||||||
"gulp": "^5.0.0",
|
"gulp": "^5.0.0",
|
||||||
|
"gulp-execa": "^7.0.1",
|
||||||
"gulp-zip": "^6.0.0",
|
"gulp-zip": "^6.0.0",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"postcss": "^8.4.47",
|
"postcss": "^8.4.47",
|
||||||
"prettier": "^3.3.3",
|
"prettier": "^3.3.3",
|
||||||
"react-dev-utils": "^12.0.1",
|
"react-dev-utils": "^12.0.1",
|
||||||
"semantic-release": "^24.1.2",
|
"semantic-release": "^24.2.0",
|
||||||
"storybook": "^8.3.5",
|
"storybook": "^8.4.1",
|
||||||
"typescript": "^5.6.3",
|
"typescript": "^5.6.3",
|
||||||
"unocss": "^0.63.4",
|
"unocss": "^0.63.6",
|
||||||
"unocss-preset-primitives": "0.0.2-beta.1",
|
"unocss-preset-primitives": "0.0.2-beta.1",
|
||||||
"unplugin-icons": "^0.19.3",
|
"unplugin-icons": "^0.19.3",
|
||||||
"vite": "^5.4.8",
|
"vite": "^5.4.10",
|
||||||
"vite-plugin-inspect": "^0.8.7",
|
"vite-plugin-inspect": "^0.8.7",
|
||||||
"vitest": "^2.1.2"
|
"vitest": "^2.1.4"
|
||||||
},
|
},
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"patchedDependencies": {
|
"patchedDependencies": {
|
||||||
|
|||||||
3822
pnpm-lock.yaml
generated
3822
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user