Skip to content

Commit

Permalink
build: added updateVersion build step
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0n committed May 18, 2022
1 parent 023e36f commit 98d2fc3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const writeFile = util.promisify(fs.writeFile);
const rimraf = require('rimraf');
const copyPackageFiles = require('./copyPackageFiles');
const generateLocaleTypes = require('./generateLocaleTypes');
const updateVersion = require('./updateVersion');

let babelConfig = path.resolve(__dirname, '../babel.config.js');
let srcPath = path.resolve('./src');
Expand All @@ -33,6 +34,13 @@ async function run() {
rimraf.sync(distPath);
fs.mkdirSync(distPath);

try {
await updateVersion();
log.success('Version updated successfully');
} catch (e) {
log.error('Error while updating version');
}

try {
await execAsync('set NODE_ENV="production"&& webpack');
log.success('Bundle compiled successfully');
Expand All @@ -56,7 +64,7 @@ async function run() {

try {
await generateLocaleTypes();
log.success('Localization types are generated')
log.success('Localization types are generated');
} catch (e) {
log.error(`Error while generating types for locale files: ${e}`,);
}
Expand All @@ -66,7 +74,7 @@ async function run() {
path.join(distPath, 'index.es.js'),
'import AirDatepicker from \'./air-datepicker\';\nexport default AirDatepicker'
);
log.success('ES module file created')
log.success('ES module file created');
} catch (e) {
log.error('Could not create ES index file');
}
Expand Down
18 changes: 18 additions & 0 deletions scripts/updateVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require('path');
const fs = require('fs');
const packageJson = require('../package.json');
const util = require('util');
const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);

const srcPath = path.resolve('.');
const file = path.resolve(srcPath, 'src/datepicker.js');

module.exports = async () => {
const datepickerFile = await readFile(file, 'UTF-8');
const updatedFile = datepickerFile.replace(/static version = '(.+)'/, (match, $1) => {
return match.replace($1, packageJson.version);
});

await writeFile(file, updatedFile);
};

0 comments on commit 98d2fc3

Please sign in to comment.