100+ copy-paste UI components in plain HTML and CSS: no dependencies, no build step.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-web-native.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-web-native.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-web-native.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add canonical.html v1.0 - The single source of truth for usability standards fb6e650 1 year ago History
build.js · 2.3 KB · 78 lines
1#!/usr/bin/env node
2
3/**
4 * Simple build script for Semantic Components
5 * Minifies source files for CDN distribution
6 */
7
8const fs = require('fs');
9const path = require('path');
10
11const sourceFile = process.argv[2];
12
13if (!sourceFile) {
14 console.error('Usage: node build.js <source-file>');
15 process.exit(1);
16}
17
18const sourcePath = path.join(__dirname, sourceFile);
19const fileName = path.basename(sourceFile, '.js');
20
21// Create dist directory if it doesn't exist
22const distDir = path.join(__dirname, 'dist');
23if (!fs.existsSync(distDir)) {
24 fs.mkdirSync(distDir);
25}
26
27// Read source file
28const source = fs.readFileSync(sourcePath, 'utf8');
29
30// Add version header
31const version = require('./package.json').version;
32const header = `/**
33 * Semantic Components v${version}
34 * ${fileName}.js
35 *
36 * Intent-based, context-aware, modality-agnostic web components
37 * https://semantic-components.dev
38 *
39 * Copyright (c) ${new Date().getFullYear()} Semantic Components Team
40 * Released under the MIT License
41 */
42
43`;
44
45// Copy to dist (full version)
46const fullPath = path.join(distDir, `${fileName}.js`);
47fs.writeFileSync(fullPath, header + source);
48console.log(`✓ Built ${fileName}.js`);
49
50// Create ESM version
51const esmSource = source.replace(
52 /if \(typeof module !== 'undefined' && module\.exports\) \{[\s\S]*?\}/g,
53 ''
54);
55const esmPath = path.join(distDir, `${fileName}.esm.js`);
56fs.writeFileSync(esmPath, header + esmSource + '\nexport default window.semanticContext || {};');
57console.log(`✓ Built ${fileName}.esm.js`);
58
59// Simple minification (remove comments and extra whitespace)
60const minified = source
61 .replace(/\/\*[\s\S]*?\*\//g, '') // Remove multi-line comments
62 .replace(/\/\/.*/g, '') // Remove single-line comments
63 .replace(/\s+/g, ' ') // Collapse whitespace
64 .replace(/\s*([{}();,:])\s*/g, '$1') // Remove spaces around symbols
65 .trim();
66
67const minPath = path.join(distDir, `${fileName}.min.js`);
68fs.writeFileSync(minPath, header + minified);
69console.log(`✓ Built ${fileName}.min.js`);
70
71// File sizes
72const fullSize = fs.statSync(fullPath).size;
73const minSize = fs.statSync(minPath).size;
74const savings = ((1 - minSize / fullSize) * 100).toFixed(1);
75
76console.log(`\nFile sizes:`);
77console.log(` Full: ${(fullSize / 1024).toFixed(1)} KB`);
78console.log(` Min: ${(minSize / 1024).toFixed(1)} KB (${savings}% smaller)`);