@sealcode/sealgen 0.12.11 → 0.12.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/src/get-fonts.d.ts +2 -0
- package/@types/src/target-locreq.d.ts +4 -0
- package/dist/build.js +38 -11
- package/dist/cli.js +3 -1
- package/dist/get-fonts.js +27 -0
- package/dist/target-locreq.js +6 -0
- package/package.json +2 -1
- package/src/build.ts +40 -14
- package/src/cli.ts +2 -0
- package/src/get-fonts.ts +25 -0
- package/src/target-locreq.ts +2 -0
package/dist/build.js
CHANGED
|
@@ -14,6 +14,7 @@ import md5 from "md5";
|
|
|
14
14
|
import _locreq from "locreq";
|
|
15
15
|
import path, { basename, extname } from "path";
|
|
16
16
|
import { copyFile } from "fs/promises";
|
|
17
|
+
import { FONTS_CONFIG_PATH, getFonts } from "./get-fonts.js";
|
|
17
18
|
const target_locreq = _locreq(process.cwd());
|
|
18
19
|
async function get_notifier_port() {
|
|
19
20
|
return getPort({ port: 4e3 });
|
|
@@ -78,12 +79,18 @@ async function build_ts() {
|
|
|
78
79
|
"utf8"
|
|
79
80
|
);
|
|
80
81
|
for (const ext of embeddable_file_extensions) {
|
|
82
|
+
const regex = new RegExp(
|
|
83
|
+
`^import (\\w+|{[^}]+}) from "([^"]+.${ext})";`,
|
|
84
|
+
"gm"
|
|
85
|
+
);
|
|
81
86
|
contents = contents.replaceAll(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
regex,
|
|
88
|
+
(line) => {
|
|
89
|
+
return line.replace(
|
|
90
|
+
`.${ext}"`,
|
|
91
|
+
'.js"'
|
|
92
|
+
);
|
|
93
|
+
}
|
|
87
94
|
);
|
|
88
95
|
}
|
|
89
96
|
contents = removeNamedImports(contents);
|
|
@@ -107,19 +114,30 @@ async function build_ts() {
|
|
|
107
114
|
)
|
|
108
115
|
},
|
|
109
116
|
async (args) => {
|
|
110
|
-
const mode = "url";
|
|
111
117
|
let contents = `export const url = "${await makeResourceURL(
|
|
112
118
|
args.path
|
|
113
119
|
)}";
|
|
114
120
|
|
|
115
121
|
import fs from "fs";
|
|
116
|
-
let
|
|
122
|
+
let buffer_promise = null;
|
|
123
|
+
|
|
124
|
+
export const getBuffer = function(){
|
|
125
|
+
if(buffer_promise) return buffer_promise;
|
|
126
|
+
buffer_promise = fs.promises.readFile("${args.path}");
|
|
127
|
+
return buffer_promise;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const getContent = async function(){
|
|
131
|
+
const buffer = await getBuffer();
|
|
132
|
+
return buffer.toString("utf-8");
|
|
133
|
+
}
|
|
117
134
|
|
|
118
|
-
export const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return content_promise;
|
|
135
|
+
export const getBase64 = async function(){
|
|
136
|
+
const buffer = await getBuffer();
|
|
137
|
+
return buffer.toString("base64");
|
|
122
138
|
}
|
|
139
|
+
|
|
140
|
+
export default { getContent, url, getBase64, getBuffer };
|
|
123
141
|
`;
|
|
124
142
|
return {
|
|
125
143
|
contents
|
|
@@ -149,6 +167,7 @@ async function complex_build(watch) {
|
|
|
149
167
|
// plugins: [sassPlugin()],
|
|
150
168
|
loader
|
|
151
169
|
});
|
|
170
|
+
let ongoing_fonts = false;
|
|
152
171
|
let ongoing_ts = false;
|
|
153
172
|
let ongoing_css = false;
|
|
154
173
|
let ongoing_ts_promise = null;
|
|
@@ -162,6 +181,14 @@ async function complex_build(watch) {
|
|
|
162
181
|
return;
|
|
163
182
|
if (path2.includes(".#"))
|
|
164
183
|
return;
|
|
184
|
+
if (path2 == FONTS_CONFIG_PATH) {
|
|
185
|
+
if (!ongoing_fonts) {
|
|
186
|
+
ongoing_fonts = true;
|
|
187
|
+
await getFonts();
|
|
188
|
+
ongoing_fonts = false;
|
|
189
|
+
}
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
165
192
|
if (path2.endsWith(".css") && !path2.endsWith("/includes.css")) {
|
|
166
193
|
if (ongoing_css) {
|
|
167
194
|
return;
|
package/dist/cli.js
CHANGED
|
@@ -9,6 +9,7 @@ import { generateComponents } from "./generate-components.js";
|
|
|
9
9
|
import { generateRoutes } from "./generate-routes.js";
|
|
10
10
|
import { makeEnv } from "./make-env.js";
|
|
11
11
|
import yargs from "yargs/yargs";
|
|
12
|
+
import { getFonts } from "./get-fonts.js";
|
|
12
13
|
const actions = {
|
|
13
14
|
"add-collection": addCollection,
|
|
14
15
|
"add-route": addRoute,
|
|
@@ -24,7 +25,8 @@ const actions = {
|
|
|
24
25
|
);
|
|
25
26
|
},
|
|
26
27
|
"make-env": makeEnv,
|
|
27
|
-
"add-component": addJDDComponent
|
|
28
|
+
"add-component": addJDDComponent,
|
|
29
|
+
"get-fonts": getFonts
|
|
28
30
|
};
|
|
29
31
|
void async function() {
|
|
30
32
|
const action = process.argv.at(2);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
import { constructURL, download } from "google-fonts-helper";
|
|
3
|
+
import { target_locreq } from "./target-locreq.js";
|
|
4
|
+
const FONTS_CONFIG_PATH = "src/fonts.json";
|
|
5
|
+
async function getFonts(_ = {}) {
|
|
6
|
+
const fonts_config_path = target_locreq.resolve(FONTS_CONFIG_PATH);
|
|
7
|
+
const fonts_config = JSON.parse(await readFile(fonts_config_path, "utf8"));
|
|
8
|
+
const fonts_url = constructURL(fonts_config.googleFonts);
|
|
9
|
+
if (!fonts_url) {
|
|
10
|
+
throw new Error("Invalid font config");
|
|
11
|
+
}
|
|
12
|
+
const downloader = download(fonts_url, {
|
|
13
|
+
base64: false,
|
|
14
|
+
overwriting: false,
|
|
15
|
+
outputDir: target_locreq.resolve("public/dist/fonts"),
|
|
16
|
+
stylePath: "fonts.css",
|
|
17
|
+
fontsDir: "./",
|
|
18
|
+
fontsPath: "/dist/fonts"
|
|
19
|
+
});
|
|
20
|
+
await downloader.execute();
|
|
21
|
+
console.log("Downloaded new fonts pack");
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
FONTS_CONFIG_PATH,
|
|
25
|
+
getFonts
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=get-fonts.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealcode/sealgen",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.13",
|
|
4
4
|
"description": "Module to automate adding routes and collections to a sealious application",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"@sealcode/ts-predicates": "^0.4.3",
|
|
56
56
|
"deepmerge": "^4.3.1",
|
|
57
57
|
"esbuild": "^0.20.0",
|
|
58
|
+
"google-fonts-helper": "^3.4.1",
|
|
58
59
|
"js-convert-case": "^4.2.0",
|
|
59
60
|
"locreq": "^3.0.0",
|
|
60
61
|
"md5": "^2.3.0",
|
package/src/build.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { build, BuildContext,
|
|
1
|
+
import { build, BuildContext, context } from "esbuild";
|
|
2
2
|
import { promises as fs } from "fs";
|
|
3
3
|
import * as chokidar from "chokidar";
|
|
4
4
|
import { default as glob } from "tiny-glob";
|
|
@@ -14,7 +14,8 @@ import md5 from "md5";
|
|
|
14
14
|
|
|
15
15
|
import _locreq from "locreq";
|
|
16
16
|
import path, { basename, extname } from "path";
|
|
17
|
-
import { copyFile
|
|
17
|
+
import { copyFile } from "fs/promises";
|
|
18
|
+
import { FONTS_CONFIG_PATH, getFonts } from "./get-fonts.js";
|
|
18
19
|
const target_locreq = _locreq(process.cwd());
|
|
19
20
|
|
|
20
21
|
async function get_notifier_port() {
|
|
@@ -87,13 +88,18 @@ async function build_ts() {
|
|
|
87
88
|
"utf8"
|
|
88
89
|
);
|
|
89
90
|
for (const ext of embeddable_file_extensions) {
|
|
91
|
+
const regex = new RegExp(
|
|
92
|
+
`^import (\\w+|{[^}]+}) from "([^"]+.${ext})";`,
|
|
93
|
+
"gm"
|
|
94
|
+
);
|
|
90
95
|
contents = contents.replaceAll(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
regex,
|
|
97
|
+
(line) => {
|
|
98
|
+
return line.replace(
|
|
99
|
+
`.${ext}"`,
|
|
100
|
+
'.js"'
|
|
101
|
+
);
|
|
102
|
+
}
|
|
97
103
|
);
|
|
98
104
|
}
|
|
99
105
|
|
|
@@ -122,19 +128,30 @@ async function build_ts() {
|
|
|
122
128
|
),
|
|
123
129
|
},
|
|
124
130
|
async (args: any) => {
|
|
125
|
-
const mode = "url";
|
|
126
131
|
let contents = `export const url = "${await makeResourceURL(
|
|
127
132
|
args.path
|
|
128
133
|
)}";
|
|
129
134
|
|
|
130
135
|
import fs from "fs";
|
|
131
|
-
let
|
|
136
|
+
let buffer_promise = null;
|
|
137
|
+
|
|
138
|
+
export const getBuffer = function(){
|
|
139
|
+
if(buffer_promise) return buffer_promise;
|
|
140
|
+
buffer_promise = fs.promises.readFile("${args.path}");
|
|
141
|
+
return buffer_promise;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export const getContent = async function(){
|
|
145
|
+
const buffer = await getBuffer();
|
|
146
|
+
return buffer.toString("utf-8");
|
|
147
|
+
}
|
|
132
148
|
|
|
133
|
-
export const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return content_promise;
|
|
149
|
+
export const getBase64 = async function(){
|
|
150
|
+
const buffer = await getBuffer();
|
|
151
|
+
return buffer.toString("base64");
|
|
137
152
|
}
|
|
153
|
+
|
|
154
|
+
export default { getContent, url, getBase64, getBuffer };
|
|
138
155
|
`;
|
|
139
156
|
return {
|
|
140
157
|
contents,
|
|
@@ -166,6 +183,7 @@ async function complex_build(watch: boolean): Promise<void> {
|
|
|
166
183
|
// plugins: [sassPlugin()],
|
|
167
184
|
loader,
|
|
168
185
|
});
|
|
186
|
+
let ongoing_fonts = false;
|
|
169
187
|
let ongoing_ts = false;
|
|
170
188
|
let ongoing_css = false;
|
|
171
189
|
let ongoing_ts_promise: Promise<any> | null = null;
|
|
@@ -177,6 +195,14 @@ async function complex_build(watch: boolean): Promise<void> {
|
|
|
177
195
|
watcher.on("all", async (_, path) => {
|
|
178
196
|
if (!css_build) return;
|
|
179
197
|
if (path.includes(".#")) return;
|
|
198
|
+
if (path == FONTS_CONFIG_PATH) {
|
|
199
|
+
if (!ongoing_fonts) {
|
|
200
|
+
ongoing_fonts = true;
|
|
201
|
+
await getFonts();
|
|
202
|
+
ongoing_fonts = false;
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
180
206
|
if (path.endsWith(".css") && !path.endsWith("/includes.css")) {
|
|
181
207
|
if (ongoing_css) {
|
|
182
208
|
return;
|
package/src/cli.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { generateComponents } from "./generate-components.js";
|
|
|
9
9
|
import { generateRoutes } from "./generate-routes.js";
|
|
10
10
|
import { makeEnv } from "./make-env.js";
|
|
11
11
|
import yargs from "yargs/yargs";
|
|
12
|
+
import { getFonts } from "./get-fonts.js";
|
|
12
13
|
|
|
13
14
|
const actions: Record<
|
|
14
15
|
string,
|
|
@@ -31,6 +32,7 @@ const actions: Record<
|
|
|
31
32
|
},
|
|
32
33
|
"make-env": makeEnv,
|
|
33
34
|
"add-component": addJDDComponent,
|
|
35
|
+
"get-fonts": getFonts,
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
void (async function () {
|
package/src/get-fonts.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
import { constructURL, download } from "google-fonts-helper";
|
|
3
|
+
import { target_locreq } from "./target-locreq.js";
|
|
4
|
+
|
|
5
|
+
export const FONTS_CONFIG_PATH = "src/fonts.json";
|
|
6
|
+
|
|
7
|
+
export async function getFonts(_: Record<string, string | boolean> = {}) {
|
|
8
|
+
const fonts_config_path = target_locreq.resolve(FONTS_CONFIG_PATH);
|
|
9
|
+
|
|
10
|
+
const fonts_config = JSON.parse(await readFile(fonts_config_path, "utf8"));
|
|
11
|
+
const fonts_url = constructURL(fonts_config.googleFonts);
|
|
12
|
+
if (!fonts_url) {
|
|
13
|
+
throw new Error("Invalid font config");
|
|
14
|
+
}
|
|
15
|
+
const downloader = download(fonts_url, {
|
|
16
|
+
base64: false,
|
|
17
|
+
overwriting: false,
|
|
18
|
+
outputDir: target_locreq.resolve("public/dist/fonts"),
|
|
19
|
+
stylePath: "fonts.css",
|
|
20
|
+
fontsDir: "./",
|
|
21
|
+
fontsPath: "/dist/fonts",
|
|
22
|
+
});
|
|
23
|
+
await downloader.execute();
|
|
24
|
+
console.log("Downloaded new fonts pack");
|
|
25
|
+
}
|