Skip to content

Commit

Permalink
Rewrite build steps to produce lib and es modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopding committed Dec 18, 2018
1 parent 51858b8 commit dbe8e9d
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 47 deletions.
12 changes: 0 additions & 12 deletions .babelrc

This file was deleted.

5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ coverage.html
*.js.map
.nyc_output
yarn-error.log
fontkit.js
fontkit.min.js
dist/
es/
lib/
trie.json
trieIndic.json
trieUse.json
45 changes: 37 additions & 8 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,64 @@ target.all = () => {
target.clean();
target.generateTrieJson();
target.moveTrieJsonToRoot();
target.rollupUMD();
target.rollupUMDMin();
target.compileBabel();
// target.rollupUMD();
// target.rollupUMDMin();
};

target.generateTrieJson = () => {
env.MODULE_TYPE = 'commonjs';
exec('babel-node src/opentype/shapers/generate-data.js');
exec('babel-node src/opentype/shapers/gen-use.js');
exec('babel-node src/opentype/shapers/gen-indic.js');
};

target.moveTrieJsonToRoot = () => {
target.generateTrieJson();
// mv('src/opentype/shapers/trie.json', 'trie.json');
// mv('src/opentype/shapers/trieUse.json', 'trieUse.json');
// mv('src/opentype/shapers/trieIndic.json', 'trieIndic.json');
mkdir('-p', 'es/opentype/shapers/')
mkdir('-p', 'lib/opentype/shapers/')
cp(
'src/opentype/shapers/trie.json',
'src/opentype/shapers/trieUse.json',
'src/opentype/shapers/trieIndic.json',
'es/opentype/shapers/'
);
cp(
'src/opentype/shapers/trie.json',
'src/opentype/shapers/trieUse.json',
'src/opentype/shapers/trieIndic.json',
'lib/opentype/shapers/'
);
};

target.compileBabel = () => {
target.moveTrieJsonToRoot();
env.MODULE_TYPE = 'es6';
exec(`babel --out-dir es src/`);
env.MODULE_TYPE = 'commonjs';
exec(`babel --out-dir lib src/`);
}

target.rollupUMD = () => {
target.moveTrieJsonToRoot();
env.UGLIFY = false;
exec('rollup -c rollup.config.js -o fontkit.js');
exec('rollup -c rollup.config.js -o dist/fontkit.js');
};

target.rollupUMDMin = () => {
target.moveTrieJsonToRoot();
env.UGLIFY = true;
exec('rollup -c rollup.config.js -o fontkit.min.js');
exec('rollup -c rollup.config.js -o dist/fontkit.min.js');
};

