Skip to content

Commit

Permalink
Revert "feat: Emoji build (#1766)"
Browse files Browse the repository at this point in the history
This reverts commit 2bd1171.
  • Loading branch information
Koooooo-7 authored Oct 26, 2022
1 parent 4e642d9 commit 80908b9
Show file tree
Hide file tree
Showing 5 changed files with 1,900 additions and 1,923 deletions.
52 changes: 17 additions & 35 deletions build/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ const filePaths = {
'src',
'core',
'render',
'emoji-data.js'
'emojify-data.js'
),
};

async function getEmojiData() {
const emojiDataURL = 'https://api.github.com/emojis';

console.info(`- Fetching emoji data from ${emojiDataURL}`);

const response = await axios.get(emojiDataURL);
const baseURL = Object.values(response.data)
.find(url => /unicode\//)
Expand All @@ -29,18 +26,16 @@ async function getEmojiData() {
([key, value]) => (data[key] = value.replace(baseURL, ''))
);

console.info(`- Retrieved ${Object.keys(data).length} emoji entries`);

return {
baseURL,
data,
};
}

function writeEmojiPage(emojiData) {
const isExistingPage = fs.existsSync(filePaths.emojiMarkdown);
const emojiPage =
(isExistingPage && fs.readFileSync(filePaths.emojiMarkdown, 'utf8')) ||
(fs.existsSync(filePaths.emojiMarkdown) &&
fs.readFileSync(filePaths.emojiMarkdown, 'utf8')) ||
`<!-- START -->\n\n<!-- END -->`;
const emojiRegEx = /(<!--\s*START.*-->\n)([\s\S]*)(\n<!--\s*END.*-->)/;
const emojiMatch = emojiPage.match(emojiRegEx);
Expand All @@ -58,52 +53,39 @@ function writeEmojiPage(emojiData) {
if (emojiMarkdown !== newEmojiMarkdown) {
const newEmojiPage = emojiPage.replace(
emojiMatch[0],
`${emojiMarkdownStart}\n\n${newEmojiMarkdown}\n\n${emojiMarkdownEnd}`
`${emojiMarkdownStart}\n${newEmojiMarkdown}\n${emojiMarkdownEnd}`
);

fs.writeFileSync(filePaths.emojiMarkdown, newEmojiPage);

console.info(
`- ${!isExistingPage ? 'Created' : 'Updated'}: ${filePaths.emojiMarkdown}`
);
console.info(`- Created new file: ${filePaths.emojiMarkdown}`);
} else {
console.info(`- No changes: ${filePaths.emojiMarkdown}`);
console.info(`- No changes to file: ${filePaths.emojiMarkdown}`);
}
}

function writeEmojiJS(emojiData) {
const isExistingPage = fs.existsSync(filePaths.emojiJS);
const emojiJS = isExistingPage && fs.readFileSync(filePaths.emojiJS, 'utf8');
const newEmojiJS = [
'/* eslint-disable */\n',
'// =============================================================================',
'// DO NOT EDIT: This file is auto-generated by an /build/emoji.js',
'// =============================================================================\n',
`export default ${JSON.stringify(emojiData, {}, 2)}`,
].join('\n');
const emojiJS =
fs.existsSync(filePaths.emojiJS) &&
fs.readFileSync(filePaths.emojiJS, 'utf8');
const newEmojiJS = `export default ${JSON.stringify(emojiData, {}, 2)}`;

if (!emojiJS || emojiJS !== newEmojiJS) {
fs.writeFileSync(filePaths.emojiJS, newEmojiJS);

console.info(
`- ${!isExistingPage ? 'Created' : 'Updated'}: ${filePaths.emojiJS}`
);
console.info(`- Created new file: ${filePaths.emojiJS}`);
} else {
console.info(`- No changes: ${filePaths.emojiJS}`);
console.info(`- No changes to file: ${filePaths.emojiJS}`);
}
}

(async () => {
console.info('Build emoji');
console.log('Build emoji');

try {
const emojiData = await getEmojiData();

if (emojiData) {
writeEmojiPage(emojiData);
writeEmojiJS(emojiData);
}
} catch (err) {
console.warn(`- Error: ${err.message}`);
writeEmojiPage(emojiData);
writeEmojiJS(emojiData);
} catch (e) {
console.error(e);
}
})();
4 changes: 2 additions & 2 deletions docs/emoji.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Below is a complete list of emoji shorthand codes. Docsify can be configured to

<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(15em, 1fr));">

<!-- START: Auto-generated content (/build/emoji.js) -->
<!-- START: auto-generated emoji markdown (do not edit between these comments) -->

:100: `:100:`

Expand Down Expand Up @@ -3754,6 +3754,6 @@ Below is a complete list of emoji shorthand codes. Docsify can be configured to

:zzz: `:zzz:`

<!-- END: Auto-generated content (/build/emoji.js) -->
<!-- END: auto-generated emoji markdown -->

</div>
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
</script>
<script src="/lib/docsify.js"></script>
<script src="/lib/plugins/search.js"></script>
<script src="/lib/plugins/emoji.js"></script>
<script src="/lib/plugins/front-matter.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-bash.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-markdown.min.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
"build:cover": "node build/cover.js",
"build:css:min": "mkdirp lib/themes && npm run css -- -o lib/themes && node build/mincss.js",
"build:css": "mkdirp themes && npm run css -- -o themes",
"build:emoji": "node ./build/emoji.js",
"build:emoji": "node ./build/emoji.js && eslint ./src/core/render/emojify-data.js --fix --quiet",
"build:js": "cross-env NODE_ENV=production node build/build.js",
"build:ssr": "node build/ssr.js",
"build:test": "npm run build && npm test",
"build": "rimraf lib themes && run-s build:js build:css build:css:min build:ssr build:cover build:emoji",
"build": "rimraf lib themes && run-s build:js build:css build:css:min build:ssr build:cover",
"css": "node build/css",
"dev:ssr": "run-p serve:ssr watch:*",
"dev": "run-p serve watch:*",
Expand Down
Loading

0 comments on commit 80908b9

Please sign in to comment.