Skip to content

Commit 5ace77b

Browse files
authored
build: migrated component build script (#19)
* build: migrated component build script Signed-off-by: Asitha de Silva <[email protected]> * build: fix component renaming Signed-off-by: Asitha de Silva <[email protected]> --------- Signed-off-by: Asitha de Silva <[email protected]>
1 parent 02928f5 commit 5ace77b

File tree

5 files changed

+103
-6
lines changed

5 files changed

+103
-6
lines changed

docs/tools.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ lfx-tools {
225225
--lfx-tools-button-radius: 4px;
226226
--lfx-tools-icon-color: #666666;
227227
--lfx-tools-icon-hover-color: #333;
228+
--lfx-tools-menu-z-index: 1000;
228229
--lfx-tools-menu-bg: #ffffff;
229230
--lfx-tools-menu-width: 240px;
230231
--lfx-tools-menu-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
@@ -251,6 +252,7 @@ lfx-tools {
251252
| `--lfx-tools-button-radius` | Button border radius | `4px` |
252253
| `--lfx-tools-icon-color` | Grid icon color | `#666666` |
253254
| `--lfx-tools-icon-hover-color` | Grid icon hover color | `#333` |
255+
| `--lfx-tools-menu-z-index` | Menu z-index | `1000` |
254256
| `--lfx-tools-menu-bg` | Menu background color | `#ffffff` |
255257
| `--lfx-tools-menu-width` | Menu width | `240px` |
256258
| `--lfx-tools-menu-shadow` | Menu box shadow | `0 4px 20px rgba(0, 0, 0, 0.15)` |

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "@linuxfoundation/lfx-ui-core",
3-
"version": "0.0.0",
3+
"version": "0.0.17-alpha.2",
44
"description": "LFX UI Core Configurations and Components",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"license": "MIT",
88
"author": "The Linux Foundation",
99
"scripts": {
1010
"build:tokens": "ts-node src/scripts/build.ts",
11-
"build:browser": "browserify src/components/footer/footer.component.ts -p [ tsify ] -o dist/browser/footer.bundle.js",
11+
"build:browser": "ts-node src/scripts/build-browser.ts",
1212
"build": "npm run build:tokens && npm run format && tsc && npm run build:browser",
1313
"prepare": "npm run build",
1414
"format": "prettier --write \"src/**/*.{ts,js,json,md}\"",

src/components/tools/tools.style.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const style = `
6565
position: absolute;
6666
top: 0;
6767
left: 100%;
68-
z-index: 1000;
68+
z-index: var(--lfx-tools-menu-z-index, 1000);
6969
background: var(--lfx-tools-menu-bg, #ffffff);
7070
border: 1px solid var(--lfx-tools-menu-border, #e1e5e9);
7171
border-radius: var(--lfx-tools-menu-radius, 8px);

src/scripts/build-browser.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright The Linux Foundation and each contributor to LFX.
2+
// SPDX-License-Identifier: MIT
3+
4+
import { execSync } from 'child_process';
5+
import { existsSync, mkdirSync, readFileSync } from 'fs';
6+
import { join } from 'path';
7+
8+
interface ComponentInfo {
9+
name: string;
10+
path: string;
11+
exportPath: string;
12+
}
13+
14+
/**
15+
* Extract component information from the components index file
16+
*/
17+
function extractComponents(): ComponentInfo[] {
18+
const indexPath = join(__dirname, '../components/index.ts');
19+
const content = readFileSync(indexPath, 'utf-8');
20+
21+
const components: ComponentInfo[] = [];
22+
const exportRegex = /export \* from '\.\/([^']+)\/([^']+)'/g;
23+
24+
let match;
25+
while ((match = exportRegex.exec(content)) !== null) {
26+
const [, folder, file] = match;
27+
const componentName = folder.replace(/-(.)/g, (_, letter: string) => letter.toUpperCase()); // Convert kebab-case to camelCase
28+
components.push({
29+
name: componentName,
30+
path: join(__dirname, '../components', folder, `${file}.ts`),
31+
exportPath: `./${folder}/${file}`,
32+
});
33+
}
34+
35+
return components;
36+
}
37+
38+
/**
39+
* Build a single component for browser
40+
*/
41+
function buildComponent(component: ComponentInfo): void {
42+
const outputDir = join(__dirname, '../../dist/browser');
43+
const outputFile = join(outputDir, `${component.name}.bundle.js`);
44+
45+
// Ensure output directory exists
46+
if (!existsSync(outputDir)) {
47+
mkdirSync(outputDir, { recursive: true });
48+
}
49+
50+
console.log(`Building ${component.name} component...`);
51+
52+
try {
53+
const command = `browserify ${component.path} -p [ tsify ] -o ${outputFile}`;
54+
execSync(command, { stdio: 'inherit' });
55+
console.log(`✅ Built ${component.name} component`);
56+
} catch (error) {
57+
console.error(`❌ Failed to build ${component.name} component:`, error);
58+
throw error;
59+
}
60+
}
61+
62+
/**
63+
* Main build function
64+
*/
65+
function buildBrowser(): void {
66+
console.log('🚀 Starting browser build...');
67+
68+
try {
69+
const components = extractComponents();
70+
console.log(`📦 Found ${components.length} components to build:`, components.map((c) => c.name).join(', '));
71+
72+
for (const component of components) {
73+
buildComponent(component);
74+
}
75+
76+
console.log('✅ Browser build completed successfully!');
77+
} catch (error) {
78+
console.error('❌ Browser build failed:', error);
79+
process.exit(1);
80+
}
81+
}
82+
83+
// Run the build if this script is executed directly
84+
if (require.main === module) {
85+
buildBrowser();
86+
}
87+
88+
export { buildBrowser, extractComponents };

src/scripts/build.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export * from './components';`;
9696

9797
async function buildTokens() {
9898
try {
99+
console.log('🔧 Building design tokens...');
100+
99101
// Read tokens.json
100102
const tokensPath = path.resolve(__dirname, '../design/tokens/tokens.json');
101103
const tokens = JSON.parse(fs.readFileSync(tokensPath, 'utf8'));
@@ -122,11 +124,16 @@ async function buildTokens() {
122124
// Write index file
123125
fs.writeFileSync(path.join(mainDir, 'index.ts'), generateIndex());
124126

125-
console.log('Token and preset files generated successfully!');
127+
console.log('Token and preset files generated successfully!');
126128
} catch (error) {
127-
console.error('Error generating files:', error);
129+
console.error('Error generating files:', error);
128130
process.exit(1);
129131
}
130132
}
131133

132-
buildTokens();
134+
// Run the build if this script is executed directly
135+
if (require.main === module) {
136+
buildTokens();
137+
}
138+
139+
export { buildTokens };

0 commit comments

Comments
 (0)