punchcutter 2.0.5 → 2.0.7
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/lib/buildGlyph.js +12 -16
- package/lib/buildJsFont.js +2 -4
- package/lib/buildPngSprite.js +12 -24
- package/lib/buildSvgSprite.js +2 -4
- package/lib/buildWebFont.js +2 -2
- package/lib/loadFiles.js +3 -5
- package/lib/svg2pngMin.js +2 -4
- package/package.json +15 -17
- package/test/index.js +3 -5
- package/lib/multiGlob.js +0 -23
package/lib/buildGlyph.js
CHANGED
|
@@ -3,16 +3,14 @@ const _ = require('lodash');
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
4
|
const DirectoryColorfy = require('directory-colorfy');
|
|
5
5
|
const fs = require('fs-extra');
|
|
6
|
+
const globby = require('globby');
|
|
6
7
|
const path = require('path');
|
|
7
8
|
const Promise = require('bluebird');
|
|
8
9
|
const loadFiles = require('./loadFiles');
|
|
9
|
-
const multiGlob = require('./multiGlob');
|
|
10
10
|
const svg2pngMin = require('./svg2pngMin');
|
|
11
11
|
const svgMin = require('./svgMin');
|
|
12
12
|
const {PNG, SVG} = require('./constants');
|
|
13
13
|
|
|
14
|
-
Promise.promisifyAll(fs);
|
|
15
|
-
|
|
16
14
|
/**
|
|
17
15
|
*
|
|
18
16
|
* @param {Object} config
|
|
@@ -41,20 +39,18 @@ module.exports = function (config) {
|
|
|
41
39
|
// Delete temp directories.
|
|
42
40
|
return (
|
|
43
41
|
Promise.mapSeries([tempDir1, tempDir2], function (file) {
|
|
44
|
-
return fs.
|
|
42
|
+
return fs.remove(file);
|
|
45
43
|
})
|
|
46
44
|
.then(function () {
|
|
47
45
|
const dirs = [tempDir1, tempDir2].concat(svgBuildsDist, pngBuildsDist);
|
|
48
46
|
|
|
49
47
|
// Create temp and destination directories.
|
|
50
48
|
return Promise.mapSeries(dirs, function (dir) {
|
|
51
|
-
return fs.
|
|
49
|
+
return fs.mkdirp(dir);
|
|
52
50
|
});
|
|
53
51
|
})
|
|
54
52
|
// Find source files.
|
|
55
|
-
.then(
|
|
56
|
-
return multiGlob(config.src);
|
|
57
|
-
})
|
|
53
|
+
.then(() => globby(config.src))
|
|
58
54
|
.then(function (files) {
|
|
59
55
|
srcFiles = files;
|
|
60
56
|
|
|
@@ -68,7 +64,7 @@ module.exports = function (config) {
|
|
|
68
64
|
svgDistDirs.push(svgDistDir);
|
|
69
65
|
|
|
70
66
|
return fs
|
|
71
|
-
.
|
|
67
|
+
.mkdirp(svgDistDir)
|
|
72
68
|
.then(function () {
|
|
73
69
|
return Promise.mapSeries(srcFiles, function (file) {
|
|
74
70
|
// Add colors to filename for DirectoryColorfy.
|
|
@@ -85,7 +81,7 @@ module.exports = function (config) {
|
|
|
85
81
|
)} > ${chalk.cyan(basename)} > ${chalk.cyan(color.name)}`
|
|
86
82
|
);
|
|
87
83
|
|
|
88
|
-
return fs.
|
|
84
|
+
return fs.copy(file, copy);
|
|
89
85
|
});
|
|
90
86
|
})
|
|
91
87
|
.then(function () {
|
|
@@ -101,7 +97,7 @@ module.exports = function (config) {
|
|
|
101
97
|
})
|
|
102
98
|
.then(function (files) {
|
|
103
99
|
return Promise.mapSeries(files, function (file) {
|
|
104
|
-
return fs.
|
|
100
|
+
return fs.writeFile(file.path, file.data, 'utf-8');
|
|
105
101
|
});
|
|
106
102
|
})
|
|
107
103
|
.then(function () {
|
|
@@ -124,7 +120,7 @@ module.exports = function (config) {
|
|
|
124
120
|
);
|
|
125
121
|
const distPath = path.resolve(svgDistDir, basename + '.svg');
|
|
126
122
|
|
|
127
|
-
return fs.
|
|
123
|
+
return fs.rename(srcPath, distPath);
|
|
128
124
|
});
|
|
129
125
|
});
|
|
130
126
|
});
|
|
@@ -144,13 +140,13 @@ module.exports = function (config) {
|
|
|
144
140
|
);
|
|
145
141
|
|
|
146
142
|
return fs
|
|
147
|
-
.
|
|
143
|
+
.readFile(file, 'utf-8')
|
|
148
144
|
.then(function (data) {
|
|
149
145
|
// Minify SVG.
|
|
150
146
|
return svgMin(data);
|
|
151
147
|
})
|
|
152
148
|
.then(function (data) {
|
|
153
|
-
return fs.
|
|
149
|
+
return fs.writeFile(svgDistPath, data, 'utf-8');
|
|
154
150
|
})
|
|
155
151
|
.then(function () {
|
|
156
152
|
if (pngBuilds.length) {
|
|
@@ -172,7 +168,7 @@ module.exports = function (config) {
|
|
|
172
168
|
});
|
|
173
169
|
const base = path.resolve(svgDistDirs[0], '..');
|
|
174
170
|
|
|
175
|
-
return
|
|
171
|
+
return globby(src).then(function (files) {
|
|
176
172
|
return Promise.mapSeries(pngBuilds, function (pngBuild, i) {
|
|
177
173
|
console.log(
|
|
178
174
|
`Building PNG glyphs [${i + 1}/${
|
|
@@ -209,7 +205,7 @@ module.exports = function (config) {
|
|
|
209
205
|
|
|
210
206
|
// Clean up.
|
|
211
207
|
return Promise.mapSeries(dirs, function (file) {
|
|
212
|
-
return fs.
|
|
208
|
+
return fs.remove(file);
|
|
213
209
|
});
|
|
214
210
|
})
|
|
215
211
|
);
|
package/lib/buildJsFont.js
CHANGED
|
@@ -8,8 +8,6 @@ const Promise = require('bluebird');
|
|
|
8
8
|
const loadFiles = require('./loadFiles');
|
|
9
9
|
const svgMin = require('./svgMin');
|
|
10
10
|
|
|
11
|
-
Promise.promisifyAll(fs);
|
|
12
|
-
|
|
13
11
|
/**
|
|
14
12
|
*
|
|
15
13
|
* @param {Object} config
|
|
@@ -55,8 +53,8 @@ module.exports = function (config) {
|
|
|
55
53
|
const distPath = path.resolve(config.build.dist, config.name + '.js');
|
|
56
54
|
const distDir = path.dirname(distPath);
|
|
57
55
|
|
|
58
|
-
return fs.
|
|
59
|
-
return fs.
|
|
56
|
+
return fs.mkdirp(distDir).then(function () {
|
|
57
|
+
return fs.writeFile(distPath, data, 'utf-8');
|
|
60
58
|
});
|
|
61
59
|
});
|
|
62
60
|
};
|
package/lib/buildPngSprite.js
CHANGED
|
@@ -4,17 +4,15 @@ const autoprefixer = require('autoprefixer');
|
|
|
4
4
|
const chalk = require('chalk');
|
|
5
5
|
const crypto = require('crypto');
|
|
6
6
|
const fs = require('fs-extra');
|
|
7
|
+
const globby = require('globby');
|
|
7
8
|
const path = require('path');
|
|
8
9
|
const postcss = require('postcss');
|
|
9
10
|
const Promise = require('bluebird');
|
|
10
11
|
const sass = require('node-sass');
|
|
11
12
|
const Spritesmith = require('spritesmith');
|
|
12
13
|
const nunjucks = require('nunjucks');
|
|
13
|
-
const multiGlob = require('./multiGlob');
|
|
14
14
|
const packageJson = require('../package.json');
|
|
15
15
|
|
|
16
|
-
Promise.promisifyAll(fs);
|
|
17
|
-
|
|
18
16
|
const md5 = crypto.createHash('md5');
|
|
19
17
|
|
|
20
18
|
/**
|
|
@@ -27,7 +25,7 @@ module.exports = function (config) {
|
|
|
27
25
|
md5.update(JSON.stringify(config));
|
|
28
26
|
|
|
29
27
|
return Promise.mapSeries(config.build.rules, (rule) =>
|
|
30
|
-
|
|
28
|
+
globby(rule.src).then((glyphs) =>
|
|
31
29
|
Promise.resolve(
|
|
32
30
|
_.assign({}, rule, {
|
|
33
31
|
src: glyphs.map((glyph) => ({
|
|
@@ -75,11 +73,9 @@ module.exports = function (config) {
|
|
|
75
73
|
|
|
76
74
|
md5.update(result.image);
|
|
77
75
|
|
|
78
|
-
fs.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
);
|
|
76
|
+
fs.outputFile(file, result.image, 'binary').then(function () {
|
|
77
|
+
resolve(sprite);
|
|
78
|
+
});
|
|
83
79
|
}
|
|
84
80
|
});
|
|
85
81
|
})
|
|
@@ -94,10 +90,8 @@ module.exports = function (config) {
|
|
|
94
90
|
|
|
95
91
|
// Build stylesheet data.
|
|
96
92
|
const {sprite: baselineSprite} = rules[0];
|
|
97
|
-
const {
|
|
98
|
-
|
|
99
|
-
height: spriteHeight
|
|
100
|
-
} = baselineSprite.properties;
|
|
93
|
+
const {width: spriteWidth, height: spriteHeight} =
|
|
94
|
+
baselineSprite.properties;
|
|
101
95
|
const baselineRuleGlyphs = _.values(baselineSprite.coordinates);
|
|
102
96
|
const {width: glyphWidth, height: glyphHeight} = baselineRuleGlyphs.length
|
|
103
97
|
? baselineRuleGlyphs[0]
|
|
@@ -137,10 +131,7 @@ module.exports = function (config) {
|
|
|
137
131
|
}));
|
|
138
132
|
|
|
139
133
|
return fs
|
|
140
|
-
.
|
|
141
|
-
path.join(__dirname, '../src/png-sprite.scss.njk'),
|
|
142
|
-
'utf8'
|
|
143
|
-
)
|
|
134
|
+
.readFile(path.join(__dirname, '../src/png-sprite.scss.njk'), 'utf-8')
|
|
144
135
|
.then((data) =>
|
|
145
136
|
Promise.resolve(
|
|
146
137
|
nunjucks.renderString(data, {
|
|
@@ -170,11 +161,11 @@ module.exports = function (config) {
|
|
|
170
161
|
}
|
|
171
162
|
)
|
|
172
163
|
.then((result) =>
|
|
173
|
-
fs.
|
|
164
|
+
fs.outputFile(cssPath, result.css, 'utf-8')
|
|
174
165
|
);
|
|
175
166
|
|
|
176
167
|
case 'scss':
|
|
177
|
-
return fs.
|
|
168
|
+
return fs.outputFile(scssPath, data, 'utf-8');
|
|
178
169
|
}
|
|
179
170
|
|
|
180
171
|
return Promise.reject(
|
|
@@ -199,14 +190,11 @@ module.exports = function (config) {
|
|
|
199
190
|
};
|
|
200
191
|
|
|
201
192
|
return fs
|
|
202
|
-
.
|
|
203
|
-
path.join(__dirname, '../src/png-sprite.html.njk'),
|
|
204
|
-
'utf8'
|
|
205
|
-
)
|
|
193
|
+
.readFile(path.join(__dirname, '../src/png-sprite.html.njk'), 'utf-8')
|
|
206
194
|
.then((data) =>
|
|
207
195
|
Promise.resolve(nunjucks.renderString(data, htmlData))
|
|
208
196
|
)
|
|
209
|
-
.then((data) => fs.
|
|
197
|
+
.then((data) => fs.outputFile(htmlPath, data, 'utf-8'));
|
|
210
198
|
}
|
|
211
199
|
|
|
212
200
|
return Promise.resolve();
|
package/lib/buildSvgSprite.js
CHANGED
|
@@ -9,8 +9,6 @@ const svgstore = require('svgstore');
|
|
|
9
9
|
const loadFiles = require('./loadFiles');
|
|
10
10
|
const svgMin = require('./svgMin');
|
|
11
11
|
|
|
12
|
-
Promise.promisifyAll(fs);
|
|
13
|
-
|
|
14
12
|
/**
|
|
15
13
|
*
|
|
16
14
|
* @param {Object} config
|
|
@@ -52,8 +50,8 @@ module.exports = function (config) {
|
|
|
52
50
|
const distPath = path.resolve(build.dist, config.name + '.svg');
|
|
53
51
|
const distDir = path.dirname(distPath);
|
|
54
52
|
|
|
55
|
-
return fs.
|
|
56
|
-
return fs.
|
|
53
|
+
return fs.mkdirp(distDir).then(function () {
|
|
54
|
+
return fs.writeFile(distPath, data, 'utf-8');
|
|
57
55
|
});
|
|
58
56
|
});
|
|
59
57
|
});
|
package/lib/buildWebFont.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* eslint no-console: 0 */
|
|
2
2
|
const _ = require('lodash');
|
|
3
3
|
const chalk = require('chalk');
|
|
4
|
+
const globby = require('globby');
|
|
4
5
|
const Promise = require('bluebird');
|
|
5
6
|
const webfont = require('grunt-webfont');
|
|
6
|
-
const multiGlob = require('./multiGlob');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
@@ -13,7 +13,7 @@ const multiGlob = require('./multiGlob');
|
|
|
13
13
|
module.exports = function (config) {
|
|
14
14
|
console.log(`Building web font: ${chalk.cyan(config.name)}`);
|
|
15
15
|
|
|
16
|
-
return
|
|
16
|
+
return globby(config.src).then(function (files) {
|
|
17
17
|
return new Promise(function (resolve, reject) {
|
|
18
18
|
let task;
|
|
19
19
|
|
package/lib/loadFiles.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
2
|
const fs = require('fs-extra');
|
|
3
|
+
const globby = require('globby');
|
|
3
4
|
const Promise = require('bluebird');
|
|
4
|
-
const multiGlob = require('./multiGlob');
|
|
5
|
-
|
|
6
|
-
Promise.promisifyAll(fs);
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
*
|
|
@@ -11,14 +9,14 @@ Promise.promisifyAll(fs);
|
|
|
11
9
|
* @returns {Promise}
|
|
12
10
|
*/
|
|
13
11
|
module.exports = function (src) {
|
|
14
|
-
return
|
|
12
|
+
return globby(src).then(function (matches) {
|
|
15
13
|
const files = _.map(matches, function (file) {
|
|
16
14
|
return {path: file};
|
|
17
15
|
});
|
|
18
16
|
|
|
19
17
|
return Promise.mapSeries(files, function (file) {
|
|
20
18
|
return Promise.props(
|
|
21
|
-
_.assign(file, {data: fs.
|
|
19
|
+
_.assign(file, {data: fs.readFile(file.path, 'utf-8')})
|
|
22
20
|
);
|
|
23
21
|
});
|
|
24
22
|
});
|
package/lib/svg2pngMin.js
CHANGED
|
@@ -5,8 +5,6 @@ const path = require('path');
|
|
|
5
5
|
const Promise = require('bluebird');
|
|
6
6
|
const sharp = require('sharp');
|
|
7
7
|
|
|
8
|
-
Promise.promisifyAll(fs);
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
*
|
|
12
10
|
* @param {string} src - Soure file path
|
|
@@ -24,8 +22,8 @@ module.exports = function (src, destDir, scale, suffix) {
|
|
|
24
22
|
);
|
|
25
23
|
|
|
26
24
|
return fs
|
|
27
|
-
.
|
|
28
|
-
.then(() => fs.
|
|
25
|
+
.mkdirp(destDir)
|
|
26
|
+
.then(() => fs.readFile(src, 'utf-8'))
|
|
29
27
|
.then((data) => {
|
|
30
28
|
let resize;
|
|
31
29
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "punchcutter",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "Build fonts",
|
|
5
5
|
"main": "lib/punchcutter.js",
|
|
6
6
|
"repository": {
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"url": "https://github.com/netbek/punchcutter/issues"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@babel/core": "7.
|
|
25
|
-
"@babel/eslint-parser": "7.
|
|
26
|
-
"autoprefixer": "10.4.
|
|
24
|
+
"@babel/core": "7.22.1",
|
|
25
|
+
"@babel/eslint-parser": "7.21.8",
|
|
26
|
+
"autoprefixer": "10.4.14",
|
|
27
27
|
"babel-loader": "8.3.0",
|
|
28
28
|
"babel-plugin-lodash": "3.3.4",
|
|
29
29
|
"babel-plugin-transform-class-properties": "6.24.1",
|
|
@@ -31,33 +31,32 @@
|
|
|
31
31
|
"chalk": "4.1.2",
|
|
32
32
|
"cheerio": "0.22.0",
|
|
33
33
|
"directory-colorfy": "https://github.com/netbek/directory-colorfy.git#netbek-jsdom-9",
|
|
34
|
-
"eslint": "8.
|
|
34
|
+
"eslint": "8.41.0",
|
|
35
35
|
"eslint-config-airbnb": "19.0.4",
|
|
36
|
-
"eslint-config-prettier": "8.
|
|
36
|
+
"eslint-config-prettier": "8.8.0",
|
|
37
37
|
"eslint-plugin-babel": "5.3.1",
|
|
38
38
|
"eslint-plugin-dollar-sign": "1.0.2",
|
|
39
39
|
"eslint-plugin-html": "6.2.0",
|
|
40
40
|
"eslint-plugin-import": "2.27.5",
|
|
41
|
-
"eslint-plugin-jsdoc": "39.
|
|
41
|
+
"eslint-plugin-jsdoc": "39.9.1",
|
|
42
42
|
"eslint-plugin-jsx-a11y": "6.7.1",
|
|
43
43
|
"eslint-plugin-markdown": "2.2.1",
|
|
44
44
|
"eslint-plugin-prettier": "4.2.1",
|
|
45
|
-
"eslint-plugin-react": "7.32.
|
|
45
|
+
"eslint-plugin-react": "7.32.2",
|
|
46
46
|
"eslint-plugin-react-hooks": "4.6.0",
|
|
47
47
|
"fs-extra": "10.1.0",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"grunt": "1.5.3",
|
|
48
|
+
"globby": "9.2.0",
|
|
49
|
+
"grunt": "1.6.1",
|
|
51
50
|
"grunt-webfont": "git+https://github.com/netbek/grunt-webfont.git#netbek-logger-option",
|
|
52
51
|
"lodash": "4.17.21",
|
|
53
52
|
"lodash-webpack-plugin": "0.11.6",
|
|
54
53
|
"node-sass": "7.0.3",
|
|
55
|
-
"nunjucks": "3.2.
|
|
56
|
-
"postcss": "8.4.
|
|
57
|
-
"prettier": "2.8.
|
|
54
|
+
"nunjucks": "3.2.4",
|
|
55
|
+
"postcss": "8.4.24",
|
|
56
|
+
"prettier": "2.8.8",
|
|
58
57
|
"replace-ext": "2.0.0",
|
|
59
|
-
"sharp": "0.
|
|
60
|
-
"spritesmith": "3.4.
|
|
58
|
+
"sharp": "0.32.1",
|
|
59
|
+
"spritesmith": "3.4.1",
|
|
61
60
|
"svgo": "2.8.0",
|
|
62
61
|
"svgstore": "3.0.1",
|
|
63
62
|
"webpack": "4.46.0"
|
|
@@ -65,7 +64,6 @@
|
|
|
65
64
|
"devDependencies": {
|
|
66
65
|
"chai": "4.3.7",
|
|
67
66
|
"chai-as-promised": "7.1.1",
|
|
68
|
-
"glob-promise": "4.2.2",
|
|
69
67
|
"mocha": "9.2.2"
|
|
70
68
|
}
|
|
71
69
|
}
|
package/test/index.js
CHANGED
|
@@ -3,8 +3,8 @@ const {assert} = chai;
|
|
|
3
3
|
const chaiAsPromised = require('chai-as-promised');
|
|
4
4
|
chai.use(chaiAsPromised);
|
|
5
5
|
const fs = require('fs-extra');
|
|
6
|
+
const globby = require('globby');
|
|
6
7
|
const Promise = require('bluebird');
|
|
7
|
-
const multiGlob = require('../lib/multiGlob');
|
|
8
8
|
const {
|
|
9
9
|
build,
|
|
10
10
|
GLYPH,
|
|
@@ -18,8 +18,6 @@ const {
|
|
|
18
18
|
TTF
|
|
19
19
|
} = require('..');
|
|
20
20
|
|
|
21
|
-
Promise.promisifyAll(fs);
|
|
22
|
-
|
|
23
21
|
describe('Punchcutter', function () {
|
|
24
22
|
const testDir = __dirname.substring(process.cwd().length + 1) + '/';
|
|
25
23
|
|
|
@@ -138,7 +136,7 @@ describe('Punchcutter', function () {
|
|
|
138
136
|
|
|
139
137
|
const setup = function (done) {
|
|
140
138
|
// Delete test output.
|
|
141
|
-
fs.
|
|
139
|
+
fs.remove(testDir + 'data/dist/').then(function () {
|
|
142
140
|
done();
|
|
143
141
|
});
|
|
144
142
|
};
|
|
@@ -152,7 +150,7 @@ describe('Punchcutter', function () {
|
|
|
152
150
|
|
|
153
151
|
const actual = () =>
|
|
154
152
|
Promise.mapSeries(config.fonts, (font) => build(font))
|
|
155
|
-
.then(() =>
|
|
153
|
+
.then(() => globby([testDir + 'data/dist/**/*'], {onlyFiles: true}))
|
|
156
154
|
.then((files) => Promise.resolve(files.sort()));
|
|
157
155
|
|
|
158
156
|
const expected = [
|
package/lib/multiGlob.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const fs = require('fs-extra');
|
|
2
|
-
const globPromise = require('glob-promise');
|
|
3
|
-
const Promise = require('bluebird');
|
|
4
|
-
|
|
5
|
-
Promise.promisifyAll(fs);
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {Array} patterns
|
|
10
|
-
* @param {Object} options
|
|
11
|
-
* @returns {Promise}
|
|
12
|
-
*/
|
|
13
|
-
module.exports = function (patterns, options) {
|
|
14
|
-
let matches = [];
|
|
15
|
-
|
|
16
|
-
return Promise.mapSeries(patterns, function (pattern) {
|
|
17
|
-
return globPromise(pattern, options).then(function (files) {
|
|
18
|
-
matches = matches.concat(files);
|
|
19
|
-
});
|
|
20
|
-
}).then(function () {
|
|
21
|
-
return Promise.resolve(matches);
|
|
22
|
-
});
|
|
23
|
-
};
|