1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 |
|
4 | var _fsExtra = require("fs-extra");
|
5 |
|
6 | var _fsExtra2 = _interopRequireDefault(_fsExtra);
|
7 |
|
8 | var _meow = require("meow");
|
9 |
|
10 | var _meow2 = _interopRequireDefault(_meow);
|
11 |
|
12 | var _path = require("path");
|
13 |
|
14 | var _path2 = _interopRequireDefault(_path);
|
15 |
|
16 | var _resolveFrom = require("resolve-from");
|
17 |
|
18 | var _resolveFrom2 = _interopRequireDefault(_resolveFrom);
|
19 |
|
20 | var _standalone = require("./standalone");
|
21 |
|
22 | var _standalone2 = _interopRequireDefault(_standalone);
|
23 |
|
24 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25 |
|
26 | const cli = (0, _meow2.default)(`
|
27 | Usage: webfont [input] [options]
|
28 |
|
29 | Input: File(s) or glob(s).
|
30 |
|
31 | If an input argument is wrapped in quotation marks, it will be passed to "fast-glob"
|
32 | for cross-platform glob support.
|
33 |
|
34 | Options:
|
35 |
|
36 | --config
|
37 |
|
38 | Path to a specific configuration file (JSON, YAML, or CommonJS)
|
39 | or the name of a module in \`node_modules\` that points to one.
|
40 | If no \`--config\` argument is provided, webfont will search for
|
41 | configuration files in the following places, in this order:
|
42 | - a \`webfont\` property in \`package.json\`
|
43 | - a \`.webfontrc\` file (with or without filename extension:
|
44 | \`.json\`, \`.yaml\`, and \`.js\` are available)
|
45 | - a \`webfont.config.js\` file exporting a JS object
|
46 | The search will begin in the working directory and move up the
|
47 | directory tree until a configuration file is found.
|
48 |
|
49 | -f, --font-name
|
50 |
|
51 | The font family name you want, default: "webfont".
|
52 |
|
53 | -h, --help
|
54 |
|
55 | Output usage information.
|
56 |
|
57 | -v, --version
|
58 |
|
59 | Output the version number.
|
60 |
|
61 | -r, --formats
|
62 |
|
63 | Only this formats generate.
|
64 |
|
65 | -d, --dest
|
66 |
|
67 | Destination for generated fonts.
|
68 |
|
69 | -t, --template
|
70 |
|
71 | Type of template ('css', 'scss') or path to custom template.
|
72 |
|
73 | -s, --dest-template
|
74 |
|
75 | Destination for generated template. If not passed used \`dest\` argument value.
|
76 |
|
77 | -c, --template-class-name
|
78 |
|
79 | Class name in css template.
|
80 |
|
81 | -p, --template-font-path
|
82 |
|
83 | Font path in css template.
|
84 |
|
85 | -n, --template-font-name
|
86 |
|
87 | Font name in css template.
|
88 |
|
89 | --verbose
|
90 |
|
91 | Tell me everything!.
|
92 |
|
93 | For "svgicons2svgfont":
|
94 |
|
95 | --font-id
|
96 |
|
97 | The font id you want, default as "--font-name".
|
98 |
|
99 | --font-style
|
100 |
|
101 | The font style you want.
|
102 |
|
103 | --font-weight
|
104 |
|
105 | The font weight you want.
|
106 |
|
107 | --fixed-width
|
108 |
|
109 | Creates a monospace font of the width of the largest input icon.
|
110 |
|
111 | --center-horizontally
|
112 |
|
113 | Calculate the bounds of a glyph and center it horizontally.
|
114 |
|
115 | --normalize
|
116 |
|
117 | Normalize icons by scaling them to the height of the highest icon.
|
118 |
|
119 | --font-height
|
120 |
|
121 | The outputted font height [MAX(icons.height)].
|
122 |
|
123 | --round
|
124 |
|
125 | Setup the SVG path rounding [10e12].
|
126 |
|
127 | --descent
|
128 |
|
129 | The font descent [0].
|
130 |
|
131 | --ascent
|
132 |
|
133 | The font ascent [height - descent].
|
134 |
|
135 | --start-unicode
|
136 |
|
137 | The start unicode codepoint for unprefixed files [0xEA01].
|
138 |
|
139 | --prepend-unicode
|
140 |
|
141 | Prefix files with their automatically allocated unicode codepoint.
|
142 |
|
143 | --metadata
|
144 |
|
145 | Content of the metadata tag.
|
146 | `, {
|
147 | autoHelp: false,
|
148 | autoVersion: false,
|
149 | flags: {
|
150 | ascent: {
|
151 | type: "string"
|
152 | },
|
153 | "center-horizontally": {
|
154 | type: "boolean"
|
155 | },
|
156 | config: {
|
157 | default: null
|
158 | },
|
159 | descent: {
|
160 | type: "string"
|
161 | },
|
162 | dest: {
|
163 | alias: "d",
|
164 | default: process.cwd(),
|
165 | type: "string"
|
166 | },
|
167 | "dest-template": {
|
168 | alias: "s",
|
169 | type: "string"
|
170 | },
|
171 | "fixed-width": {
|
172 | type: "boolean"
|
173 | },
|
174 | "font-height": {
|
175 | type: "string"
|
176 | },
|
177 | "font-id": {
|
178 | type: "string"
|
179 | },
|
180 | "font-name": {
|
181 | alias: "u",
|
182 | type: "string"
|
183 | },
|
184 | "font-style": {
|
185 | type: "string"
|
186 | },
|
187 | "font-weight": {
|
188 | type: "string"
|
189 | },
|
190 | formats: {
|
191 | alias: "f"
|
192 | },
|
193 | help: {
|
194 | alias: "h",
|
195 | type: "boolean"
|
196 | },
|
197 | normalize: {
|
198 | type: "boolean"
|
199 | },
|
200 | "prepend-unicode": {
|
201 | type: "boolean"
|
202 | },
|
203 | round: {
|
204 | type: "string"
|
205 | },
|
206 | "start-unicode": {
|
207 | type: "string"
|
208 | },
|
209 | template: {
|
210 | alias: "t",
|
211 | type: "string"
|
212 | },
|
213 | "template-class-name": {
|
214 | alias: "c",
|
215 | type: "string"
|
216 | },
|
217 | "template-font-name": {
|
218 | alias: "n",
|
219 | type: "string"
|
220 | },
|
221 | "template-font-path": {
|
222 | alias: "p",
|
223 | type: "string"
|
224 | },
|
225 | verbose: {
|
226 | default: false,
|
227 | type: "boolean"
|
228 | },
|
229 | version: {
|
230 | alias: "v",
|
231 | type: "boolean"
|
232 | }
|
233 | }
|
234 | });
|
235 |
|
236 | const optionsBase = {};
|
237 |
|
238 | if (cli.flags.config) {
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 | optionsBase.configFile = (0, _resolveFrom2.default)(process.cwd(), cli.flags.config) || _path2.default.join(process.cwd(), cli.flags.config);
|
246 | }
|
247 |
|
248 | if (cli.flags.fontName) {
|
249 | optionsBase.fontName = cli.flags.fontName;
|
250 | }
|
251 |
|
252 | if (cli.flags.formats) {
|
253 | optionsBase.formats = cli.flags.formats;
|
254 | }
|
255 |
|
256 | if (cli.flags.dest) {
|
257 | optionsBase.dest = cli.flags.dest;
|
258 | }
|
259 |
|
260 | if (cli.flags.template) {
|
261 | optionsBase.template = cli.flags.template;
|
262 | }
|
263 |
|
264 | if (cli.flags.templateClassName) {
|
265 | optionsBase.templateClassName = cli.flags.templateClassName;
|
266 | }
|
267 |
|
268 | if (cli.flags.templateFontPath) {
|
269 | optionsBase.templateFontPath = cli.flags.templateFontPath;
|
270 | }
|
271 |
|
272 | if (cli.flags.templateFontName) {
|
273 | optionsBase.templateFontName = cli.flags.templateFontName;
|
274 | }
|
275 |
|
276 | if (cli.flags.destTemplate) {
|
277 | optionsBase.destTemplate = cli.flags.destTemplate;
|
278 | }
|
279 |
|
280 | if (cli.flags.verbose) {
|
281 | optionsBase.verbose = cli.flags.verbose;
|
282 | }
|
283 |
|
284 | if (cli.flags.fontId) {
|
285 | optionsBase.fontId = cli.flags.fontId;
|
286 | }
|
287 |
|
288 | if (cli.flags.fontStyle) {
|
289 | optionsBase.fontStyle = cli.flags.fontStyle;
|
290 | }
|
291 |
|
292 | if (cli.flags.fontWeight) {
|
293 | optionsBase.fontWeight = cli.flags.fontWeight;
|
294 | }
|
295 |
|
296 | if (cli.flags.fixedWidth) {
|
297 | optionsBase.fixedWidth = cli.flags.fixedWidth;
|
298 | }
|
299 |
|
300 | if (cli.flags.centerHorizontally) {
|
301 | optionsBase.centerHorizontally = cli.flags.centerHorizontally;
|
302 | }
|
303 |
|
304 | if (cli.flags.normalize) {
|
305 | optionsBase.normalize = cli.flags.normalize;
|
306 | }
|
307 |
|
308 | if (cli.flags.fontHeight) {
|
309 | optionsBase.fontHeight = cli.flags.fontHeight;
|
310 | }
|
311 |
|
312 | if (cli.flags.round) {
|
313 | optionsBase.round = cli.flags.round;
|
314 | }
|
315 |
|
316 | if (cli.flags.descent) {
|
317 | optionsBase.descent = cli.flags.descent;
|
318 | }
|
319 |
|
320 | if (cli.flags.ascent) {
|
321 | optionsBase.ascent = cli.flags.ascent;
|
322 | }
|
323 |
|
324 | if (cli.flags.startUnicode) {
|
325 | optionsBase.startUnicode = cli.flags.startUnicode;
|
326 | }
|
327 |
|
328 | if (cli.flags.prependUnicode) {
|
329 | optionsBase.prependUnicode = cli.flags.prependUnicode;
|
330 | }
|
331 |
|
332 | if (cli.flags.metadata) {
|
333 | optionsBase.metadata = cli.flags.metadata;
|
334 | }
|
335 |
|
336 | if (cli.flags.help || cli.flags.h) {
|
337 | cli.showHelp();
|
338 | }
|
339 |
|
340 | if (cli.flags.version || cli.flags.v) {
|
341 | cli.showVersion();
|
342 | }
|
343 |
|
344 | Promise.resolve().then(() => Object.assign({}, optionsBase, {
|
345 | files: cli.input
|
346 | })).then(options => {
|
347 | if (options.files.length === 0) {
|
348 | cli.showHelp();
|
349 | }
|
350 |
|
351 | return (0, _standalone2.default)(options).then(result => {
|
352 | result.config = Object.assign({}, {
|
353 | dest: options.dest,
|
354 | destTemplate: options.destTemplate
|
355 | }, result.config);
|
356 |
|
357 | return result;
|
358 | });
|
359 | }).then(result => {
|
360 | const { fontName, dest } = result.config;
|
361 |
|
362 | let destTemplate = null;
|
363 |
|
364 | if (result.template) {
|
365 | ({ destTemplate } = result.config);
|
366 |
|
367 | if (!destTemplate) {
|
368 | destTemplate = dest;
|
369 | }
|
370 |
|
371 | if (result.usedBuildInTemplate) {
|
372 | destTemplate = _path2.default.join(destTemplate, `${result.config.fontName}.${result.config.template}`);
|
373 | } else {
|
374 | destTemplate = _path2.default.join(destTemplate, _path2.default.basename(result.config.template).replace(".njk", ""));
|
375 | }
|
376 | }
|
377 |
|
378 | return Promise.resolve().then(() => Promise.all(Object.keys(result).map(type => {
|
379 | if (type === "config" || type === "usedBuildInTemplate" || type === "glyphsData") {
|
380 | return null;
|
381 | }
|
382 |
|
383 | const content = result[type];
|
384 | let file = null;
|
385 |
|
386 | if (type !== "template") {
|
387 | file = _path2.default.resolve(_path2.default.join(dest, `${fontName}.${type}`));
|
388 | } else {
|
389 | file = _path2.default.resolve(destTemplate);
|
390 | }
|
391 |
|
392 | return _fsExtra2.default.writeFile(file, content);
|
393 | }))).then(() => Promise.resolve(result));
|
394 | }).catch(error => {
|
395 | console.log(error.stack);
|
396 |
|
397 | const exitCode = typeof error.code === "number" ? error.code : 1;
|
398 |
|
399 | process.exit(exitCode);
|
400 | }); |
\ | No newline at end of file |