target.clean = () => {
rm('-f', 'fonkit.js', 'fontkit.min.js', 'trie.json', 'trieUse.json', 'trieIndic.json');
rm(
'-rf',
'lib',
'es',
'dist',
'src/opentype/shapers/trie.json',
'src/opentype/shapers/trieUse.json',
'src/opentype/shapers/trieIndic.json',
);
};
24 changes: 24 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = (api) => {
api.cache(true);

const { MODULE_TYPE } = process.env;

// MODULE_TYPE = 'commonjs' | 'es6'
const modules = MODULE_TYPE === 'commonjs' ? 'commonjs' : false;

return {
presets: [['@babel/preset-env', { modules }]],
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties']
],
env: {
test: {
presets: [['@babel/preset-env', { modules: 'commonjs' }]],
},
cover: {
plugins: ['istanbul']
}
}
};
}
34 changes: 14 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,27 @@
"name": "fontkit",
"version": "1.7.7",
"description": "An advanced font engine for Node and the browser",
"keywords": [
"opentype",
"font",
"typography",
"subset",
"emoji",
"glyph",
"layout"
],
"main": "lib/index.js",
"unpkg": "dist/fontkit.min.js",
"module": "es/index.js",
"scripts": {
"make": "node Makefile.js",
"clean": "node Makefile.js clean",
"test": "mocha",
"coverage": "cross-env BABEL_ENV=cover nyc mocha",
"build-bundle": "browserify --insert-globals --standalone fontkit ./index.js | uglifyjs --mangle -c > bundle.js"
},
"main": "fontkit.js",
"files": [
"src",
"base.js",
"base.js.map",
"index.js",
"index.js.map",
"data.trie",
"use.trie",
"indic.trie"
],
"author": "Devon Govett <devongovett@gmail.com>",
"license": "MIT",
"keywords": [
"opentype",
"font",
"typography",
"subset",
"emoji",
"glyph",
"layout"
],
"dependencies": {
"brotli": "^1.2.0",
"browserify-optional": "^1.0.0",
Expand Down Expand Up @@ -61,8 +53,10 @@
"rollup": "^0.68.0",
"rollup-plugin-analyzer": "^2.1.0",
"rollup-plugin-babel": "^4.1.0",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-local-resolve": "^1.0.7",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-uglify": "^6.0.0"
}
}
21 changes: 18 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import babel from 'rollup-plugin-babel';
import nodeResolve from 'rollup-plugin-node-resolve';
import localResolve from 'rollup-plugin-local-resolve';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import { uglify } from 'rollup-plugin-uglify';
import { plugin as analyze } from 'rollup-plugin-analyzer';
Expand All @@ -14,13 +16,26 @@ export default {
},
plugins: [
// analyze(),
localResolve(),
nodeResolve({
jsnext: true,
preferBuiltins: false,
}),
// localResolve(),
commonjs({
exclude: 'src/**',
namedExports: {
'node_modules/unicode-trie/index.js': ['default'],

// TODO: Remove this once create fork of restructure that exports es/
'node_modules/restructure/index.js': ['default'],
},
}),
json(),
babel({
// TODO: Use external .babelrc file?
babelrc: false,
// exclude: 'node_modules/**',
presets: [
['@babel/preset-env', { modules: false, loose: true }]
['@babel/preset-env', { loose: true }]
],
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
Expand Down
45 changes: 43 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,11 @@ builtin-modules@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"

builtin-modules@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.0.0.tgz#1e587d44b006620d90286cc7a9238bbc6129cab1"
integrity sha512-hMIeU4K2ilbXV6Uv93ZZ0Avg/M91RaKXucQ+4me2Do1txxBDyDZWCBa5bJSLqoNTRpXTLwEzIk1KmloenDDjhg==

cache-base@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2"
Expand Down Expand Up @@ -2162,6 +2167,11 @@ is-glob@^4.0.0:
dependencies:
is-extglob "^2.1.1"

is-module@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591"
integrity sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=

is-number@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-number/-/is-number-2.1.0.tgz#01fcbbb393463a548f2f466cce16dece49db908f"
Expand Down Expand Up @@ -2489,6 +2499,13 @@ lru-cache@^4.0.1:
pseudomap "^1.0.2"
yallist "^2.1.2"

magic-string@^0.25.1:
version "0.25.1"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.1.tgz#b1c248b399cd7485da0fe7385c2fc7011843266e"
integrity sha512-sCuTz6pYom8Rlt4ISPFn6wuFodbKMIHUMv4Qko9P17dpxb7s52KJTmRuZZqHdGmLCK9AOcDare039nRIcfdkEg==
dependencies:
sourcemap-codec "^1.4.1"

make-dir@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.3.0.tgz#79c1033b80515bd6d24ec9933e860ca75ee27f0c"
Expand Down Expand Up @@ -3268,7 +3285,7 @@ resolve@1.1.7:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"

resolve@^1.1.6, resolve@^1.3.2:
resolve@^1.1.6, resolve@^1.3.2, resolve@^1.8.1:
version "1.9.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.9.0.tgz#a14c6fdfa8f92a7df1d996cb7105fa744658ea06"
integrity sha512-TZNye00tI67lwYvzxCxHGjwTNlUV70io54/Ed4j6PscB8xVfuBJpRenI/o6dVk0cY0PYTY27AgCoGGxRnYuItQ==
Expand Down Expand Up @@ -3310,6 +3327,16 @@ rollup-plugin-babel@^4.1.0:
"@babel/helper-module-imports" "^7.0.0"
rollup-pluginutils "^2.3.0"

rollup-plugin-commonjs@^9.2.0:
version "9.2.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-commonjs/-/rollup-plugin-commonjs-9.2.0.tgz#4604e25069e0c78a09e08faa95dc32dec27f7c89"
integrity sha512-0RM5U4Vd6iHjL6rLvr3lKBwnPsaVml+qxOGaaNUWN1lSq6S33KhITOfHmvxV3z2vy9Mk4t0g4rNlVaJJsNQPWA==
dependencies:
estree-walker "^0.5.2"
magic-string "^0.25.1"
resolve "^1.8.1"
rollup-pluginutils "^2.3.3"

rollup-plugin-json@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-json/-/rollup-plugin-json-3.1.0.tgz#7c1daf60c46bc21021ea016bd00863561a03321b"
Expand All @@ -3321,6 +3348,15 @@ rollup-plugin-local-resolve@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/rollup-plugin-local-resolve/-/rollup-plugin-local-resolve-1.0.7.tgz#c486701716c15add2127565c2eaa101123320887"

rollup-plugin-node-resolve@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-4.0.0.tgz#9bc6b8205e9936cc0e26bba2415f1ecf1e64d9b2"
integrity sha512-7Ni+/M5RPSUBfUaP9alwYQiIKnKeXCOHiqBpKUl9kwp3jX5ZJtgXAait1cne6pGEVUUztPD6skIKH9Kq9sNtfw==
dependencies:
builtin-modules "^3.0.0"
is-module "^1.0.0"
resolve "^1.8.1"

rollup-plugin-uglify@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-uglify/-/rollup-plugin-uglify-6.0.0.tgz#15aa8919e5cdc63b7cfc9319c781788b40084ce4"
Expand All @@ -3331,7 +3367,7 @@ rollup-plugin-uglify@^6.0.0:
serialize-javascript "^1.5.0"
uglify-js "^3.4.9"

rollup-pluginutils@^2.3.0, rollup-pluginutils@^2.3.1:
rollup-pluginutils@^2.3.0, rollup-pluginutils@^2.3.1, rollup-pluginutils@^2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.3.3.tgz#3aad9b1eb3e7fe8262820818840bf091e5ae6794"
integrity sha512-2XZwja7b6P5q4RZ5FhyX1+f46xi1Z3qBKigLRZ6VTZjwbN0K1IFGMlwm06Uu0Emcre2Z63l77nq/pzn+KxIEoA==
Expand Down Expand Up @@ -3510,6 +3546,11 @@ source-map@~0.2.0:
dependencies:
amdefine ">=0.0.4"

sourcemap-codec@^1.4.1:
version "1.4.4"
resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.4.tgz#c63ea927c029dd6bd9a2b7fa03b3fec02ad56e9f"
integrity sha512-CYAPYdBu34781kLHkaW3m6b/uUSyMOC2R61gcYMWooeuaGtjof86ZA/8T+qVPPt7np1085CR9hmMGrySwEc8Xg==

spawn-wrap@1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/spawn-wrap/-/spawn-wrap-1.2.4.tgz#920eb211a769c093eebfbd5b0e7a5d2e68ab2e40"
Expand Down

0 comments on commit dbe8e9d

Please sign in to comment.