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

soffit-pwa #658

Merged
merged 22 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
66cb5c0
feat(uniquely/soffit-site-pwa): new app
MM25Zamanian Jan 15, 2023
fe9944d
feat(tsconfig): uniquely/soffit-site-pwa
MM25Zamanian Jan 15, 2023
e13e319
feat(ui-kit/icon-box): new component
MM25Zamanian Jan 16, 2023
9fceafe
feat(uniquely/soffit-site-pwa): use `alwatr-icon-box` & remove extras
MM25Zamanian Jan 16, 2023
e187b8a
fix(ui-kit/icon-box): empty & linkable width
MM25Zamanian Jan 16, 2023
5eb959d
fix(uniquely/soffit-site-pwa/page-home): incorrect import
MM25Zamanian Jan 16, 2023
eca14c8
feat(uniquely/soffit-site-pwa): `alwatr-icon-box` description
MM25Zamanian Jan 17, 2023
4d11e08
feat(uniquely/soffit-site-pwa): scroll bar
MM25Zamanian Jan 17, 2023
0ca4028
refactor(uniquely/soffit-site-pwa): build with esbuild
MM25Zamanian Jan 18, 2023
8226ec0
feat(soffit-pwa): use demo-pwa esbuild
alimd Jan 18, 2023
7217dd1
chore(demo-pwa): enhance log
alimd Jan 18, 2023
692ab2a
refactor(soffit-pwa): use _initLocale
alimd Jan 18, 2023
9c3aef8
feat(icon-box): respect breaks in desc
alimd Jan 18, 2023
a144886
chore(ui): cleanup old icon-box
alimd Jan 18, 2023
9359616
feat(soffit-pwa): make transparent logo
alimd Jan 18, 2023
9439f87
fix(soffit-pwa): build issue
alimd Jan 18, 2023
b26d1f4
feat(soffit-pwa): dynamic menu
alimd Jan 18, 2023
dc1eaa4
fix(soffit-pwa): review and fix root element
alimd Jan 18, 2023
a94ca31
feat(ui): add palette 260 and 270
alimd Jan 18, 2023
46ee93e
fix(icon): fetch timeout
alimd Jan 18, 2023
83ff766
fix(icon-box): optional description
alimd Jan 18, 2023
7b3adb4
feat(soffit-pwa): improve style
alimd Jan 18, 2023
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
Prev Previous commit
Next Next commit
refactor(uniquely/soffit-site-pwa): build with esbuild
  • Loading branch information
MM25Zamanian authored and alimd committed Jan 18, 2023
commit 0ca402856fc467f077f9ab262b9c2a1a005d34ca
44 changes: 0 additions & 44 deletions uniquely/soffit-site-pwa/CHANGELOG.md

This file was deleted.

144 changes: 144 additions & 0 deletions uniquely/soffit-site-pwa/esbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/usr/bin/env node
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/explicit-function-return-type */

import {promises as fs, existsSync} from 'node:fs';

import {createLogger} from '@alwatr/logger';
import * as esbuild from 'esbuild';

import packageJson from './package.json' assert {type: 'json'};

const logger = createLogger('alwatr-pwa-build');
const banner = '/* ..:: Alwatr UI Demo ::.. */\n';

const srcDir = 'src';
const resDir = 'res';
const outDir = 'dist';
const srcFilename = 'alwatr-pwa';

const cleanMode = process.argv.includes('--clean');
const watchMode = process.argv.includes('--watch');
const debugMode = process.argv.includes('--debug');

logger.logOther(banner);

logger.logProperty('cleanMode', cleanMode);
logger.logProperty('watchMode', watchMode);
logger.logProperty('debugMode', debugMode);

if (cleanMode) {
logger.logMethod('clean build');
await fs.rm(outDir, {recursive: true, force: true});
}

const copyPromise = fs.cp(resDir, outDir, {recursive: true, force: true, verbatimSymlinks: true});

const esBuild = esbuild.build({
entryPoints: [`${srcDir}/${srcFilename}.ts`],

logLevel: 'info',
platform: 'browser',
target: 'es2018',
format: 'esm',
conditions: debugMode ? ['development'] : undefined,

minify: true,
treeShaking: true,
sourcemap: true,
sourcesContent: debugMode,
bundle: true,
splitting: true,
charset: 'ascii',
legalComments: 'none',
metafile: true,

define: {
_ALWATR_VERSION_: `'${packageJson.version}'`,
},
// drop: ['debugger'],

loader: {
'.png': 'copy',
'.jpg': 'copy',
'.woff': 'copy',
'.woff2': 'copy',
},

banner: {
js: banner,
css: banner,
},

outbase: srcDir,
outdir: outDir,
assetNames: 'asset/[name]-[hash]',
entryNames: watchMode ? '[name]' : '[dir]/[name]-[hash]',
chunkNames: 'chunks/[name]-[hash]',

incremental: watchMode,
watch: watchMode,
});

