2019-06-26 01:15:00 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
/*! Copyright Twitter Inc. and other contributors. Licensed under MIT *//*
|
|
|
|
https://github.com/twitter/twemoji/blob/gh-pages/LICENSE
|
|
|
|
*/
|
|
|
|
|
2019-06-26 02:55:51 +00:00
|
|
|
const fs = require('fs-extra');
|
2019-06-26 01:15:00 +00:00
|
|
|
const path = require('path');
|
|
|
|
const { spawnSync } = require('child_process');
|
2019-09-25 21:50:07 +00:00
|
|
|
const { getIntegrityHash } = require('./utils');
|
2019-06-26 01:15:00 +00:00
|
|
|
|
|
|
|
function file(...which) {
|
|
|
|
return path.join(__dirname, '..', ...which);
|
|
|
|
}
|
|
|
|
|
|
|
|
function distFile(...which) {
|
|
|
|
return path.join(__dirname, '..', 'dist', ...which);
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
distFile('twemoji.npm.js'),
|
|
|
|
[
|
|
|
|
'var location = global.location || {};',
|
|
|
|
fs.readFileSync(distFile('twemoji.js')),
|
|
|
|
'if (!location.protocol) {',
|
|
|
|
' twemoji.base = twemoji.base.replace(/^http:/, "");',
|
|
|
|
'}',
|
|
|
|
'module.exports = twemoji;'
|
|
|
|
].join('\n')
|
|
|
|
);
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
distFile('twemoji.amd.js'),
|
|
|
|
'define(function () {\n' +
|
|
|
|
fs.readFileSync(distFile('twemoji.js')).toString().replace(
|
|
|
|
/^(.)/gm, ' $1'
|
|
|
|
) +
|
|
|
|
'\n return twemoji;\n});'
|
|
|
|
);
|
|
|
|
|
|
|
|
spawnSync(
|
|
|
|
'yarnpkg',
|
|
|
|
[
|
|
|
|
'uglifyjs',
|
|
|
|
'--verbose',
|
|
|
|
distFile('twemoji.js'),
|
|
|
|
'-o',
|
|
|
|
distFile('twemoji.tmp.js')
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
const copyright = '/*! Copyright Twitter Inc. and other contributors. Licensed under MIT */';
|
|
|
|
const minifiedContents = fs.readFileSync(distFile('twemoji.tmp.js'));
|
|
|
|
fs.unlinkSync(distFile('twemoji.tmp.js'));
|
|
|
|
|
|
|
|
fs.writeFileSync(distFile('twemoji.min.js'), `${copyright}\n${minifiedContents}`);
|
|
|
|
fs.writeFileSync(distFile('twemoji.esm.js'), `${copyright}\n${minifiedContents}\nexport default twemoji;`);
|
|
|
|
|
2019-09-25 21:50:07 +00:00
|
|
|
const integrityHash = getIntegrityHash(distFile('twemoji.min.js'));
|
|
|
|
const { version } = require('../package.json');
|
|
|
|
|
|
|
|
function updateSriScriptReference(filename) {
|
|
|
|
const newScript = `<script src="https://twemoji.maxcdn.com/v/${version}/twemoji.min.js" integrity="${integrityHash}"`;
|
|
|
|
fs.writeFileSync(filename, fs.readFileSync(filename).toString('utf8').replace(/<script src="[^ ]*" integrity="[^ ]*"/, newScript));
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSriScriptReference(file('README.md'));
|
|
|
|
|
2019-06-26 01:15:00 +00:00
|
|
|
// Copy the png assets and svgs to the dist folder
|
2019-06-26 02:55:51 +00:00
|
|
|
fs.copySync(file('assets/svg'), distFile('svg'));
|
|
|
|
fs.copySync(file('assets/72x72'), distFile('72x72'));
|