Skip to content

Commit

Permalink
add dist build script
Browse files Browse the repository at this point in the history
  • Loading branch information
caperaven committed Jul 27, 2022
1 parent 5708393 commit a9f01c8
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 20 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ package-lock.json
yarn.lock
yarn-error.log
/coverage/
/dist/
/publish/
6 changes: 6 additions & 0 deletions .idea/deno.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 28 additions & 17 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions build/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { emptyDir, ensureDir } from "https://deno.land/[email protected]/fs/mod.ts";
import * as esbuild from 'https://deno.land/x/[email protected]/mod.js'

async function createFolderStructure() {
await ensureDir("./dist");
await emptyDir("./dist");
}

async function packageDirectory(def, loader, format, minified) {
for (const dir of def.dir) {
for await (const dirEntry of Deno.readDir(dir)) {
if (dirEntry.isDirectory) {
continue;
}

const sourceFile = `${dir}/${dirEntry.name}`;

let targetFile = `${def.target}${dir}/${dirEntry.name}`;
let keys = Object.keys(def.replace || {});
for (const key of keys) {
targetFile = targetFile.replace(key, def.replace[key]);
}

await packageFile(sourceFile, targetFile, loader, format, minified);
}
}
}

async function packageFiles(def, loader, format, minified) {
for (const file of def.files) {
const target = file.replace("./src", "./dist");
await packageFile(file, target, loader, format, minified);
}
}

async function packageFile(sourceFile, targetFile, loader, format, minified) {
const src = await Deno.readTextFile(sourceFile);
const result = await esbuild.transform(src, { loader: loader, minify: minified, format: format });
await Deno.writeTextFile(targetFile, result.code);
}

/**
* Save the html/css/json file to the target and minify it if required
* @param sourceFile
* @param targetFile
* @param minified
* @returns {Promise<void>}
*/
async function packageMarkup(sourceFile, targetFile, minified) {
let src = await Deno.readTextFile(sourceFile);

if (minified == true) {
src = src
.split(" ").join("")
.split("\t").join("")
.split("\r").join("")
.split("\n").join("");
}

await Deno.writeTextFile(targetFile, src);
}

async function bundle(file, output) {
const result = await esbuild.build({
entryPoints: [file],
bundle: true,
outfile: output,
format: "esm",
minify: true
})

console.log(result);
}


await createFolderStructure();

await packageMarkup("./src/crs-loader.html", "./dist/crs-loader.html", true);
await packageFile("./src/crs-loader.js", "./dist/crs-loader.js", "js", "esm", true);
await packageFile("./src/crs-router.js", "./dist/crs-router.js", "js", "esm", true);
await packageFile("./src/crs-static-provider.js", "./dist/crs-static-provider.js", "js", "esm", true);
await packageFile("./src/crs-url-provider.js", "./dist/crs-url-provider.js", "js", "esm", true);
await packageFile("./src/crs-utils.js", "./dist/crs-utils.js", "js", "esm", true);

Deno.exit(0);
1 change: 1 addition & 0 deletions dist/crs-loader.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<style>crs-loader{--path:#2F3545;--dot:#ff0080;--duration:2s;position:fixed;display:flex;flex-direction:column;justify-content:center;width:60px;height:60px;}crs-loader.text{color:var(--dot);}crs-loader.loader{width:44px;height:44px;position:relative;}crs-loader.loader:before{content:'';width:5px;height:5px;border-radius:50%;position:absolute;display:block;background:var(--dot);top:37px;}crs-loader.loadersvg{display:block;width:100%;height:100%;}crs-loader.loadersvgpolygon{fill:none;stroke:var(--path);stroke-width:10px;stroke-linejoin:round;stroke-linecap:round;stroke-dasharray:1457614576;stroke-dashoffset:0;animation:pathTrianglevar(--duration)cubic-bezier(0.785,0.135,0.15,0.86)infinite;}crs-loader.triangle:before{left:21px;transform:translate(-10px,-18px);animation:dotTrianglevar(--duration)cubic-bezier(0.785,0.135,0.15,0.86)infinite;}@keyframespathTriangle{33%{stroke-dashoffset:74;}66%{stroke-dashoffset:147;}100%{stroke-dashoffset:221;}}@keyframesdotTriangle{33%{transform:translate(0,0);}66%{transform:translate(10px,-18px);}100%{transform:translate(-10px,-18px);}}</style><divclass="loadertriangle"><svgviewBox="008680"><polygonpoints="4387972772"></polygon></svg></div><divclass="text">Loading</div>
1 change: 1 addition & 0 deletions dist/crs-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class t extends HTMLElement{connectedCallback(){fetch(import.meta.url.replace(".js",".html")).then(e=>e.text()).then(e=>this.innerHTML=e)}}customElements.define("crs-loader",t);export{t as Loader};
2 changes: 2 additions & 0 deletions dist/crs-router.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/crs-static-provider.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/crs-url-provider.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/crs-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "crs-router",
"version": "0.0.78",
"version": "0.0.82",
"description": "Zero dependency router web component for framework free applications",
"main": "index.js",
"scripts": {
"test": "jest",
"bundle": "rollup -c",
"bundle": "deno run --allow-read --allow-write --allow-env --allow-run ./build/package.js",
"build-publish": "node build/publish.js"
},
"keywords": [
Expand Down

0 comments on commit a9f01c8

Please sign in to comment.