Skip to content

Commit afbfd84

Browse files
committed
Version 1.0.1
1 parent 95a2c37 commit afbfd84

12 files changed

Lines changed: 7109 additions & 6825 deletions

File tree

build-tools/binToTs.ts

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
import { join } from "https://deno.land/std@0.213.0/path/mod.ts";
22
import { copy } from "https://deno.land/std@0.213.0/fs/copy.ts";
33

4-
import { bin } from "../wwwzip/ui.ts";
4+
import { bin, version } from "../wwwzip/ui.ts";
55
import { decompress } from "./zip.ts";
66

77
export async function initServer(wwwRoot: string): Promise<boolean> {
88
try {
9-
const zipFile = await tsToZip(wwwRoot);
109
const indexFile = join(wwwRoot, "index.html");
1110
const isExist = await exists(indexFile);
1211
if (isExist) {
13-
return true;
12+
//Check for update
13+
const installedVersion = await getUiVersion(indexFile)
14+
15+
if (installedVersion === version) {
16+
return true;
17+
}
18+
19+
console.log(`Updating UI from V${installedVersion} to V${version}`)
20+
//We need to remove old version
21+
await Deno.remove(indexFile);
22+
await Deno.remove(join(wwwRoot, "favicon.ico"));
23+
await Deno.remove(join(wwwRoot, "assets"), { recursive: true });
24+
await Deno.remove(join(wwwRoot, "icons"), { recursive: true });
1425
}
1526

27+
const zipFile = await tsToZip(wwwRoot);
28+
29+
//Decompress zip file
1630
await decompress(zipFile, wwwRoot);
1731
await Deno.remove(zipFile);
32+
1833
const spa = join(wwwRoot, "spa");
1934
const spa_assets = join(spa, "assets");
2035
const spa_icons = join(spa, "icons");
@@ -28,18 +43,30 @@ export async function initServer(wwwRoot: string): Promise<boolean> {
2843
await copy(join(spa, "index.html"), join(wwwRoot, "index.html"));
2944
await copy(join(spa, "favicon.ico"), join(wwwRoot, "favicon.ico"));
3045

31-
Deno.remove(spa, { recursive: true });
46+
await Deno.remove(spa, { recursive: true });
3247
return true;
3348
} catch (err) {
3449
console.log(err);
3550
return false;
3651
}
3752
}
3853

54+
/**
55+
* Convert zip file to base64 ts
56+
* @date 2/3/2024 - 6:23:34 PM
57+
*
58+
* @export
59+
* @async
60+
* @param {string} path
61+
* @param {string} fileName
62+
* @returns {*}
63+
*/
3964
export async function zipToTs(path: string, fileName: string) {
65+
const version = await getUiVersion(join(path, `spa\\index.html`));
66+
4067
const binPath = join(path, `${fileName}.zip`);
4168
const uint = await Deno.readFile(binPath);
42-
69+
4370
let binary = "";
4471
const len = uint.length;
4572

@@ -50,12 +77,25 @@ export async function zipToTs(path: string, fileName: string) {
5077
const binBase64 = btoa(binary);
5178
const base64 = trunString(binBase64, 100);
5279

53-
const tsFileContent = `export const bin=\`${base64}\``;
80+
const tsFileContent = `export const version='${version}';
81+
82+
export const bin=\`${base64}\``;
5483
const tsFilePath = join("./wwwzip", `${fileName}.ts`);
5584
await Deno.writeTextFile(tsFilePath, tsFileContent);
56-
console.log(`TS File saved to: ${tsFilePath}`);
85+
await Deno.remove(binPath);
5786
}
5887

88+
/**
89+
* This function converts the ts base64 file to .zip file
90+
* The zip file will be wwwroot
91+
* example: C:\Users\USERNAME\AppData\Local\deno\denoman\wwwroot
92+
* @date 2/3/2024 - 6:09:39 PM
93+
*
94+
* @export
95+
* @async
96+
* @param {string} wwwRoot
97+
* @returns {Promise<string>}
98+
*/
5999
export async function tsToZip(wwwRoot: string): Promise<string> {
60100
const binContent = atob(bin);
61101
const binArray = new Uint8Array(binContent.length);
@@ -70,6 +110,17 @@ export async function tsToZip(wwwRoot: string): Promise<string> {
70110
return zipFile;
71111
}
72112

113+
async function getUiVersion(indexFile: string): Promise<string> {
114+
const content = await Deno.readTextFile(indexFile);
115+
const regEx = /content\=\"DenoMan\s(.*?)\"\>/gm;
116+
const matches = content.matchAll(regEx);
117+
let version = "0";
118+
for (const m of matches) {
119+
version = m[1];
120+
}
121+
return version;
122+
}
123+
73124
function trunString(input: string, width: number): string {
74125
const it = Math.ceil(input.length / width);
75126
let rtnVal = "";

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"tasks": {
3-
"start": "deno run -A mod.ts"
3+
"start": "deno run -A mod.ts",
4+
"build": "deno run -A prepare-spa.ts"
45
},
56

67
"lint": {

deno.lock

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

prepare-spa.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
1+
import { parseArgs } from "https://deno.land/std@0.214.0/cli/parse_args.ts";
2+
3+
14
import { zipToTs } from "./build-tools/binToTs.ts";
25
import { compress } from "./build-tools/zip.ts";
36

4-
console.log("Compressing ...");
5-
await compress("./q-manui/dist/spa", "./q-manui/dist/ui.zip", {
6-
overwrite: true,
7-
flags: [],
8-
});
9-
console.log(`Compressed: q-manui/dist/ui.zip`);
7+
await increaseUiVersion();
8+
buildQuasar();
9+
await spaToTypeScript();
10+
11+
12+
function buildQuasar() {
13+
const msg = "Please go to [./q-manui] and build the project [quasar build]."
14+
alert(msg);
15+
}
16+
17+
async function increaseUiVersion() {
18+
const newVersion = prompt("Please enter the new version:");
19+
20+
const packageFile = "./q-manui/package.json";
21+
let packageJson = await Deno.readTextFile(packageFile);
22+
const pkg = JSON.parse(packageJson);
23+
pkg.version = newVersion;
24+
pkg.description = `DenoMan ${newVersion}`
25+
packageJson = JSON.stringify(pkg, null, 2);
26+
27+
await Deno.writeTextFile(packageFile, packageJson);
28+
console.log("package.json file updated.")
29+
}
30+
31+
async function spaToTypeScript() {
32+
console.log("Compressing [q-manui/dist/spa] ...");
33+
await compress("./q-manui/dist/spa", "./q-manui/dist/ui.zip", {
34+
overwrite: true,
35+
flags: [],
36+
});
1037

11-
console.log("Zip to ts ...");
12-
await zipToTs("./q-manui/dist", "ui");
38+
console.log("Converting [q-manui/dist/ui.zip] to [ui.ts]");
39+
await zipToTs("./q-manui/dist", "ui");
40+
console.log("[ui.ts] created.");
41+
}

q-manui/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "q-manui",
3-
"version": "0.0.1",
4-
"description": "denoman spa ui",
3+
"version": "1.0.1",
4+
"description": "DenoMan 1.0.1",
55
"productName": "q-manui",
66
"author": "Sameh Fakoua <s.fakoua@gmail.com>",
77
"private": true,
@@ -41,4 +41,4 @@
4141
"npm": ">= 6.13.4",
4242
"yarn": ">= 1.21.1"
4343
}
44-
}
44+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<template>
2+
<q-card flat bordered style="min-height: 268px" v-if="loading">
3+
<q-item>
4+
<q-item-section avatar>
5+
<q-skeleton type="QAvatar" />
6+
</q-item-section>
7+
8+
<q-item-section>
9+
<q-item-label>
10+
<q-skeleton type="text" />
11+
</q-item-label>
12+
<q-item-label caption>
13+
<q-skeleton type="text" />
14+
</q-item-label>
15+
</q-item-section>
16+
</q-item>
17+
18+
<q-skeleton height="200px" square />
19+
</q-card>
20+
<q-card flat bordered v-if="!loading">
21+
<q-card-section>
22+
<div class="text-h6 text-red-6">
23+
<q-icon name="notification_important" />
24+
Critical
25+
</div>
26+
<div class="text-weight-thin text-red-3">
27+
Automatic services & not running
28+
</div>
29+
</q-card-section>
30+
<div class="critical-table">
31+
<q-markup-table dense flat>
32+
<tbody>
33+
<tr v-for="s in critical" :key="s.name">
34+
<td class="text-red-9">
35+
<q-icon name="sync_problem" /> {{ s.caption }}
36+
</td>
37+
</tr>
38+
</tbody>
39+
</q-markup-table>
40+
</div>
41+
</q-card>
42+
</template>
43+
44+
<style lang="css" scoped>
45+
.critical-table {
46+
overflow-y: auto;
47+
max-height: 172px;
48+
}
49+
</style>
50+
51+
<script lang="ts">
52+
import { defineComponent } from 'vue';
53+
import { PropType } from 'vue';
54+
55+
import { ServiceModel } from '../models';
56+
57+
export default defineComponent({
58+
name: 'CriticalComponent',
59+
props: {
60+
critical: Object as PropType<ServiceModel[] | undefined>,
61+
loading: {
62+
type: Boolean,
63+
default: true,
64+
},
65+
},
66+
67+
setup() {
68+
return {};
69+
},
70+
});
71+
</script>

0 commit comments

Comments
 (0)