@sealcode/sealgen 0.12.12 → 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.
@@ -0,0 +1,2 @@
1
+ export declare const FONTS_CONFIG_PATH = "src/fonts.json";
2
+ export declare function getFonts(_?: Record<string, string | boolean>): Promise<void>;
@@ -0,0 +1,4 @@
1
+ export declare const target_locreq: {
2
+ (module_path: string): unknown;
3
+ resolve: (module_path: string) => string;
4
+ };
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 });
@@ -113,7 +114,6 @@ async function build_ts() {
113
114
  )
114
115
  },
115
116
  async (args) => {
116
- const mode = "url";
117
117
  let contents = `export const url = "${await makeResourceURL(
118
118
  args.path
119
119
  )}";
@@ -167,6 +167,7 @@ async function complex_build(watch) {
167
167
  // plugins: [sassPlugin()],
168
168
  loader
169
169
  });
170
+ let ongoing_fonts = false;
170
171
  let ongoing_ts = false;
171
172
  let ongoing_css = false;
172
173
  let ongoing_ts_promise = null;
@@ -180,6 +181,14 @@ async function complex_build(watch) {
180
181
  return;
181
182
  if (path2.includes(".#"))
182
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
+ }
183
192
  if (path2.endsWith(".css") && !path2.endsWith("/includes.css")) {
184
193
  if (ongoing_css) {
185
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
@@ -0,0 +1,6 @@
1
+ import _locreq from "locreq";
2
+ const target_locreq = _locreq(process.cwd());
3
+ export {
4
+ target_locreq
5
+ };
6
+ //# sourceMappingURL=target-locreq.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealcode/sealgen",
3
- "version": "0.12.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, BuildResult, context } from "esbuild";
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, writeFile } from "fs/promises";
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() {
@@ -127,7 +128,6 @@ async function build_ts() {
127
128
  ),
128
129
  },
129
130
  async (args: any) => {
130
- const mode = "url";
131
131
  let contents = `export const url = "${await makeResourceURL(
132
132
  args.path
133
133
  )}";
@@ -183,6 +183,7 @@ async function complex_build(watch: boolean): Promise<void> {
183
183
  // plugins: [sassPlugin()],
184
184
  loader,
185
185
  });
186
+ let ongoing_fonts = false;
186
187
  let ongoing_ts = false;
187
188
  let ongoing_css = false;
188
189
  let ongoing_ts_promise: Promise<any> | null = null;
@@ -194,6 +195,14 @@ async function complex_build(watch: boolean): Promise<void> {
194
195
  watcher.on("all", async (_, path) => {
195
196
  if (!css_build) return;
196
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
+ }
197
206
  if (path.endsWith(".css") && !path.endsWith("/includes.css")) {
198
207
  if (ongoing_css) {
199
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 () {
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ import _locreq from "locreq";
2
+ export const target_locreq = _locreq(process.cwd());