async function makeHtml() {
logger.logMethod('makeHtml');

let htmlContent = await fs.readFile(`${resDir}/index.html`, {encoding: 'utf-8'});

const metafile = (await esBuild).metafile;
const outFiles = Object.keys(metafile.outputs);

const jsFilename = outFiles
.find((filename) => filename.includes(srcFilename) && filename.endsWith('.js'))
.substring(outDir.length + 1);

const cssFilename = outFiles
.find((filename) => filename.includes(srcFilename) && filename.endsWith('.css'))
.substring(outDir.length + 1);

logger.logProperty('jsFilename', jsFilename);
logger.logProperty('cssFilename', cssFilename);

if (!existsSync(`${outDir}/${jsFilename}`)) {
logger.error('makeHtml', 'js_filename_not_found', {jsFilename});
throw new Error('js_filename_not_found');
}

if (!existsSync(`${outDir}/${cssFilename}`)) {
logger.error('makeHtml', 'css_filename_not_found', {cssFilename});
throw new Error('css_filename_not_found');
}

htmlContent = htmlContent
.replace('alwatr-pwa.css', cssFilename)
.replace('alwatr-pwa.js', jsFilename)
;

await copyPromise; // wait to cp done
await fs.writeFile(`${outDir}/index.html`, htmlContent, {encoding: 'utf-8', flag: 'w'});
}

if (!watchMode) {
makeHtml();
}

if (debugMode) {
console.log(await esbuild.analyzeMetafile((await esBuild).metafile));
}

/*
TODO:
- Assets hash
- PostCSS css file
- lit css loader
- PostCSS lit internal styles
- Dynamic from @alwatr/build
- sideEffects
https://esbuild.github.io/api/#ignore-annotations
https://webpack.js.org/guides/tree-shaking/
- readme
https://esbuild.github.io/api/#write
https://github.com/fakundo/esbuild-plugin-replace-regex/blob/master/src/index.js#L30
https://github.com/zandaqo/esbuild-plugin-lit/blob/master/css-loader.ts
https://github.com/chialab/rna/tree/main/packages/esbuild-plugin-html
*/
30 changes: 8 additions & 22 deletions uniquely/soffit-site-pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,26 @@
"directory": "ui/soffit-site-pwa"
},
"scripts": {
"b": "yarn build",
"cb": "run-s clean build",
"b": "yarn build --debug",
"cb": "yarn build --debug --clean",
"s": "yarn start",
"w": "yarn watch",
"start": "NODE_OPTIONS=--enable-source-maps run-s clean build serve",
"clean": "rimraf dist build .tsbuildinfo **/*.{d.ts,map} src/**/*.{js,cjs,mjs}",
"build": "run-s build:ts build:es",
"build:ts": "tsc --build",
"build:es": "rimraf dist && rollup -c",
"clean": "rimraf dist build .tsbuildinfo",
"build": "./esbuild.mjs",
"build:tsc": "tsc --build",
"serve": "wds",
"watch": "run-s clean build:ts && run-p watch:ts serve",
"watch:ts": "yarn build:ts --watch --preserveWatchOutput"
"watch": "run-p watch:es serve",
"watch:es": "yarn build --clean --watch --debug"
},
"devDependencies": {
"@alwatr/element": "^0.27.0",
"@alwatr/ui-kit": "^0.27.0",
"@babel/core": "^7.20.12",
"@babel/preset-env": "^7.20.2",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.3.0",
"@web/dev-server": "^0.1.35",
"@web/dev-server-esbuild": "^0.3.3",
"@web/rollup-plugin-copy": "^0.3.0",
"@web/rollup-plugin-html": "^1.11.0",
"@web/rollup-plugin-polyfills-loader": "^1.3.1",
"@webcomponents/webcomponentsjs": "^2.7.0",
"lit-analyzer": "^1.2.1",
"npm-run-all": "^4.1.5",
"rimraf": "^4.0.4",
"rollup": "^3.10.0",
"rollup-plugin-minify-html-literals": "^1.2.6",
"rollup-plugin-summary": "^2.0.0",
"rollup-plugin-workbox": "^6.2.0",
"rimraf": "^4.1.0",
"ts-lit-plugin": "^1.2.1",
"tslib": "^2.4.1",
"typescript": "^4.9.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@
<meta charset="utf-8" />
<title>بازرگانی سافیت</title>

<link
crossorigin
media="print"
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@alwatr/[email protected]/vazirmatn.min.css"
onload="this.media='all';this.onload=null;"
/>
<link rel="stylesheet" href="style/index.css" />
<link rel="stylesheet" href="alwatr-pwa.css" />
<script type="module" src="alwatr-pwa.js"></script>

<meta name="color-scheme" content="light dark" />
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#673ab7" />
Expand Down
78 changes: 0 additions & 78 deletions uniquely/soffit-site-pwa/rollup.config.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {AlwatrRootElement, html, customElement} from '@alwatr/element';
import {html, customElement} from '@alwatr/element';
import {AlwatrPwaElement} from '@alwatr/element/pwa-element.js';
import {l10n} from '@alwatr/i18n';

import '@alwatr/ui-kit/style/theme/palette-300.css';
import '@alwatr/ui-kit/style/theme/color.css';
import '@alwatr/font/vazirmatn.css';

import './page-home.js';

import type {PropertyValues} from '@alwatr/element';
Expand All @@ -16,7 +21,7 @@ declare global {
* Alwatr PWA Root Element
*/
@customElement('alwatr-pwa-root')
export class AlwatrPwaRoot extends AlwatrRootElement {
export class AlwatrPwaRoot extends AlwatrPwaElement {
protected override _routes: RoutesConfig = {
map: (route) => route.sectionList[0]?.toString(),
list: {
Expand Down
Loading