punchcutter 2.0.17 → 2.1.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.
@@ -0,0 +1,187 @@
1
+ import fs from 'fs-extra';
2
+ import globby from 'globby';
3
+ import path from 'path';
4
+ import {describe, expect, test} from 'vitest';
5
+ import {
6
+ build,
7
+ GLYPH,
8
+ JS_FONT,
9
+ PNG_SPRITE,
10
+ SVG_SPRITE,
11
+ WEB_FONT,
12
+ PNG,
13
+ SVG,
14
+ WOFF,
15
+ TTF
16
+ } from '../punchcutter';
17
+
18
+ const dir = import.meta.dirname;
19
+
20
+ describe('Punchcutter', () => {
21
+ test('build', async () => {
22
+ await fs.remove(path.join(dir, 'data/dist'));
23
+
24
+ const config = {
25
+ fonts: [
26
+ // Mono
27
+ {
28
+ name: 'mono',
29
+ src: [path.join(dir, 'data/src/mono/*.svg')],
30
+ builds: [
31
+ {
32
+ type: GLYPH,
33
+ builds: [
34
+ {
35
+ type: SVG,
36
+ dist: path.join(dir, 'data/dist/mono/glyph/svg') + path.sep
37
+ }
38
+ ]
39
+ },
40
+ {
41
+ type: SVG_SPRITE,
42
+ monochrome: true,
43
+ builds: [
44
+ {
45
+ dist: path.join(dir, 'data/dist/mono/svg-sprite') + path.sep,
46
+ idPrefix: 'mono--'
47
+ }
48
+ ]
49
+ }
50
+ ]
51
+ },
52
+ // Poly
53
+ {
54
+ name: 'poly',
55
+ src: [path.join(dir, 'data/src/poly/*.svg')],
56
+ builds: [
57
+ {
58
+ type: WEB_FONT,
59
+ css: {
60
+ dist: path.join(dir, 'data/dist/poly/font') + path.sep
61
+ },
62
+ font: {
63
+ dist: path.join(dir, 'data/dist/poly/font') + path.sep
64
+ },
65
+ order: [WOFF, TTF],
66
+ stylesheets: ['scss'],
67
+ syntax: 'bem',
68
+ templateOptions: {
69
+ baseClass: 'poly',
70
+ classPrefix: 'poly--'
71
+ },
72
+ types: [WOFF, TTF]
73
+ },
74
+ {
75
+ type: GLYPH,
76
+ colors: {
77
+ blue: '#00f',
78
+ red: '#f00'
79
+ },
80
+ builds: [
81
+ {
82
+ type: SVG,
83
+ dist: path.join(dir, 'data/dist/poly/glyph/svg') + path.sep
84
+ },
85
+ {
86
+ type: PNG,
87
+ dist:
88
+ path.join(dir, 'data/dist/poly/glyph/png/@1x') + path.sep,
89
+ scale: 1
90
+ },
91
+ {
92
+ type: PNG,
93
+ dist:
94
+ path.join(dir, 'data/dist/poly/glyph/png/@2x') + path.sep,
95
+ scale: 2
96
+ }
97
+ ]
98
+ },
99
+ {
100
+ type: JS_FONT,
101
+ dist: path.join(dir, 'data/dist/poly/js') + path.sep
102
+ },
103
+ {
104
+ type: PNG_SPRITE,
105
+ css: {
106
+ dist: path.join(dir, 'data/dist/poly/png-sprite/css') + path.sep
107
+ },
108
+ rules: [
109
+ {
110
+ dppx: 1,
111
+ src: [
112
+ path.join(dir, 'data/dist/poly/glyph/png/@1x/blue/*.png')
113
+ ],
114
+ dist:
115
+ path.join(dir, 'data/dist/poly/png-sprite/@1x') + path.sep // Output to directory
116
+ },
117
+ {
118
+ dppx: 1.5,
119
+ src: [
120
+ path.join(dir, 'data/dist/poly/glyph/png/@2x/blue/*.png')
121
+ ],
122
+ dist: path.join(
123
+ dir,
124
+ 'data/dist/poly/png-sprite/img/poly@2x.png'
125
+ ) // Output to file
126
+ }
127
+ ],
128
+ stylesheets: ['scss'],
129
+ templateOptions: {
130
+ baseClass: 'poly',
131
+ classPrefix: 'poly--'
132
+ }
133
+ },
134
+ {
135
+ type: SVG_SPRITE,
136
+ builds: [
137
+ {
138
+ dist: path.join(dir, 'data/dist/poly/svg-sprite') + path.sep
139
+ }
140
+ ]
141
+ }
142
+ ]
143
+ }
144
+ ]
145
+ };
146
+
147
+ for (const font of config.fonts) {
148
+ await build(font);
149
+ }
150
+
151
+ const actual = (
152
+ await globby([path.join(dir, 'data/dist')], {
153
+ onlyFiles: true
154
+ })
155
+ ).sort();
156
+
157
+ const expected = [
158
+ path.join(dir, 'data/dist/mono/glyph/svg/erlenmeyer-flask.svg'),
159
+ path.join(dir, 'data/dist/mono/glyph/svg/eye.svg'),
160
+ path.join(dir, 'data/dist/mono/svg-sprite/mono.svg'),
161
+ path.join(dir, 'data/dist/poly/font/_poly.scss'),
162
+ path.join(dir, 'data/dist/poly/font/poly.ttf'),
163
+ path.join(dir, 'data/dist/poly/font/poly.woff'),
164
+ path.join(dir, 'data/dist/poly/glyph/png/@1x/blue/erlenmeyer-flask.png'),
165
+ path.join(dir, 'data/dist/poly/glyph/png/@1x/blue/eye.png'),
166
+ path.join(dir, 'data/dist/poly/glyph/png/@1x/red/erlenmeyer-flask.png'),
167
+ path.join(dir, 'data/dist/poly/glyph/png/@1x/red/eye.png'),
168
+ path.join(dir, 'data/dist/poly/glyph/png/@2x/blue/erlenmeyer-flask.png'),
169
+ path.join(dir, 'data/dist/poly/glyph/png/@2x/blue/eye.png'),
170
+ path.join(dir, 'data/dist/poly/glyph/png/@2x/red/erlenmeyer-flask.png'),
171
+ path.join(dir, 'data/dist/poly/glyph/png/@2x/red/eye.png'),
172
+ path.join(dir, 'data/dist/poly/glyph/svg/blue/erlenmeyer-flask.svg'),
173
+ path.join(dir, 'data/dist/poly/glyph/svg/red/erlenmeyer-flask.svg'),
174
+ path.join(dir, 'data/dist/poly/glyph/svg/blue/eye.svg'),
175
+ path.join(dir, 'data/dist/poly/glyph/svg/red/eye.svg'),
176
+ path.join(dir, 'data/dist/poly/js/poly.js'),
177
+ path.join(dir, 'data/dist/poly/png-sprite/@1x/poly.png'),
178
+ path.join(dir, 'data/dist/poly/png-sprite/img/poly@2x.png'),
179
+ path.join(dir, 'data/dist/poly/png-sprite/css/_poly.scss'),
180
+ path.join(dir, 'data/dist/poly/svg-sprite/poly.svg')
181
+ ].sort();
182
+
183
+ expect(actual).toEqual(expected);
184
+
185
+ await fs.remove(path.join(dir, 'data/dist'));
186
+ });
187
+ });
@@ -8,7 +8,7 @@ const globby = require('globby');
8
8
  const path = require('path');
