@featherk/icons 0.15.7 → 0.16.0
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/README.md +15 -3
- package/bin/featherk-fontawesome-setup.mjs +4 -0
- package/dist/docs-manifest.d.ts +1 -0
- package/dist/docs-manifest.js +7 -5
- package/dist/fontawesome/build.cjs +1 -2
- package/dist/fontawesome/build.d.ts +1 -1
- package/dist/fontawesome/build.mjs +2 -3
- package/dist/fontawesome/catalog.cjs +0 -13
- package/dist/fontawesome/catalog.d.ts +0 -8
- package/dist/fontawesome/catalog.mjs +0 -13
- package/dist/fontawesome/chunks/{generate-BBurrhLv.cjs → generate-B_FxftR7.cjs} +12 -1
- package/dist/fontawesome/chunks/{generate-Zq9q2YZD.mjs → generate-DF9R65sV.mjs} +13 -2
- package/dist/fontawesome/chunks/manifest-CSRIDvaR.mjs +56 -0
- package/dist/fontawesome/chunks/manifest-Yjw62jxG.cjs +55 -0
- package/dist/fontawesome/cli.cjs +25 -40
- package/dist/fontawesome/cli.mjs +25 -40
- package/dist/fontawesome/generate.d.ts +7 -0
- package/dist/fontawesome/manifest.d.ts +50 -0
- package/dist/fontawesome/setup.cjs +482 -0
- package/dist/fontawesome/setup.d.ts +39 -0
- package/dist/fontawesome/setup.mjs +482 -0
- package/dist/fontawesome/vite.cjs +64 -28
- package/dist/fontawesome/vite.d.ts +26 -5
- package/dist/fontawesome/vite.mjs +65 -29
- package/docs/ICONS.md +1 -1
- package/docs/fontawesome/CreateFontAwesomeManifest.md +1 -1
- package/docs/fontawesome/FontAwesome.md +48 -44
- package/docs/fontawesome/FontAwesomeCLI.md +14 -17
- package/docs/fontawesome/FontAwesomeDeveloperSetup.md +134 -0
- package/docs/fontawesome/LICENSING.md +185 -26
- package/package.json +5 -4
- package/dist/fontawesome/catalog.test.d.ts +0 -1
- package/dist/fontawesome/cli.test.d.ts +0 -1
- package/dist/fontawesome/fontawesome-service.test.d.ts +0 -1
- package/dist/fontawesome/generate.test.d.ts +0 -1
- package/dist/fontawesome/normalize.test.d.ts +0 -1
- package/dist/fontawesome/vite.test.d.ts +0 -1
- package/dist/icon-service.test.d.ts +0 -1
- /package/{scripts/fontawesome.mjs → bin/featherk-fontawesome.mjs} +0 -0
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const node_child_process = require("node:child_process");
|
|
4
|
+
const node_fs = require("node:fs");
|
|
5
|
+
const node_path = require("node:path");
|
|
6
|
+
const node_readline = require("node:readline");
|
|
7
|
+
const node_util = require("node:util");
|
|
8
|
+
const fontawesome_catalog = require("./catalog.cjs");
|
|
9
|
+
const manifest = require("./chunks/manifest-Yjw62jxG.cjs");
|
|
10
|
+
const tokenVariable = "FONTAWESOME_PACKAGE_TOKEN";
|
|
11
|
+
const tokenPlaceholder = `\${${tokenVariable}}`;
|
|
12
|
+
const registry = "https://npm.fontawesome.com/";
|
|
13
|
+
const authKey = "//npm.fontawesome.com/:_authToken";
|
|
14
|
+
const pinRegistry = `--@fortawesome:registry=${registry}`;
|
|
15
|
+
const npmrcLines = [
|
|
16
|
+
"# Route @fortawesome packages to the Font Awesome Pro registry.",
|
|
17
|
+
`@fortawesome:registry=${registry}`,
|
|
18
|
+
"# Authenticate using the token from the environment; never commit a token.",
|
|
19
|
+
`${authKey}=${tokenPlaceholder}`
|
|
20
|
+
];
|
|
21
|
+
const workspaceVariables = [
|
|
22
|
+
"npm_config_workspace",
|
|
23
|
+
"npm_config_workspaces",
|
|
24
|
+
"NPM_CONFIG_WORKSPACE",
|
|
25
|
+
"NPM_CONFIG_WORKSPACES"
|
|
26
|
+
];
|
|
27
|
+
const usage = `Usage:
|
|
28
|
+
featherk-fontawesome-setup --manifest <icons.json> [--free-only | --pro-in-app]
|
|
29
|
+
featherk-fontawesome-setup
|
|
30
|
+
|
|
31
|
+
Run from the application root. The manifest contains
|
|
32
|
+
{ "free": [keys], "pro": [keys] }, the same file the Vite plugin reads.
|
|
33
|
+
|
|
34
|
+
--manifest (default): installs exact Free pins into the app's devDependencies
|
|
35
|
+
from public npm, and writes exact Pro pins into an isolated private source
|
|
36
|
+
project, ${manifest.fontAwesomeProSourcesDir}/, then installs it with the token. The
|
|
37
|
+
app's own install never needs the token. Rerun after changing the manifest.
|
|
38
|
+
Commit package.json, package-lock.json, and ${manifest.fontAwesomeProSourcesDir}/
|
|
39
|
+
(its node_modules is ignored).
|
|
40
|
+
|
|
41
|
+
No arguments: installs ${manifest.fontAwesomeProSourcesDir}/ from its committed
|
|
42
|
+
lockfile with the token, for CI and fresh clones. Run it after the app's own
|
|
43
|
+
"npm ci".
|
|
44
|
+
|
|
45
|
+
--free-only: Free keys only from public npm. No token, no source project.
|
|
46
|
+
|
|
47
|
+
--pro-in-app: installs Free and Pro pins into the app's own devDependencies
|
|
48
|
+
and routes @fortawesome to the Pro registry in the app's .npmrc (token
|
|
49
|
+
placeholder only). Every install of the app, including CI, then needs the
|
|
50
|
+
token for "npm ci --ignore-scripts". Use only when the isolated project is not
|
|
51
|
+
an option.
|
|
52
|
+
|
|
53
|
+
The token comes from ${tokenVariable} or a hidden prompt in an interactive
|
|
54
|
+
terminal. --manifest setup changes package.json and is refused in CI
|
|
55
|
+
(CI, TEAMCITY_VERSION, or GITHUB_ACTIONS is set). Do not export the token
|
|
56
|
+
persistently.`;
|
|
57
|
+
function promptForTerminalToken() {
|
|
58
|
+
const input = process.stdin;
|
|
59
|
+
if (!input.isTTY || typeof input.setRawMode !== "function") {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`${tokenVariable} is not set and this is not an interactive terminal. Provide it through an approved CI secret environment.`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
node_readline.emitKeypressEvents(input);
|
|
65
|
+
process.stdout.write("Font Awesome Pro Package Token (input hidden): ");
|
|
66
|
+
const wasRaw = input.isRaw;
|
|
67
|
+
input.setRawMode(true);
|
|
68
|
+
input.resume();
|
|
69
|
+
return new Promise((resolveToken, rejectToken) => {
|
|
70
|
+
const characters = [];
|
|
71
|
+
const finish = (error) => {
|
|
72
|
+
input.off("keypress", onKeypress);
|
|
73
|
+
input.setRawMode(wasRaw);
|
|
74
|
+
input.pause();
|
|
75
|
+
process.stdout.write("\n");
|
|
76
|
+
if (error) rejectToken(error);
|
|
77
|
+
else resolveToken(characters.join(""));
|
|
78
|
+
};
|
|
79
|
+
const onKeypress = (character, key = {}) => {
|
|
80
|
+
if (key.ctrl && key.name === "c") {
|
|
81
|
+
finish(new Error("Token entry cancelled."));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (key.name === "return" || key.name === "enter") {
|
|
85
|
+
finish();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (key.name === "backspace") {
|
|
89
|
+
if (characters.length) {
|
|
90
|
+
characters.pop();
|
|
91
|
+
process.stdout.write("\b \b");
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!key.ctrl && !key.meta && character && !character.startsWith("\x1B")) {
|
|
96
|
+
for (const item of character) {
|
|
97
|
+
if (item >= " " && item <= "~") {
|
|
98
|
+
characters.push(item);
|
|
99
|
+
process.stdout.write("*");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
input.on("keypress", onKeypress);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const spawnNpm = ({ npmCli, args, cwd, env }) => {
|
|
108
|
+
const result = node_child_process.spawnSync(process.execPath, [npmCli, ...args], {
|
|
109
|
+
cwd,
|
|
110
|
+
env,
|
|
111
|
+
stdio: "inherit"
|
|
112
|
+
});
|
|
113
|
+
if (result.error) throw result.error;
|
|
114
|
+
return result.status ?? 1;
|
|
115
|
+
};
|
|
116
|
+
async function readToken(context) {
|
|
117
|
+
const token = context.env[tokenVariable] || await context.promptForToken();
|
|
118
|
+
if (!token) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
"A Font Awesome Pro Package Token is required to install Pro packages."
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return token;
|
|
124
|
+
}
|
|
125
|
+
function requireNpm(context) {
|
|
126
|
+
const npmCli = context.env.npm_execpath;
|
|
127
|
+
if (!npmCli) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
"Run this command through an npm script or npx so npm is available."
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return npmCli;
|
|
133
|
+
}
|
|
134
|
+
async function readKeys(values, context) {
|
|
135
|
+
if (!values.manifest) {
|
|
136
|
+
throw new Error("Provide --manifest. Use --help for usage.");
|
|
137
|
+
}
|
|
138
|
+
const manifest$1 = await manifest.readFontAwesomeManifest(
|
|
139
|
+
node_path.resolve(context.cwd, values.manifest)
|
|
140
|
+
);
|
|
141
|
+
return manifest.fontAwesomeManifestKeys(manifest$1);
|
|
142
|
+
}
|
|
143
|
+
function resolvePins(keys) {
|
|
144
|
+
const tiers = new Map(
|
|
145
|
+
fontawesome_catalog.fontAwesomeCatalog.map((entry) => [entry.key, entry.tier])
|
|
146
|
+
);
|
|
147
|
+
const pins = /* @__PURE__ */ new Map();
|
|
148
|
+
for (const selection of fontawesome_catalog.resolveFontAwesomeKeys(keys, { allowPro: true })) {
|
|
149
|
+
const spec = selection.package === selection.registryPackage ? selection.version : `npm:${selection.registryPackage}@${selection.version}`;
|
|
150
|
+
const existing = pins.get(selection.package);
|
|
151
|
+
if (existing && existing.spec !== spec) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
`Conflicting pins for ${selection.package}: ${existing.spec} and ${spec}.`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
if (!existing) {
|
|
157
|
+
pins.set(selection.package, {
|
|
158
|
+
tier: tiers.get(selection.key),
|
|
159
|
+
spec,
|
|
160
|
+
key: selection.key
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return pins;
|
|
165
|
+
}
|
|
166
|
+
function checkNpmrc(config, file) {
|
|
167
|
+
let fontAwesomeRegistry;
|
|
168
|
+
let hasAuth = false;
|
|
169
|
+
for (const raw of config.split(/\r?\n/)) {
|
|
170
|
+
const line = raw.trim();
|
|
171
|
+
if (!line || line.startsWith("#") || line.startsWith(";")) continue;
|
|
172
|
+
const separator = line.indexOf("=");
|
|
173
|
+
const key = (separator < 0 ? line : line.slice(0, separator)).trim();
|
|
174
|
+
const value = separator < 0 ? "" : line.slice(separator + 1).trim();
|
|
175
|
+
if (key === "@fortawesome:registry") {
|
|
176
|
+
fontAwesomeRegistry = value;
|
|
177
|
+
} else if (key === authKey && value === tokenPlaceholder) {
|
|
178
|
+
hasAuth = true;
|
|
179
|
+
} else if (key.includes("npm.fontawesome.com")) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
`${file} may configure npm.fontawesome.com only as ${authKey}=${tokenPlaceholder}; remove "${key}".`
|
|
182
|
+
);
|
|
183
|
+
} else if (line.includes(tokenVariable)) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
`${file} references ${tokenVariable} in "${key}"; the token may only authenticate npm.fontawesome.com.`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (fontAwesomeRegistry !== void 0 && fontAwesomeRegistry.replace(/\/?$/, "/") !== registry) {
|
|
190
|
+
throw new Error(
|
|
191
|
+
`${file} routes @fortawesome to ${fontAwesomeRegistry}; the Pro token may only be sent to ${registry}.`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
return { fontAwesomeRegistry, hasAuth };
|
|
195
|
+
}
|
|
196
|
+
function installIntoApp(pins, pro, token, context) {
|
|
197
|
+
const npmCli = requireNpm(context);
|
|
198
|
+
const environment = { ...context.env };
|
|
199
|
+
delete environment[tokenVariable];
|
|
200
|
+
if (pro && token) environment[tokenVariable] = token;
|
|
201
|
+
const specs = [...pins].map(([name, pin]) => `${name}@${pin.spec}`);
|
|
202
|
+
const status = context.runNpm({
|
|
203
|
+
npmCli,
|
|
204
|
+
args: [
|
|
205
|
+
"install",
|
|
206
|
+
"--save-dev",
|
|
207
|
+
"--save-exact",
|
|
208
|
+
"--ignore-scripts",
|
|
209
|
+
"--no-audit",
|
|
210
|
+
"--no-fund",
|
|
211
|
+
...pro ? [pinRegistry] : [],
|
|
212
|
+
...specs
|
|
213
|
+
],
|
|
214
|
+
cwd: context.cwd,
|
|
215
|
+
env: environment
|
|
216
|
+
});
|
|
217
|
+
if (status === 0) {
|
|
218
|
+
context.log(
|
|
219
|
+
`Installed ${specs.length} Font Awesome package(s) into the app: ${specs.join(" ")}`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return status;
|
|
223
|
+
}
|
|
224
|
+
function readDependencies(packageJsonPath) {
|
|
225
|
+
try {
|
|
226
|
+
const { dependencies = {} } = JSON.parse(
|
|
227
|
+
node_fs.readFileSync(packageJsonPath, "utf8")
|
|
228
|
+
);
|
|
229
|
+
return JSON.stringify(
|
|
230
|
+
Object.fromEntries(Object.entries(dependencies).sort())
|
|
231
|
+
);
|
|
232
|
+
} catch {
|
|
233
|
+
return void 0;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function writeSourceProject(sourceRoot, proPins, context) {
|
|
237
|
+
const dependencies = Object.fromEntries(
|
|
238
|
+
[...proPins].map(([name, pin]) => [name, pin.spec]).sort()
|
|
239
|
+
);
|
|
240
|
+
const created = !node_fs.existsSync(node_path.resolve(sourceRoot, "package.json"));
|
|
241
|
+
const lockfilePath = node_path.resolve(sourceRoot, "package-lock.json");
|
|
242
|
+
const removeStaleLockfile = node_fs.existsSync(lockfilePath) && readDependencies(node_path.resolve(sourceRoot, "package.json")) !== JSON.stringify(dependencies);
|
|
243
|
+
const files = {
|
|
244
|
+
".npmrc": `${npmrcLines.join("\n")}
|
|
245
|
+
`,
|
|
246
|
+
".gitignore": "node_modules/\n",
|
|
247
|
+
"package.json": `${JSON.stringify(
|
|
248
|
+
{
|
|
249
|
+
name: manifest.fontAwesomeProSourcesDir,
|
|
250
|
+
version: "0.0.0",
|
|
251
|
+
private: true,
|
|
252
|
+
dependencies
|
|
253
|
+
},
|
|
254
|
+
null,
|
|
255
|
+
2
|
|
256
|
+
)}
|
|
257
|
+
`
|
|
258
|
+
};
|
|
259
|
+
node_fs.mkdirSync(sourceRoot, { recursive: true });
|
|
260
|
+
for (const [name, content] of Object.entries(files)) {
|
|
261
|
+
node_fs.writeFileSync(node_path.resolve(sourceRoot, name), content);
|
|
262
|
+
}
|
|
263
|
+
if (removeStaleLockfile) node_fs.rmSync(lockfilePath);
|
|
264
|
+
context.log(
|
|
265
|
+
`${created ? "Created" : "Updated"} ${manifest.fontAwesomeProSourcesDir}/ with ${proPins.size} Pro package(s).`
|
|
266
|
+
);
|
|
267
|
+
if (removeStaleLockfile) {
|
|
268
|
+
context.log(
|
|
269
|
+
`Removed ${manifest.fontAwesomeProSourcesDir}/package-lock.json because the Pro pins changed; this install regenerates it.`
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async function installSourceProject(sourceRoot, token, context) {
|
|
274
|
+
const npmCli = requireNpm(context);
|
|
275
|
+
const npmrc = `${manifest.fontAwesomeProSourcesDir}/.npmrc`;
|
|
276
|
+
const { fontAwesomeRegistry, hasAuth } = checkNpmrc(
|
|
277
|
+
node_fs.readFileSync(node_path.resolve(sourceRoot, ".npmrc"), "utf8"),
|
|
278
|
+
npmrc
|
|
279
|
+
);
|
|
280
|
+
if (!fontAwesomeRegistry || !hasAuth) {
|
|
281
|
+
throw new Error(
|
|
282
|
+
`${npmrc} must contain @fortawesome:registry=${registry} and ${authKey}=${tokenPlaceholder}. Rerun with --manifest to rewrite it.`
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
const locked = node_fs.existsSync(node_path.resolve(sourceRoot, "package-lock.json"));
|
|
286
|
+
if (context.isCi && !locked) {
|
|
287
|
+
throw new Error(
|
|
288
|
+
`${manifest.fontAwesomeProSourcesDir}/package-lock.json is required in CI. Run setup with --manifest locally first and commit the lockfile.`
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
const environment = {
|
|
292
|
+
...context.env,
|
|
293
|
+
[tokenVariable]: await readToken(context)
|
|
294
|
+
};
|
|
295
|
+
for (const name of workspaceVariables) delete environment[name];
|
|
296
|
+
const status = context.runNpm({
|
|
297
|
+
npmCli,
|
|
298
|
+
args: [
|
|
299
|
+
locked ? "ci" : "install",
|
|
300
|
+
"--workspaces=false",
|
|
301
|
+
"--ignore-scripts",
|
|
302
|
+
"--no-audit",
|
|
303
|
+
"--no-fund",
|
|
304
|
+
pinRegistry
|
|
305
|
+
],
|
|
306
|
+
cwd: sourceRoot,
|
|
307
|
+
env: environment
|
|
308
|
+
});
|
|
309
|
+
if (status !== 0) return status;
|
|
310
|
+
const lockfile = `${manifest.fontAwesomeProSourcesDir}/package-lock.json`;
|
|
311
|
+
context.log(
|
|
312
|
+
locked ? `Pro sources installed from ${lockfile}.` : `Pro sources installed. Review and commit ${lockfile}.`
|
|
313
|
+
);
|
|
314
|
+
return 0;
|
|
315
|
+
}
|
|
316
|
+
async function setupFromManifest(values, context) {
|
|
317
|
+
const { log } = context;
|
|
318
|
+
const freeOnly = Boolean(values["free-only"]);
|
|
319
|
+
const proInApp = Boolean(values["pro-in-app"]);
|
|
320
|
+
if (freeOnly && proInApp) {
|
|
321
|
+
throw new Error("Use either --free-only or --pro-in-app, not both.");
|
|
322
|
+
}
|
|
323
|
+
if (context.isCi) {
|
|
324
|
+
throw new Error(
|
|
325
|
+
`--manifest setup changes package.json and is a local step. In CI, run the app's own "npm ci", then featherk-fontawesome-setup without arguments to install ${manifest.fontAwesomeProSourcesDir}/.`
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
const appRoot = context.cwd;
|
|
329
|
+
if (!node_fs.existsSync(node_path.resolve(appRoot, "package.json"))) {
|
|
330
|
+
throw new Error(
|
|
331
|
+
"Run this command from the application root (package.json not found)."
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
const pins = resolvePins(await readKeys(values, context));
|
|
335
|
+
if (!pins.size) {
|
|
336
|
+
throw new Error("No Font Awesome keys selected.");
|
|
337
|
+
}
|
|
338
|
+
const freePins = new Map([...pins].filter(([, pin]) => pin.tier !== "pro"));
|
|
339
|
+
const proPins = new Map([...pins].filter(([, pin]) => pin.tier === "pro"));
|
|
340
|
+
if (freeOnly && proPins.size) {
|
|
341
|
+
throw new Error(
|
|
342
|
+
`--free-only cannot install Pro keys: ${[...proPins.values()].map((pin) => pin.key).join(", ")}.`
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
const npmrcPath = node_path.resolve(appRoot, ".npmrc");
|
|
346
|
+
const config = node_fs.existsSync(npmrcPath) ? node_fs.readFileSync(npmrcPath, "utf8") : "";
|
|
347
|
+
const { fontAwesomeRegistry, hasAuth } = checkNpmrc(config, ".npmrc");
|
|
348
|
+
const sourceRoot = node_path.resolve(appRoot, manifest.fontAwesomeProSourcesDir);
|
|
349
|
+
const isolated = manifest.isFontAwesomeIsolated(appRoot);
|
|
350
|
+
if (proInApp && isolated) {
|
|
351
|
+
throw new Error(
|
|
352
|
+
`${manifest.fontAwesomeProSourcesDir}/ exists, so this app keeps Pro in the isolated source project. Run without --pro-in-app, or remove ${manifest.fontAwesomeProSourcesDir}/ first.`
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
if (!proInApp && fontAwesomeRegistry) {
|
|
356
|
+
throw new Error(
|
|
357
|
+
`.npmrc routes @fortawesome to ${fontAwesomeRegistry}, so this app installs Pro in the app itself. Rerun with --pro-in-app.`
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
if (freeOnly && isolated) {
|
|
361
|
+
throw new Error(
|
|
362
|
+
`${manifest.fontAwesomeProSourcesDir}/ exists, so this app uses Pro. Run without --free-only, or remove ${manifest.fontAwesomeProSourcesDir}/ first.`
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
if (proInApp) {
|
|
366
|
+
const token = proPins.size ? await readToken(context) : void 0;
|
|
367
|
+
if (proPins.size) {
|
|
368
|
+
const missing = [];
|
|
369
|
+
if (!fontAwesomeRegistry) missing.push(npmrcLines[0], npmrcLines[1]);
|
|
370
|
+
if (!hasAuth) missing.push(npmrcLines[2], npmrcLines[3]);
|
|
371
|
+
if (missing.length) {
|
|
372
|
+
const separator = config && !config.endsWith("\n") ? "\n" : "";
|
|
373
|
+
node_fs.writeFileSync(
|
|
374
|
+
npmrcPath,
|
|
375
|
+
`${config}${separator}${missing.join("\n")}
|
|
376
|
+
`
|
|
377
|
+
);
|
|
378
|
+
log(
|
|
379
|
+
`${config ? "Updated" : "Created"} .npmrc with the Font Awesome registry and token placeholder.`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const status2 = installIntoApp(pins, proPins.size > 0, token, context);
|
|
384
|
+
if (status2 !== 0) return status2;
|
|
385
|
+
log(lifecycleNote);
|
|
386
|
+
log(
|
|
387
|
+
`Next: commit .npmrc, package.json, and package-lock.json. Configure the Vite plugin with { manifest }. Every later install, including CI, gives ${tokenVariable} only to "npm ci --ignore-scripts"; run needed install scripts and builds without it.`
|
|
388
|
+
);
|
|
389
|
+
return 0;
|
|
390
|
+
}
|
|
391
|
+
if (freePins.size) {
|
|
392
|
+
const status2 = installIntoApp(freePins, false, void 0, context);
|
|
393
|
+
if (status2 !== 0) return status2;
|
|
394
|
+
log(lifecycleNote);
|
|
395
|
+
}
|
|
396
|
+
if (!proPins.size) {
|
|
397
|
+
if (isolated) {
|
|
398
|
+
log(
|
|
399
|
+
`The manifest has no Pro keys; ${manifest.fontAwesomeProSourcesDir}/ is no longer needed and can be removed.`
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
log(
|
|
403
|
+
"Next: commit package.json and package-lock.json. Configure the Vite plugin with { manifest }; no token is needed."
|
|
404
|
+
);
|
|
405
|
+
return 0;
|
|
406
|
+
}
|
|
407
|
+
writeSourceProject(sourceRoot, proPins, context);
|
|
408
|
+
const status = await installSourceProject(sourceRoot, void 0, context);
|
|
409
|
+
if (status !== 0) return status;
|
|
410
|
+
log(
|
|
411
|
+
`Next: commit package.json, package-lock.json, and ${manifest.fontAwesomeProSourcesDir}/. Configure the Vite plugin with { manifest }; builds include Pro icons wherever ${manifest.fontAwesomeProSourcesDir}/ is installed. In CI, run the app's "npm ci" without the token, then featherk-fontawesome-setup with ${tokenVariable}, then the normal build.`
|
|
412
|
+
);
|
|
413
|
+
return 0;
|
|
414
|
+
}
|
|
415
|
+
const lifecycleNote = "Lifecycle scripts were skipped. If needed, run npm rebuild for dependency scripts and the app's own scripts (e.g. npm run prepare --if-present).";
|
|
416
|
+
const removedFlags = [
|
|
417
|
+
"--keys",
|
|
418
|
+
"--source-root",
|
|
419
|
+
"--init",
|
|
420
|
+
"--force",
|
|
421
|
+
"--refresh-lock"
|
|
422
|
+
];
|
|
423
|
+
async function runFontAwesomeSetup(args, io = {}) {
|
|
424
|
+
const cwd = io.cwd ?? process.cwd();
|
|
425
|
+
const env = io.env ?? process.env;
|
|
426
|
+
const stderr = io.stderr ?? console.error;
|
|
427
|
+
const context = {
|
|
428
|
+
cwd,
|
|
429
|
+
env,
|
|
430
|
+
// TeamCity and GitHub Actions are detected directly; TeamCity does not set CI.
|
|
431
|
+
isCi: Boolean(env.CI) && env.CI !== "false" || Boolean(env.TEAMCITY_VERSION || env.GITHUB_ACTIONS),
|
|
432
|
+
log: io.stdout ?? console.log,
|
|
433
|
+
promptForToken: io.promptForToken ?? promptForTerminalToken,
|
|
434
|
+
runNpm: io.runNpm ?? spawnNpm
|
|
435
|
+
};
|
|
436
|
+
try {
|
|
437
|
+
const removed = removedFlags.find(
|
|
438
|
+
(flag) => args.some((arg) => arg === flag || arg.startsWith(`${flag}=`))
|
|
439
|
+
);
|
|
440
|
+
if (removed) {
|
|
441
|
+
throw new Error(
|
|
442
|
+
`${removed} was removed in 0.16.0. Run setup with --manifest; Pro sources always live in ${manifest.fontAwesomeProSourcesDir}/, and rerunning with --manifest updates them. Use --help for usage.`
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
const { values } = node_util.parseArgs({
|
|
446
|
+
args: [...args],
|
|
447
|
+
options: {
|
|
448
|
+
"free-only": { type: "boolean" },
|
|
449
|
+
"pro-in-app": { type: "boolean" },
|
|
450
|
+
manifest: { type: "string" },
|
|
451
|
+
help: { type: "boolean", short: "h" }
|
|
452
|
+
},
|
|
453
|
+
strict: true,
|
|
454
|
+
allowPositionals: false
|
|
455
|
+
});
|
|
456
|
+
if (values.help) {
|
|
457
|
+
context.log(usage);
|
|
458
|
+
return 0;
|
|
459
|
+
}
|
|
460
|
+
if (values.manifest !== void 0) {
|
|
461
|
+
return await setupFromManifest(values, context);
|
|
462
|
+
}
|
|
463
|
+
if (values["free-only"] || values["pro-in-app"]) {
|
|
464
|
+
throw new Error("--free-only and --pro-in-app require --manifest.");
|
|
465
|
+
}
|
|
466
|
+
if (!manifest.isFontAwesomeIsolated(cwd)) {
|
|
467
|
+
throw new Error(
|
|
468
|
+
`${manifest.fontAwesomeProSourcesDir}/package.json was not found. Run from the application root; for first-time setup, run with --manifest <icons.json>.`
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
return await installSourceProject(
|
|
472
|
+
node_path.resolve(cwd, manifest.fontAwesomeProSourcesDir),
|
|
473
|
+
void 0,
|
|
474
|
+
context
|
|
475
|
+
);
|
|
476
|
+
} catch (error) {
|
|
477
|
+
stderr(error instanceof Error ? error.message : "Unknown error");
|
|
478
|
+
return 1;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
exports.checkNpmrc = checkNpmrc;
|
|
482
|
+
exports.runFontAwesomeSetup = runFontAwesomeSetup;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Runs npm with the given arguments and returns its exit status. */
|
|
2
|
+
export type FontAwesomeNpmRunner = (options: {
|
|
3
|
+
npmCli: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
cwd: string;
|
|
6
|
+
env: NodeJS.ProcessEnv;
|
|
7
|
+
}) => number;
|
|
8
|
+
/** Injectable process I/O used by the setup entry point and its tests. */
|
|
9
|
+
export interface FontAwesomeSetupIO {
|
|
10
|
+
cwd?: string;
|
|
11
|
+
env?: NodeJS.ProcessEnv;
|
|
12
|
+
stdout?: (message: string) => void;
|
|
13
|
+
stderr?: (message: string) => void;
|
|
14
|
+
/** Called when the token is not in the environment. */
|
|
15
|
+
promptForToken?: () => Promise<string>;
|
|
16
|
+
runNpm?: FontAwesomeNpmRunner;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks where an .npmrc could send the package token before it is supplied.
|
|
20
|
+
* The token variable may appear only in the npm.fontawesome.com auth entry,
|
|
21
|
+
* that host may carry no other credential, and @fortawesome may route only to
|
|
22
|
+
* the Font Awesome registry.
|
|
23
|
+
*
|
|
24
|
+
* @returns The configured @fortawesome registry, if any, and whether the
|
|
25
|
+
* placeholder auth entry exists.
|
|
26
|
+
* @throws If the config could expose the token or a literal credential.
|
|
27
|
+
*/
|
|
28
|
+
export declare function checkNpmrc(config: string, file: string): {
|
|
29
|
+
fontAwesomeRegistry?: string;
|
|
30
|
+
hasAuth: boolean;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Parses setup arguments and runs manifest setup, or installs the isolated
|
|
34
|
+
* source project when no arguments are given.
|
|
35
|
+
*
|
|
36
|
+
* @returns `0` on success, npm's exit status when an install fails, and `1`
|
|
37
|
+
* when argument, manifest, config, or environment validation fails.
|
|
38
|
+
*/
|
|
39
|
+
export declare function runFontAwesomeSetup(args: readonly string[], io?: FontAwesomeSetupIO): Promise<number>;
|