2016-02-28 11:37:17 +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-05-29 20:05:24 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const { spawnSync } = require('child_process');
|
2016-02-28 11:37:17 +00:00
|
|
|
|
2019-05-29 20:05:24 +00:00
|
|
|
function file(...which) {
|
|
|
|
return path.join(__dirname, '..', ...which);
|
2016-02-28 11:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
file('twemoji.npm.js'),
|
|
|
|
[
|
|
|
|
'var location = global.location || {};',
|
|
|
|
fs.readFileSync(file('twemoji.js')),
|
|
|
|
'if (!location.protocol) {',
|
|
|
|
' twemoji.base = twemoji.base.replace(/^http:/, "");',
|
|
|
|
'}',
|
|
|
|
'module.exports = twemoji;'
|
|
|
|
].join('\n')
|
|
|
|
);
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
file('twemoji.amd.js'),
|
|
|
|
'define(function () {\n' +
|
|
|
|
fs.readFileSync(file('twemoji.js')).toString().replace(
|
|
|
|
/^(.)/gm, ' $1'
|
|
|
|
) +
|
|
|
|
'\n return twemoji;\n});'
|
|
|
|
);
|
|
|
|
|
2019-05-29 00:01:14 +00:00
|
|
|
spawnSync(
|
2019-05-29 00:13:07 +00:00
|
|
|
'yarnpkg',
|
2016-02-28 11:37:17 +00:00
|
|
|
[
|
2019-05-29 00:13:07 +00:00
|
|
|
'uglifyjs',
|
2016-02-28 11:37:17 +00:00
|
|
|
'--verbose',
|
|
|
|
file('twemoji.js'),
|
|
|
|
'-o',
|
2019-05-29 00:01:14 +00:00
|
|
|
file('twemoji.tmp.js')
|
2016-02-28 11:37:17 +00:00
|
|
|
]
|
2019-05-29 00:01:14 +00:00
|
|
|
);
|
|
|
|
|
2019-05-29 20:43:48 +00:00
|
|
|
const copyright = '/*! Copyright Twitter Inc. and other contributors. Licensed under MIT */';
|
|
|
|
const minifiedContents = fs.readFileSync(file('twemoji.tmp.js'));
|
2019-05-29 00:01:14 +00:00
|
|
|
fs.unlinkSync(file('twemoji.tmp.js'));
|
2019-05-29 20:05:24 +00:00
|
|
|
|
2019-05-29 20:43:48 +00:00
|
|
|
fs.writeFileSync(file('twemoji.min.js'), `${copyright}\n${minifiedContents}`);
|
|
|
|
fs.writeFileSync(file('twemoji.esm.js'), `${copyright}\n${minifiedContents}\nexport default twemoji;`);
|
|
|
|
|
2019-05-29 20:05:24 +00:00
|
|
|
const algorithm = 'sha384';
|
|
|
|
const digest = spawnSync('openssl', ['dgst', `-${algorithm}`, '-binary', file('twemoji.min.js')]);
|
|
|
|
if (digest.status || digest.signal){
|
|
|
|
throw new Error(digest.stderr.toString('utf8'));
|
|
|
|
}
|
2019-05-29 23:40:31 +00:00
|
|
|
const integrityHash = digest.stdout.toString('base64');
|
|
|
|
const integrity = ``;
|
|
|
|
const { version } = require('../../package.json');
|
|
|
|
const src = ``
|
2019-05-29 20:05:24 +00:00
|
|
|
|
2019-05-29 23:40:31 +00:00
|
|
|
function updateScript(filename) {
|
|
|
|
const newScript = `<script src="https://twemoji.maxcdn.com/2/twemoji.min.js?${version}" integrity="${algorithm}-${integrityHash}"`
|
2019-05-29 20:05:24 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
filename,
|
2019-05-29 23:40:31 +00:00
|
|
|
fs.readFileSync(filename).toString('utf8').replace(/<script src="[^ ]*" integrity="[^ ]*"/, newScript));
|
2019-05-29 20:05:24 +00:00
|
|
|
}
|
|
|
|
|
2019-05-29 23:40:31 +00:00
|
|
|
updateScript(file('..', 'README.md'));
|
|
|
|
updateScript(file('templates', 'preview.html'));
|