9
9
  const postcss = require('postcss');
10
10
  const Promise = require('bluebird');
11
- const sass = require('node-sass');
11
+ const sass = require('sass-embedded');
12
12
  const Spritesmith = require('spritesmith');
13
13
  const nunjucks = require('nunjucks');
14
14
  const packageJson = require('../package.json');
@@ -146,26 +146,17 @@ module.exports = function (config) {
146
146
  )
147
147
  .then((data) =>
148
148
  Promise.mapSeries(config.build.stylesheets, function (stylesheet) {
149
- switch (stylesheet) {
150
- case 'css':
151
- return postcss([autoprefixer(config.build.autoprefixer)])
152
- .process(
153
- sass
154
- .renderSync({
155
- data
156
- })
157
- .css.toString(),
158
- {
159
- from: undefined,
160
- to: cssPath
161
- }
162
- )
163
- .then((result) =>
164
- fs.outputFile(cssPath, result.css, 'utf-8')
165
- );
149
+ if (stylesheet === 'css') {
150
+ return postcss([autoprefixer(config.build.autoprefixer)])
151
+ .process(sass.compileString(data).css, {
152
+ from: undefined,
153
+ to: cssPath
154
+ })
155
+ .then((result) => fs.outputFile(cssPath, result.css, 'utf-8'));
156
+ }
166
157
 
167
- case 'scss':
168
- return fs.outputFile(scssPath, data, 'utf-8');
158
+ if (stylesheet === 'scss') {
159
+ return fs.outputFile(scssPath, data, 'utf-8');
169
160
  }
170
161
 
171
162
  return Promise.reject(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "punchcutter",
3
- "version": "2.0.17",
3
+ "version": "2.1.0",
4
4
  "description": "Build fonts",
5
5
  "main": "lib/punchcutter.js",
6
6
  "repository": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "scripts": {
11
11
  "format-js": "prettier --parser espree --write \"{lib,test}/*.js\"",
12
- "test": "make test"
12
+ "test": "vitest run"
13
13
  },
14
14
  "author": {
15
15
  "name": "Hein Bekker",
@@ -35,19 +35,17 @@
35
35
  "grunt": "1.6.1",
36
36
  "grunt-webfont": "git+https://github.com/netbek/grunt-webfont.git#netbek-logger-option",
37
37
  "lodash": "4.17.21",
38
- "node-sass": "9.0.0",
39
38
  "nunjucks": "3.2.4",
40
39
  "postcss": "8.4.49",
41
40
  "prettier": "3.3.3",
42
41
  "replace-ext": "2.0.0",
42
+ "sass-embedded": "1.81.0",
43
43
  "sharp": "0.33.5",
44
44
  "spritesmith": "3.5.1",
45
45
  "svgo": "2.8.0",
46
46
  "svgstore": "3.0.1"
47
47
  },
48
48
  "devDependencies": {
49
- "chai": "4.5.0",
50
- "chai-as-promised": "7.1.2",
51
- "mocha": "9.2.2"
49
+ "vitest": "2.1.5"
52
50
  }
53
51
  }
package/Makefile DELETED
@@ -1,9 +0,0 @@
1
- GREP ?=.
2
-
3
- test: node_modules
4
- @node_modules/.bin/mocha --harmony --grep "$(GREP)"
5
-
6
- node_modules: package.json
7
- @npm install
8
-
9
- .PHONY: test
package/test/index.js DELETED
@@ -1,185 +0,0 @@
1
- const chai = require('chai');
2
- const {assert} = chai;
3
- const chaiAsPromised = require('chai-as-promised');
4
- chai.use(chaiAsPromised);
5
- const fs = require('fs-extra');
6
- const globby = require('globby');
7
- const Promise = require('bluebird');
8
- const {
9
- build,
10
- GLYPH,
11
- JS_FONT,
12
- PNG_SPRITE,
13
- SVG_SPRITE,
14
- WEB_FONT,
15
- PNG,
16
- SVG,
17
- WOFF,
18
- TTF
19
- } = require('..');
20
-
21
- describe('Punchcutter', function () {
22
- const testDir = __dirname.substring(process.cwd().length + 1) + '/';
23
-
24
- const config = {
25
- fonts: [
26
- // Mono
27
- {
28
- name: 'mono',
29
- src: [testDir + 'data/src/mono/*.svg'],
30
- builds: [
31
- {
32
- type: GLYPH,
33
- builds: [
34
- {
35
- type: SVG,
36
- dist: testDir + 'data/dist/mono/glyph/svg/'
37
- }
38
- ]
39
- },
40
- {
41
- type: SVG_SPRITE,
42
- monochrome: true,
43
- builds: [
44
- {
45
- dist: testDir + 'data/dist/mono/svg-sprite/',
46
- idPrefix: 'mono--'
47
- }
48
- ]
49
- }
50
- ]
51
- },
52
- // Poly
53
- {
54
- name: 'poly',
55
- src: [testDir + 'data/src/poly/*.svg'],
56
- builds: [
57
- {
58
- type: WEB_FONT,
59
- css: {
60
- dist: testDir + 'data/dist/poly/font/'
61
- },
62
- font: {
63
- dist: testDir + 'data/dist/poly/font/'
64
- },
65
- order: [WOFF, TTF],
66
- stylesheets: ['scss'],
67
- syntax: 'bem',
68
- templateOptions: {
69
- baseClass: 'poly',
70
- classPrefix: 'poly--'
71
- },
72
- types: [WOFF, TTF]
73
- },
74
- {
75
- type: GLYPH,
76
- colors: {
77
- blue: '#00f',
78
- red: '#f00'
79
- },
80
- builds: [
81
- {
82
- type: SVG,
83
- dist: testDir + 'data/dist/poly/glyph/svg/'
84
- },
85
- {
86
- type: PNG,
87
- dist: testDir + 'data/dist/poly/glyph/png/@1x/',
88
- scale: 1
89
- },
90
- {
91
- type: PNG,
92
- dist: testDir + 'data/dist/poly/glyph/png/@2x/',
93
- scale: 2
94
- }
95
- ]
96
- },
97
- {
98
- type: JS_FONT,
99
- dist: testDir + 'data/dist/poly/js/'
100
- },
101
- {
102
- type: PNG_SPRITE,
103
- css: {
104
- dist: testDir + 'data/dist/poly/png-sprite/css/'
105
- },
106
- rules: [
107
- {
108
- dppx: 1,
109
- src: [testDir + 'data/dist/poly/glyph/png/@1x/blue/*.png'],
110
- dist: testDir + 'data/dist/poly/png-sprite/@1x/' // Output to directory
111
- },
112
- {
113
- dppx: 1.5,
114
- src: [testDir + 'data/dist/poly/glyph/png/@2x/blue/*.png'],
115
- dist: testDir + 'data/dist/poly/png-sprite/img/poly@2x.png' // Output to file
116
- }
117
- ],
118
- stylesheets: ['scss'],
119
- templateOptions: {
120
- baseClass: 'poly',
121
- classPrefix: 'poly--'
122
- }
123
- },
124
- {
125
- type: SVG_SPRITE,
126
- builds: [
127
- {
128
- dist: testDir + 'data/dist/poly/svg-sprite/'
129
- }
130
- ]
131
- }
132
- ]
133
- }
134
- ]
135
- };
136
-
137
- const setup = function (done) {
138
- // Delete test output.
139
- fs.remove(testDir + 'data/dist/').then(function () {
140
- done();
141
- });
142
- };
143
-
144
- beforeEach(setup);
145
- after(setup);
146
-
147
- describe('build', function () {
148
- it('Should build', function () {
149
- this.timeout(10000);
150
-
151
- const actual = () =>
152
- Promise.mapSeries(config.fonts, (font) => build(font))
153
- .then(() => globby([testDir + 'data/dist/**/*'], {onlyFiles: true}))
154
- .then((files) => Promise.resolve(files.sort()));
155
-
156
- const expected = [
157
- testDir + 'data/dist/mono/glyph/svg/erlenmeyer-flask.svg',
158
- testDir + 'data/dist/mono/glyph/svg/eye.svg',
159
- testDir + 'data/dist/mono/svg-sprite/mono.svg',
160
- testDir + 'data/dist/poly/font/_poly.scss',
161
- testDir + 'data/dist/poly/font/poly.ttf',
162
- testDir + 'data/dist/poly/font/poly.woff',
163
- testDir + 'data/dist/poly/glyph/png/@1x/blue/erlenmeyer-flask.png',
164
- testDir + 'data/dist/poly/glyph/png/@1x/blue/eye.png',
165
- testDir + 'data/dist/poly/glyph/png/@1x/red/erlenmeyer-flask.png',
166
- testDir + 'data/dist/poly/glyph/png/@1x/red/eye.png',
167
- testDir + 'data/dist/poly/glyph/png/@2x/blue/erlenmeyer-flask.png',
168
- testDir + 'data/dist/poly/glyph/png/@2x/blue/eye.png',
169
- testDir + 'data/dist/poly/glyph/png/@2x/red/erlenmeyer-flask.png',
170
- testDir + 'data/dist/poly/glyph/png/@2x/red/eye.png',
171
- testDir + 'data/dist/poly/glyph/svg/blue/erlenmeyer-flask.svg',
172
- testDir + 'data/dist/poly/glyph/svg/red/erlenmeyer-flask.svg',
173
- testDir + 'data/dist/poly/glyph/svg/blue/eye.svg',
174
- testDir + 'data/dist/poly/glyph/svg/red/eye.svg',
175
- testDir + 'data/dist/poly/js/poly.js',
176
- testDir + 'data/dist/poly/png-sprite/@1x/poly.png',
177
- testDir + 'data/dist/poly/png-sprite/img/poly@2x.png',
178
- testDir + 'data/dist/poly/png-sprite/css/_poly.scss',
179
- testDir + 'data/dist/poly/svg-sprite/poly.svg'
180
- ].sort();
181
-
182
- return assert.eventually.deepEqual(actual(), expected);
183
- });
184
- });
185
- });
File without changes
File without changes