Skip to content

Commit da14f9d

Browse files
committed
update build scripts
1 parent 302f60a commit da14f9d

File tree

16 files changed

+158
-34
lines changed

16 files changed

+158
-34
lines changed

_build_scripts/build-component.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as esbuild from "https://deno.land/x/[email protected]/mod.js";
2+
import { copy } from "https://deno.land/[email protected]/fs/mod.ts";
3+
4+
export async function buildComponent(componentName: string) {
5+
console.log(`Building ${componentName}`);
6+
await build_src(componentName);
7+
await copy_files(componentName);
8+
}
9+
10+
async function build_src(componentName: string) {
11+
const result = await esbuild.build({
12+
entryPoints: [`components/${componentName}/${componentName}.js`],
13+
outfile: `dist/components/${componentName}/${componentName}.js`,
14+
bundle: true,
15+
minify: true,
16+
sourcemap: true,
17+
target: ["es2020"],
18+
format: "esm",
19+
keepNames: true
20+
});
21+
esbuild.stop();
22+
23+
if (result.errors.length > 0) {
24+
console.error(result.errors);
25+
Deno.exit(1);
26+
}
27+
}
28+
29+
// Copy all files and folders.
30+
// Ignore js files.
31+
async function copy_files(componentName: string) {
32+
const srcFolder = `components/${componentName}`;
33+
const distFolder = `dist/components/${componentName}`;
34+
35+
for await (const entry of Deno.readDir(srcFolder)) {
36+
if (entry.isFile && entry.name.endsWith(".js")) {
37+
continue;
38+
}
39+
40+
if (entry.isDirectory) {
41+
await copyFilesToFolder(`${srcFolder}/${entry.name}`, `${distFolder}/${entry.name}`);
42+
continue;
43+
}
44+
45+
const srcPath = `${srcFolder}/${entry.name}`;
46+
const distPath = `${distFolder}/${entry.name}`;
47+
await copy(srcPath, distPath, { overwrite: true });
48+
}
49+
}
50+
51+
async function copyFilesToFolder(sourceDir: string, targetDir: string) {
52+
for await (const entry of Deno.readDir(sourceDir)) {
53+
const srcPath = `${sourceDir}/${entry.name}`;
54+
const distPath = `${targetDir}/${entry.name}`;
55+
await copy(srcPath, distPath, { overwrite: true });
56+
}
57+
}

_build_scripts/build-src.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as esbuild from "https://deno.land/x/[email protected]/mod.js";
2+
3+
export async function buildSrcFile(file: string) {
4+
console.log(`Building ${file}`);
5+
const result = await esbuild.build({
6+
entryPoints: [`src/${file}`],
7+
outfile: `dist/src/${file}`,
8+
bundle: false,
9+
minify: true,
10+
sourcemap: true,
11+
target: ["es2020"],
12+
format: "esm",
13+
keepNames: true
14+
});
15+
esbuild.stop();
16+
17+
if (result.errors.length > 0) {
18+
console.error(result.errors);
19+
Deno.exit(1);
20+
}
21+
}

_build_scripts/build.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,17 @@
1-
import * as esbuild from "https://deno.land/x/[email protected]/mod.js";
1+
import { buildSrcFile } from "./build-src.ts";
2+
import { buildComponent } from "./build-component.ts";
23

34
async function cleaerDistFolder() {
45
await Deno.remove("dist", { recursive: true });
56
await Deno.mkdir("dist");
67
await Deno.mkdir("dist/src");
78
}
89

9-
async function buildSrcFile(file: string) {
10-
console.log(`Building ${file}`);
11-
const result = await esbuild.build({
12-
entryPoints: [`src/${file}`],
13-
outfile: `dist/src/${file}`,
14-
bundle: true,
15-
format: "esm",
16-
minify: true,
17-
sourcemap: true,
18-
target: "es6",
19-
keepNames: true
20-
});
21-
esbuild.stop();
22-
23-
if (result.errors.length > 0) {
24-
console.error(result.errors);
25-
Deno.exit(1);
26-
}
27-
}
28-
2910
await cleaerDistFolder();
3011

12+
// Components
13+
await buildComponent("activity-state");
14+
3115
// System Files
3216
await buildSrcFile("system/assert.js");
3317
await buildSrcFile("system/events-manager.js");

deno.lock

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
:host {
2+
display: block;
3+
box-sizing: border-box;
4+
width: 1.5rem;
5+
height: 1.5rem;
6+
}
7+
8+
.rotate {
9+
animation: rotate 2s linear infinite;
10+
}
11+
12+
@keyframes rotate {
13+
from {
14+
transform: rotate(0deg);
15+
}
16+
to {
17+
transform: rotate(360deg);
18+
}
19+
}
20+
21+
.success {
22+
fill: green;
23+
}
24+
25+
.error {
26+
fill: red;
27+
}
28+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<material-icon></material-icon>

dist/components/activity-state/activity-state.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)