diff --git a/package.json b/package.json index 854de27f..c23391ed 100644 --- a/package.json +++ b/package.json @@ -137,6 +137,7 @@ "autoprefixer": "^10.3.7", "axios-hooks": "^3.0.0", "cypress": "^9.1.0", + "enquirer": "^2.3.6", "grapesjs": "^0.17.29", "grapesjs-blocks-basic": "^0.1.8", "grapesjs-preset-webpage": "^0.1.11", @@ -158,6 +159,7 @@ "react-transition-group": "^4.4.2", "recoil": "^0.4.0", "recoil-persist": "^3.0.0", + "semver-utils": "^1.1.4", "start-server-and-test": "^1.14.0", "tailwindcss": "^2.2.7", "tailwindcss-scrollbar": "^0.1.0", diff --git a/scripts/release.js b/scripts/release.js new file mode 100644 index 00000000..f0c16bac --- /dev/null +++ b/scripts/release.js @@ -0,0 +1,44 @@ +const { Select } = require('enquirer'); +const { readFileSync, writeFileSync, write } = require('fs'); +const { join } = require('path'); +const { parse, stringify } = require('semver-utils'); +const { execSync } = require('child_process'); + +const prompt = new Select({ + name: 'semver', + message: 'Choose a version change level (semver):', + choices: ['patch', 'minor', 'major'], +}); + +prompt + .run() + .then(async answer => { + const vfile = join(__dirname, '../version'); + const pfile = join(__dirname, '../package.json'); + const current = readFileSync(vfile).toString(); + console.log('Current version:', current); + + const semver = parse(current); + + semver[answer] = parseInt(semver[answer], 10) + 1; + const bumped = stringify(semver); + console.log('New version:', bumped); + + const package = require(pfile); + package.version = bumped; + + writeFileSync(pfile, JSON.stringify(package, null, 2)); + writeFileSync(vfile, bumped); + + console.log('Version updated'); + + execSync( + `git add version package.json && git commit -m "Release ${bumped}"`, + { + cwd: join(__dirname, '../'), + }, + ); + + console.log('Commit made for the automatic release'); + }) + .catch(console.error); diff --git a/yarn.lock b/yarn.lock index 83bdd678..3182a52d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7389,6 +7389,11 @@ semver-store@^0.3.0: resolved "https://registry.yarnpkg.com/semver-store/-/semver-store-0.3.0.tgz#ce602ff07df37080ec9f4fb40b29576547befbe9" integrity sha512-TcZvGMMy9vodEFSse30lWinkj+JgOBvPn8wRItpQRSayhc+4ssDs335uklkfvQQJgL/WvmHLVj4Ycv2s7QCQMg== +semver-utils@^1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/semver-utils/-/semver-utils-1.1.4.tgz#cf0405e669a57488913909fc1c3f29bf2a4871e2" + integrity sha512-EjnoLE5OGmDAVV/8YDoN5KiajNadjzIp9BAHOhYeQHt7j0UWxjmgsx4YD48wp4Ue1Qogq38F1GNUJNqF1kKKxA== + semver@7.x, semver@^7.3.2, semver@^7.3.5: version "7.3.5" resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"