1
1
#!/usr/bin/env node
2
2
/* eslint no-console: off */
3
3
4
- import fs from 'fs' ;
5
- import path from 'path' ;
6
- import { load } from '../src/opentype' ;
4
+ const process = require ( 'process' )
5
+ , fs = require ( 'fs' )
6
+ , path = require ( 'path' )
7
+ , { load, woff_to_otf } = require ( '../dist/opentype.js' )
8
+ ;
7
9
8
10
// Print out information about the font on the console.
9
11
function printFontInfo ( font ) {
@@ -30,11 +32,13 @@ function walk(dir, fn) {
30
32
31
33
// Print out usage information.
32
34
function printUsage ( ) {
33
- console . log ( 'Usage: ot command [dir|file ]' ) ;
35
+ console . log ( 'Usage: ot < command> [...args ]' ) ;
34
36
console . log ( ) ;
35
37
console . log ( 'Commands:' ) ;
36
38
console . log ( ) ;
37
- console . log ( ' info Get information of specified font or fonts in the specified directory.' ) ;
39
+ console . log ( ' info [dir|file] Get information of specified font or fonts in the specified directory.' ) ;
40
+ console . log ( ) ;
41
+ console . log ( ' woff_2_otf <woff_font_file> [otf_font_file] Uncompress woff file into otf.' ) ;
38
42
console . log ( ) ;
39
43
}
40
44
@@ -65,7 +69,7 @@ if (process.argv.length < 3) {
65
69
} else {
66
70
var command = process . argv [ 2 ] ;
67
71
if ( command === 'info' ) {
68
- var fontpath = process . argv . length === 3 ? '.' : process . argv [ 3 ] ;
72
+ var fontpath = process . argv . length === 4 ? '.' : process . argv [ 3 ] ;
69
73
if ( fs . existsSync ( fontpath ) ) {
70
74
var ext = path . extname ( fontpath ) . toLowerCase ( ) ;
71
75
if ( fs . statSync ( fontpath ) . isDirectory ( ) ) {
@@ -78,6 +82,24 @@ if (process.argv.length < 3) {
78
82
} else {
79
83
console . log ( 'Path not found' ) ;
80
84
}
85
+ }
86
+ else if ( command === 'woff_2_otf' ) {
87
+ if ( process . argv . length < 4 ) {
88
+ printUsage ( ) ;
89
+ process . exit ( 1 ) ;
90
+ }
91
+ const fontpath = process . argv [ 3 ] ;
92
+ if ( ! fs . existsSync ( fontpath ) ) {
93
+ console . log ( `Font file at path not found.` ) ;
94
+ process . exit ( 1 ) ;
95
+ }
96
+ const targetPath = process . argv . length >= 5
97
+ ? process . argv [ 4 ]
98
+ : `${ path . join ( path . dirname ( fontpath ) , path . basename ( fontpath , path . extname ( fontpath ) ) ) } .otf`
99
+ , buffer = fs . readFileSync ( fontpath )
100
+ , result = woff_to_otf ( buffer )
101
+ ;
102
+ fs . writeFileSync ( targetPath , new DataView ( result ) ) ;
81
103
} else {
82
104
printUsage ( ) ;
83
105
}
0 commit comments