scratch-render-fonts 1.0.0-prerelease.20210325224822 → 1.0.0-prerelease.20221024190656
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/.circleci/config.yml +87 -0
- package/package.json +1 -1
- package/src/index.js +35 -30
- package/.travis.yml +0 -35
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
version: 2.1
|
|
2
|
+
|
|
3
|
+
executors:
|
|
4
|
+
default-executor:
|
|
5
|
+
docker:
|
|
6
|
+
- image: "cimg/node:8.17.0"
|
|
7
|
+
working_directory: ~/project
|
|
8
|
+
resource_class: large
|
|
9
|
+
|
|
10
|
+
commands:
|
|
11
|
+
setup:
|
|
12
|
+
steps:
|
|
13
|
+
- run:
|
|
14
|
+
name: Setup
|
|
15
|
+
command: |
|
|
16
|
+
npm install
|
|
17
|
+
npm update
|
|
18
|
+
npm prune
|
|
19
|
+
test:
|
|
20
|
+
steps:
|
|
21
|
+
- run:
|
|
22
|
+
name: Test
|
|
23
|
+
command: |
|
|
24
|
+
npm run test
|
|
25
|
+
setup_deploy:
|
|
26
|
+
steps:
|
|
27
|
+
- run:
|
|
28
|
+
name: Setup Deploy
|
|
29
|
+
command: |
|
|
30
|
+
echo "export NPM_TAG=latest" >> $BASH_ENV
|
|
31
|
+
echo "export NODE_ENV=production" >> $BASH_ENV
|
|
32
|
+
echo "export RELEASE_TIMESTAMP=$(date +'%Y%m%d%H%M%S')" >> $BASH_ENV
|
|
33
|
+
npm run build
|
|
34
|
+
VPKG=$($(npm bin)/json -f package.json version)
|
|
35
|
+
echo "export VERSION=${VPKG}-prerelease.$(date +%Y%m%d%H%M%S)" >> $BASH_ENV
|
|
36
|
+
|
|
37
|
+
deploy:
|
|
38
|
+
steps:
|
|
39
|
+
- run:
|
|
40
|
+
name: Deploy
|
|
41
|
+
command: |
|
|
42
|
+
echo $VERSION
|
|
43
|
+
npm --no-git-tag-version version $VERSION
|
|
44
|
+
npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN
|
|
45
|
+
npm publish
|
|
46
|
+
|
|
47
|
+
jobs:
|
|
48
|
+
build-and-test:
|
|
49
|
+
executor: default-executor
|
|
50
|
+
steps:
|
|
51
|
+
- checkout
|
|
52
|
+
- setup
|
|
53
|
+
- test
|
|
54
|
+
- persist_to_workspace:
|
|
55
|
+
root: ~/project
|
|
56
|
+
paths: .
|
|
57
|
+
deploy:
|
|
58
|
+
executor: default-executor
|
|
59
|
+
steps:
|
|
60
|
+
- attach_workspace:
|
|
61
|
+
at: ~/project
|
|
62
|
+
- setup_deploy
|
|
63
|
+
- deploy
|
|
64
|
+
|
|
65
|
+
workflows:
|
|
66
|
+
build-and-test-workflow:
|
|
67
|
+
when:
|
|
68
|
+
not:
|
|
69
|
+
and:
|
|
70
|
+
- equal: [tsm/circleci, <<pipeline.git.branch>>]
|
|
71
|
+
jobs:
|
|
72
|
+
- build-and-test
|
|
73
|
+
|
|
74
|
+
deploy-workflow:
|
|
75
|
+
when:
|
|
76
|
+
or:
|
|
77
|
+
- equal: [master, <<pipeline.git.branch>>]
|
|
78
|
+
- equal: [develop, <<pipeline.git.branch>>]
|
|
79
|
+
- equal: [hotfix/*, <<pipeline.git.branch>>]
|
|
80
|
+
- equal: [tsm/circleci, <<pipeline.git.branch>>]
|
|
81
|
+
jobs:
|
|
82
|
+
- build-and-test
|
|
83
|
+
- deploy:
|
|
84
|
+
context:
|
|
85
|
+
- scratch-npm-creds
|
|
86
|
+
requires:
|
|
87
|
+
- build-and-test
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,36 +1,41 @@
|
|
|
1
1
|
// Synchronously load TTF fonts.
|
|
2
2
|
// First, have Webpack load their data as Base 64 strings.
|
|
3
|
-
|
|
4
|
-
const FONTS = {
|
|
5
|
-
'Sans Serif': require('base64-loader!./NotoSans-Medium.ttf'),
|
|
6
|
-
'Serif': require('base64-loader!./SourceSerifPro-Regular.otf'),
|
|
7
|
-
'Handwriting': require('base64-loader!./handlee-regular.ttf'),
|
|
8
|
-
'Marker': require('base64-loader!./Knewave.ttf'),
|
|
9
|
-
'Curly': require('base64-loader!./Griffy-Regular.ttf'),
|
|
10
|
-
'Pixel': require('base64-loader!./Grand9K-Pixel.ttf'),
|
|
11
|
-
'Scratch': require('base64-loader!./Scratch.ttf')
|
|
12
|
-
};
|
|
13
|
-
/* eslint-enable global-require */
|
|
3
|
+
let FONTS;
|
|
14
4
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
const getFonts = function () {
|
|
6
|
+
if (FONTS) return FONTS;
|
|
7
|
+
/* eslint-disable global-require */
|
|
8
|
+
FONTS = {
|
|
9
|
+
'Sans Serif': require('base64-loader!./NotoSans-Medium.ttf'),
|
|
10
|
+
'Serif': require('base64-loader!./SourceSerifPro-Regular.otf'),
|
|
11
|
+
'Handwriting': require('base64-loader!./handlee-regular.ttf'),
|
|
12
|
+
'Marker': require('base64-loader!./Knewave.ttf'),
|
|
13
|
+
'Curly': require('base64-loader!./Griffy-Regular.ttf'),
|
|
14
|
+
'Pixel': require('base64-loader!./Grand9K-Pixel.ttf'),
|
|
15
|
+
'Scratch': require('base64-loader!./Scratch.ttf')
|
|
16
|
+
};
|
|
17
|
+
/* eslint-enable global-require */
|
|
18
|
+
|
|
19
|
+
// For each Base 64 string,
|
|
20
|
+
// 1. Replace each with a usable @font-face tag that points to a Data URI.
|
|
21
|
+
// 2. Inject the font into a style on `document.body`, so measurements
|
|
22
|
+
// can be accurately taken in SvgRenderer._transformMeasurements.
|
|
23
|
+
for (const fontName in FONTS) {
|
|
24
|
+
const fontData = FONTS[fontName];
|
|
25
|
+
FONTS[fontName] = '@font-face {' +
|
|
26
|
+
`font-family: "${fontName}";src: url("data:application/x-font-ttf;charset=utf-8;base64,${fontData}");}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!document.getElementById('scratch-font-styles')) {
|
|
30
|
+
const documentStyleTag = document.createElement('style');
|
|
31
|
+
documentStyleTag.id = 'scratch-font-styles';
|
|
32
|
+
for (const fontName in FONTS) {
|
|
33
|
+
documentStyleTag.textContent += FONTS[fontName];
|
|
34
|
+
}
|
|
35
|
+
document.body.insertBefore(documentStyleTag, document.body.firstChild);
|
|
36
|
+
}
|
|
24
37
|
|
|
25
|
-
|
|
26
|
-
const documentStyleTag = document.createElement('style');
|
|
27
|
-
documentStyleTag.id = 'scratch-font-styles';
|
|
28
|
-
for (const fontName in FONTS) {
|
|
29
|
-
documentStyleTag.textContent += FONTS[fontName];
|
|
30
|
-
}
|
|
31
|
-
document.body.insertBefore(documentStyleTag, document.body.firstChild);
|
|
38
|
+
return FONTS;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
module.exports =
|
|
35
|
-
FONTS: FONTS
|
|
36
|
-
};
|
|
41
|
+
module.exports = getFonts;
|
package/.travis.yml
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
language: node_js
|
|
2
|
-
node_js:
|
|
3
|
-
- lts/*
|
|
4
|
-
env:
|
|
5
|
-
global:
|
|
6
|
-
- NODE_ENV=production
|
|
7
|
-
cache:
|
|
8
|
-
directories:
|
|
9
|
-
- node_modules
|
|
10
|
-
install:
|
|
11
|
-
- npm --production=false install
|
|
12
|
-
- npm --production=false update
|
|
13
|
-
- npm --production=false prune
|
|
14
|
-
jobs:
|
|
15
|
-
include:
|
|
16
|
-
- stage: test
|
|
17
|
-
script:
|
|
18
|
-
- npm run test
|
|
19
|
-
- stage: release
|
|
20
|
-
script: npm run build
|
|
21
|
-
before_deploy:
|
|
22
|
-
- VPKG=$($(npm bin)/json -f package.json version)
|
|
23
|
-
- export VERSION=${VPKG}-prerelease.$(date +%Y%m%d%H%M%S)
|
|
24
|
-
- npm --no-git-tag-version version $VERSION
|
|
25
|
-
deploy:
|
|
26
|
-
- provider: npm
|
|
27
|
-
on:
|
|
28
|
-
all_branches: true
|
|
29
|
-
skip_cleanup: true
|
|
30
|
-
email: $NPM_EMAIL
|
|
31
|
-
api_key: $NPM_TOKEN
|
|
32
|
-
stages:
|
|
33
|
-
- test
|
|
34
|
-
- name: release
|
|
35
|
-
if: branch in (master, develop) and type != pull_request
|