forked from saberzero1/quartz-themes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.js
More file actions
179 lines (168 loc) · 4.98 KB
/
convert.js
File metadata and controls
179 lines (168 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import * as fs from "fs";
import * as path from "path";
import { staticMode, testMode, themes, themeToTest } from "./config.mjs";
import { format } from "./extensions/formatter.mjs";
import getManifestCollection from "./extensions/manifest.mjs";
import getThemeCollection from "./extensions/themelist.mjs";
import updateMiscFiles from "./extensions/update-misc-files.mjs";
import { inlineScssUseRulesAndClean } from "./util/at-use-embed.mjs";
import colors from "./util/color-convert.mjs";
import {
extractClassToggleCss,
extractStyleSettings,
extractStyleSettingsFromFile,
replaceVariableValue,
} from "./util/postcss-style-settings.mjs";
import {
combineIdenticalSelectors,
getAllDarkThemeRules,
getAllLightThemeRules,
getCombinedThemeVariables,
getRuleDeclarations,
removeEmptyRules,
splitCombinedRules,
} from "./util/postcss.mjs";
import { prune } from "./util/prune-unused.mjs";
import generateStatic from "./util/static-custom-properties.mjs";
import {
applyRuleToString,
cleanRulesAfterRun,
cleanup,
clearDirectories,
clearDirectoryContents,
copyFileToDirectory,
ensureDirectoryExists,
generateFundingLinks,
getCommandLineArgs,
getExtras,
getFilesUnderDirectoryToStringArray,
getFixes,
getFonts,
getTheme,
getValueFromDictionary,
isDarkTheme,
isFullTheme,
isLightTheme,
listFoldersInDirectory,
readJsonFileAsDictionary,
replaceInFile,
sanitizeFilenamePreservingEmojis as sanitize,
} from "./util/util.mjs";
import {
cleanCSS,
extractCSS,
writeIndex,
writePrettier,
writeStyleSettings,
} from "./util/writer.mjs";
let singleThemeName = "";
const start = Date.now();
// STEPS:
//
// 1. Get current folder/working directory.
// 2. Get the manifest JSON data for every theme.
// 3. Generate the file structure for automatic conversion.
// 4. Generate files from templates.
// 5. Populate README files.
// 6. Retrieve the variables from CSS.
// 7. Output variables theme sass file.
// 8. Generate sass for Quartz.
const args = getCommandLineArgs();
if (args.includes("--copy")) {
const sourceFolders = listFoldersInDirectory(
"./runner/vault/.obsidian/themes",
);
const folders = listFoldersInDirectory("./obsidian");
// Create missing theme folders
// const difference = sourceFolders.filter((x) => !folders.includes(x));
sourceFolders.forEach((folder) => {
// copy with subfolders
fs.cpSync(
`./runner/vault/.obsidian/themes/${folder}`,
`./obsidian/${folder.replaceAll("’")}`,
{ recursive: true },
);
});
}
const manifestCollection = getManifestCollection();
const themeCollection = getThemeCollection();
// STEP 3
clearDirectoryContents(`./themes`);
themeCollection.forEach((manifest) => {
if (!fs.existsSync(`./themes/${manifest.name}`)) {
fs.mkdirSync(`./themes/${manifest.name}`);
}
});
// README.md
themeCollection.forEach((manifest) => {
copyFileToDirectory(`./templates/README.md`, `./themes/${manifest.name}`);
});
themeCollection.forEach((theme) => {
const manifest = manifestCollection.find(
(m) => sanitize(m.name) === theme.name.split(".")[0],
);
console.log(manifest);
replaceInFile(
`./themes/${theme.name}/README.md`,
"%OBSIDIAN_THEME_NAME%",
manifest.name,
);
});
themeCollection.forEach((manifest) => {
replaceInFile(
`./themes/${manifest.name}/README.md`,
"%OBSIDIAN_THEME_NAME_SANITIZED%",
manifest.name,
);
});
themeCollection.forEach((theme) => {
const manifest = manifestCollection.find(
(m) => sanitize(m.name) === theme.name.split(".")[0],
);
const authorValue =
getValueFromDictionary(manifest, "author") !== ""
? getValueFromDictionary(manifest, "author")
: "No author provided";
const authorUrlValue =
getValueFromDictionary(manifest, "authorUrl") !== ""
? getValueFromDictionary(manifest, "authorUrl")
: "";
const authorString =
authorUrlValue !== ""
? `<a href="${authorUrlValue}" target="_blank" rel="noopener noreferrer">${authorValue}</a>`
: authorValue;
replaceInFile(
`./themes/${theme.name}/README.md`,
"%OBSIDIAN_THEME_AUTHOR%",
authorString,
);
});
themeCollection.forEach((theme) => {
const manifest = manifestCollection.find(
(m) => sanitize(m.name) === theme.name.split(".")[0].toLowerCase(),
);
const result = generateFundingLinks(manifest);
replaceInFile(
`./themes/${theme.name}/README.md`,
"%OBSIDIAN_THEME_AUTHOR_DONATE_URL%",
result,
);
});
themeCollection.forEach((manifest) => {
const readmePath = `./themes/${manifest.name}/README.md`;
const content = fs.readFileSync(readmePath, "utf8");
fs.writeFileSync(readmePath, format(content, "markdown"), "utf8");
});
themeCollection.forEach((manifest) => {
fs.copyFileSync(
`./runner/results/${manifest.name}/_index.scss`,
`./themes/${manifest.name}/_index.scss`,
);
});
themeCollection.forEach((manifest) => {
fs.copyFileSync(
`./runner/results/${manifest.name}/publish.css`,
`./themes/${manifest.name}/publish.css`,
);
});
updateMiscFiles(manifestCollection, themeCollection);