@fuzdev/fuz_gitops 0.61.0 → 0.61.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitops_sync.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gitops_sync.task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,IAAI,EAAC,MAAM,eAAe,CAAC;AACnD,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAgBtB,cAAc;AACd,eAAO,MAAM,IAAI;;;;;;kBAkBf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"gitops_sync.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gitops_sync.task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,IAAI,EAAC,MAAM,eAAe,CAAC;AACnD,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAgBtB,cAAc;AACd,eAAO,MAAM,IAAI;;;;;;kBAkBf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CAmF3B,CAAC"}
|
package/dist/gitops_sync.task.js
CHANGED
|
@@ -43,7 +43,8 @@ export const task = {
|
|
|
43
43
|
run: async ({ args, log, svelte_config, invoke_task }) => {
|
|
44
44
|
const { config, dir, outdir = svelte_config.routes_path, download, check } = args;
|
|
45
45
|
const { local_repos } = await get_gitops_ready({ config, dir, download, log });
|
|
46
|
-
const
|
|
46
|
+
const outfile_json = resolve(outdir, 'repos.json');
|
|
47
|
+
const outfile_ts = resolve(outdir, 'repos.ts');
|
|
47
48
|
// This searches the parent directory for the env var, so we don't use SvelteKit's $env imports
|
|
48
49
|
const token = load_from_env('SECRET_GITHUB_API_TOKEN');
|
|
49
50
|
if (!token) {
|
|
@@ -62,27 +63,43 @@ export const task = {
|
|
|
62
63
|
const repo_specifier = package_json.name === '@fuzdev/fuz_gitops'
|
|
63
64
|
? '$lib/repo.svelte.js'
|
|
64
65
|
: '@fuzdev/fuz_gitops/repo.svelte.js';
|
|
65
|
-
log.info(
|
|
66
|
+
log.info(`generating ${outfile_json} and ${outfile_ts}`);
|
|
67
|
+
// Generate repos.json with the raw data
|
|
68
|
+
const json_contents = await format_file(JSON.stringify(repos_json), { filepath: outfile_json });
|
|
69
|
+
const existing_json = existsSync(outfile_json) ? await readFile(outfile_json, 'utf8') : '';
|
|
70
|
+
const json_changed = existing_json !== json_contents;
|
|
71
|
+
if (json_changed) {
|
|
72
|
+
log.info(`writing changes to ${print_path(outfile_json)}`);
|
|
73
|
+
await writeFile(outfile_json, json_contents);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
log.info(`no changes to ${print_path(outfile_json)}`);
|
|
77
|
+
}
|
|
78
|
+
// Generate repos.ts that imports from repos.json
|
|
66
79
|
// TODO the `basename` is used here because we don't have an `origin_id` like with gen,
|
|
67
80
|
// and this file gets re-exported,
|
|
68
81
|
// and we don't want the file to change based on where it's being generated,
|
|
69
82
|
// because for example linking to a local package would change the contents
|
|
70
|
-
const
|
|
71
|
-
// generated by ${basename(import.meta.filename)}
|
|
72
|
-
|
|
83
|
+
const ts_contents = `
|
|
84
|
+
// generated by ${basename(import.meta.filename)} - do not edit
|
|
85
|
+
|
|
73
86
|
import type {RepoJson} from '${repo_specifier}';
|
|
74
87
|
|
|
75
|
-
|
|
88
|
+
import json from './repos.json' with {type: 'json'};
|
|
89
|
+
|
|
90
|
+
export const repos_json: Array<RepoJson> = json as unknown as Array<RepoJson>;
|
|
76
91
|
`;
|
|
77
92
|
// TODO think about possibly using the `gen` functionality in this task, not sure what the API design could look like
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
log.info(`no changes to ${print_path(
|
|
93
|
+
const formatted_ts = await format_file(ts_contents, { filepath: outfile_ts });
|
|
94
|
+
const existing_ts = existsSync(outfile_ts) ? await readFile(outfile_ts, 'utf8') : '';
|
|
95
|
+
if (existing_ts === formatted_ts) {
|
|
96
|
+
log.info(`no changes to ${print_path(outfile_ts)}`);
|
|
82
97
|
}
|
|
83
98
|
else {
|
|
84
|
-
log.info(`writing changes to ${print_path(
|
|
85
|
-
await writeFile(
|
|
99
|
+
log.info(`writing changes to ${print_path(outfile_ts)}`);
|
|
100
|
+
await writeFile(outfile_ts, formatted_ts);
|
|
101
|
+
}
|
|
102
|
+
if (json_changed) {
|
|
86
103
|
await invoke_task('gen');
|
|
87
104
|
}
|
|
88
105
|
const changed = await cache.save();
|
package/package.json
CHANGED
|
@@ -50,7 +50,8 @@ export const task: Task<Args> = {
|
|
|
50
50
|
|
|
51
51
|
const {local_repos} = await get_gitops_ready({config, dir, download, log});
|
|
52
52
|
|
|
53
|
-
const
|
|
53
|
+
const outfile_json = resolve(outdir, 'repos.json');
|
|
54
|
+
const outfile_ts = resolve(outdir, 'repos.ts');
|
|
54
55
|
|
|
55
56
|
// This searches the parent directory for the env var, so we don't use SvelteKit's $env imports
|
|
56
57
|
const token = load_from_env('SECRET_GITHUB_API_TOKEN');
|
|
@@ -76,27 +77,44 @@ export const task: Task<Args> = {
|
|
|
76
77
|
? '$lib/repo.svelte.js'
|
|
77
78
|
: '@fuzdev/fuz_gitops/repo.svelte.js';
|
|
78
79
|
|
|
79
|
-
log.info(
|
|
80
|
+
log.info(`generating ${outfile_json} and ${outfile_ts}`);
|
|
80
81
|
|
|
82
|
+
// Generate repos.json with the raw data
|
|
83
|
+
const json_contents = await format_file(JSON.stringify(repos_json), {filepath: outfile_json});
|
|
84
|
+
const existing_json = existsSync(outfile_json) ? await readFile(outfile_json, 'utf8') : '';
|
|
85
|
+
const json_changed = existing_json !== json_contents;
|
|
86
|
+
if (json_changed) {
|
|
87
|
+
log.info(`writing changes to ${print_path(outfile_json)}`);
|
|
88
|
+
await writeFile(outfile_json, json_contents);
|
|
89
|
+
} else {
|
|
90
|
+
log.info(`no changes to ${print_path(outfile_json)}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Generate repos.ts that imports from repos.json
|
|
81
94
|
// TODO the `basename` is used here because we don't have an `origin_id` like with gen,
|
|
82
95
|
// and this file gets re-exported,
|
|
83
96
|
// and we don't want the file to change based on where it's being generated,
|
|
84
97
|
// because for example linking to a local package would change the contents
|
|
85
|
-
const
|
|
86
|
-
// generated by ${basename(import.meta.filename)}
|
|
87
|
-
|
|
98
|
+
const ts_contents = `
|
|
99
|
+
// generated by ${basename(import.meta.filename)} - do not edit
|
|
100
|
+
|
|
88
101
|
import type {RepoJson} from '${repo_specifier}';
|
|
89
102
|
|
|
90
|
-
|
|
103
|
+
import json from './repos.json' with {type: 'json'};
|
|
104
|
+
|
|
105
|
+
export const repos_json: Array<RepoJson> = json as unknown as Array<RepoJson>;
|
|
91
106
|
`;
|
|
92
107
|
// TODO think about possibly using the `gen` functionality in this task, not sure what the API design could look like
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
log.info(`no changes to ${print_path(
|
|
108
|
+
const formatted_ts = await format_file(ts_contents, {filepath: outfile_ts});
|
|
109
|
+
const existing_ts = existsSync(outfile_ts) ? await readFile(outfile_ts, 'utf8') : '';
|
|
110
|
+
if (existing_ts === formatted_ts) {
|
|
111
|
+
log.info(`no changes to ${print_path(outfile_ts)}`);
|
|
97
112
|
} else {
|
|
98
|
-
log.info(`writing changes to ${print_path(
|
|
99
|
-
await writeFile(
|
|
113
|
+
log.info(`writing changes to ${print_path(outfile_ts)}`);
|
|
114
|
+
await writeFile(outfile_ts, formatted_ts);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (json_changed) {
|
|
100
118
|
await invoke_task('gen');
|
|
101
119
|
}
|
|
102
120
|
|