From eb758c4fdec788afc318237d4d44bc7ac293cda4 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 2 Jun 2020 00:20:11 +0300 Subject: [PATCH] Automatically update version in readme --- packages/iconify/README.md | 4 ++-- packages/iconify/rollup.config.js | 30 +++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/packages/iconify/README.md b/packages/iconify/README.md index 9d5c776..9c24b93 100644 --- a/packages/iconify/README.md +++ b/packages/iconify/README.md @@ -18,7 +18,7 @@ Iconify uses a new innovative approach to loading icons. Unlike fonts and SVG fr Iconify SVG framework is designed to be as easy to use as possible. -Add this line to your page to load Iconify SVG framework (you can add it to `` section of page or before ``): +Add this line to your page to load Iconify SVG framework (you can add it to `` section of the page or before ``): ```html @@ -251,7 +251,7 @@ Possible values for `data-rotate`: 90deg, 180deg, 270deg. If you use both flip and rotation, the icon is flipped first, then rotated. -To use custom transformations use CSS transform rule. Add `!important` after rule to override the SVG inline style (inline style exists to fix a SVG rendering bug in Firefox browser). +To use custom transformations use CSS transform rule. Add `!important` after rule to override the SVG inline style (inline style exists to fix an SVG rendering bug in Firefox browser). ```html diff --git a/packages/iconify/rollup.config.js b/packages/iconify/rollup.config.js index 4f9d4fc..bd18839 100644 --- a/packages/iconify/rollup.config.js +++ b/packages/iconify/rollup.config.js @@ -1,4 +1,4 @@ -import { readFileSync } from 'fs'; +import { readFileSync, writeFileSync } from 'fs'; import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import buble from '@rollup/plugin-buble'; @@ -10,7 +10,7 @@ const global = 'Iconify'; // Wrapper to export module as global and as ES module const header = `/** -* (c) Vjacheslav Trushkin +* (c) Iconify * * For the full copyright and license information, please view the license.txt or license.gpl.txt * files at https://github.com/iconify/iconify @@ -45,9 +45,33 @@ const replacements = {}; const packageJSON = JSON.parse(readFileSync('package.json', 'utf8')); replacements['__iconify_version__'] = packageJSON.version; +// Update README.md +let readme = readFileSync('README.md', 'utf8'); +const oldReadme = readme; +const replaceCodeLink = (search) => { + let start = 0; + let pos; + while ((pos = readme.indexOf(search, start)) !== -1) { + start = pos + search.length; + let pos2 = readme.indexOf('/', start); + if (pos2 === -1) { + return; + } + readme = + readme.slice(0, start) + packageJSON.version + readme.slice(pos2); + } +}; +replaceCodeLink('/code.iconify.design/2/'); +replaceCodeLink('/@iconify/iconify@'); + +if (readme !== oldReadme) { + console.log('Updatead README'); + writeFileSync('README.md', readme, 'utf8'); +} + // Export configuration const config = []; -[false, true].forEach(compress => { +[false, true].forEach((compress) => { const item = { input: `lib/${name}.js`, output: [