Skip to content

Commit

Permalink
chore: fix publish scripts (#3599)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krijovnick authored Nov 24, 2022
1 parent 9b79e78 commit b7b8e79
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 50 deletions.
6 changes: 3 additions & 3 deletions scripts/ensure-repo-up-to-date.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { execSync } = require('child_process');
import { execSync } from 'child_process';

module.exports = (targetBranchName = 'master') => {
export default (targetBranchName = 'master') => {
console.log(`Fetching the latest changes from upstream/${targetBranchName}...`);
const startingGitRevision = execSync('git rev-parse HEAD', { stdio: 'pipe' }).toString();
execSync(`git fetch --tags upstream ${targetBranchName}`, { stdio: 'ignore' });
Expand All @@ -10,4 +10,4 @@ module.exports = (targetBranchName = 'master') => {
console.log('Repo updated. Please, rerun script.');
process.exit(-1);
}
}
};
4 changes: 2 additions & 2 deletions scripts/get-current-branch-name.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { execSync } = require('child_process');
import { execSync } from 'child_process';

module.exports = () =>
export default () =>
execSync('git branch', { stdio: 'pipe' })
.toString()
.trim()
Expand Down
26 changes: 14 additions & 12 deletions scripts/prepare-commit.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const { join } = require('path');
const { readFileSync, writeFileSync } = require('fs');
const { execSync } = require('child_process');
const { prompt } = require('inquirer');
const { valid, lt, inc, prerelease } = require('semver');
const conventionalRecommendedBump = require('conventional-recommended-bump');
const getCurrentBranchName = require('./get-current-branch-name');
const ensureRepoUpToDate = require('./ensure-repo-up-to-date');
const updatePeerDeps = require('./update-peer-deps');
import { join } from 'path';
import { readFileSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';
import inquirer from 'inquirer';
import { valid, lt, inc, prerelease } from 'semver';
import conventionalRecommendedBump from 'conventional-recommended-bump';
import getCurrentBranchName from './get-current-branch-name.js';
import ensureRepoUpToDate from './ensure-repo-up-to-date.js';
import updatePeerDeps from './update-peer-deps.js';

const CONVENTIONAL_CHANGELOG_PRESET = 'angular';

const loadJSON = (path) => JSON.parse(readFileSync(new URL(path, import.meta.url)));

const script = async () => {
const currentBranchName = getCurrentBranchName();
ensureRepoUpToDate(currentBranchName);
Expand All @@ -20,7 +22,7 @@ const script = async () => {
console.log('====================');
console.log();

const currentVersion = require('../lerna.json').version;
const currentVersion = loadJSON('../lerna.json').version;
const recommendedReleaseType = await new Promise((resolve) => {
conventionalRecommendedBump({
preset: CONVENTIONAL_CHANGELOG_PRESET
Expand All @@ -29,7 +31,7 @@ const script = async () => {
})
});
const suggestedVersion = inc(currentVersion, (prerelease(currentVersion) !== null ? 'prerelease' : recommendedReleaseType));
const { version } = await prompt({
const { version } = await inquirer.prompt({
name: 'version',
message: `Enter new version [current: ${currentVersion}]:`,
default: suggestedVersion,
Expand Down Expand Up @@ -57,7 +59,7 @@ const script = async () => {
execSync(`"./node_modules/.bin/lerna" version ${version} --exact --force-publish --no-git-tag-version --yes`, { stdio: 'ignore' });
updatePeerDeps();

const { commit } = await prompt({
const { commit } = await inquirer.prompt({
message: 'Ready to commit. Please check build result and CHANGELOG.md. Is it ok?',
name: 'commit',
type: 'confirm',
Expand Down
19 changes: 11 additions & 8 deletions scripts/publish-npm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const { execSync } = require('child_process');
const { prompt } = require('inquirer');
const { prerelease } = require('semver');
const getCurrentBranchName = require('./get-current-branch-name');
const ensureRepoUpToDate = require('./ensure-repo-up-to-date');
import { execSync } from 'child_process';
import inquirer from 'inquirer';
import { prerelease } from 'semver';
import getCurrentBranchName from './get-current-branch-name.js';
import ensureRepoUpToDate from './ensure-repo-up-to-date.js';
import { readFileSync } from 'fs';

const loadJSON = (path) => JSON.parse(readFileSync(new URL(path, import.meta.url)));

const script = async () => {
const currentBranchName = getCurrentBranchName();
Expand All @@ -20,8 +23,8 @@ const script = async () => {
console.log('Building...');
execSync('yarn run build', { stdio: 'ignore' });

const version = require('../lerna.json').version;
const { publishNpm } = await prompt({
const version = loadJSON('../lerna.json').version;
const { publishNpm } = await inquirer.prompt({
message: `Ready to publish version ${version}. Is it ok?`,
name: 'publishNpm',
type: 'confirm',
Expand All @@ -33,7 +36,7 @@ const script = async () => {
}

const suggestedNpmTag = prerelease(version) !== null ? 'next' : 'latest';
const { npmTag } = await prompt({
const { npmTag } = await inquirer.prompt({
name: 'npmTag',
message: `Enter npm relase tag:`,
default: suggestedNpmTag,
Expand Down
32 changes: 18 additions & 14 deletions scripts/publish-site.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const { join } = require('path');
const { execSync } = require('child_process');
const { copySync, removeSync, readFileSync, writeFileSync } = require('fs-extra');
const { prompt } = require('inquirer');
const { prerelease } = require('semver');
const ensureRepoUpToDate = require('./ensure-repo-up-to-date');
const getCurrentBranchName = require('./get-current-branch-name');
import { join, dirname } from 'path';
import { execSync } from 'child_process';
import { copySync, removeSync, readFileSync, writeFileSync } from 'fs-extra';
import inquirer from 'inquirer';
import { prerelease } from 'semver';
import ensureRepoUpToDate from './ensure-repo-up-to-date.js';
import getCurrentBranchName from './get-current-branch-name.js';
import { fileURLToPath } from 'url';

const loadJSON = (path) => JSON.parse(readFileSync(new URL(path, import.meta.url)));

const SITE_PUBLISHING_DIRECTORY = join(process.cwd(), 'tmp');
const BRANCH = 'gh-pages';
Expand All @@ -20,18 +23,19 @@ const script = async () => {
console.log('====================');
console.log();

const version = require('../lerna.json').version;
const version = loadJSON('../lerna.json').version;
const suggestedTag = prerelease(version) !== null ? 'next' : 'latest';
const { tag } = await prompt({
const { tag } = await inquirer.prompt({
name: 'tag',
message: `Enter tag [version: ${version}, write 'latest' to publish site without prefix]:`,
default: suggestedTag,
});
const tagPath = tag !== 'latest' ? `/@${tag}` : '';

console.log('Building site content...');
const config = String(readFileSync(join(__dirname, '../packages/dx-site/gatsby-config.js')));
writeFileSync(join(__dirname, '../packages/dx-site/gatsby-config.js'), config.replace('pathPrefix: \'/devextreme-reactive\'', `pathPrefix: \'/devextreme-reactive${tagPath}\'`));
const packagesDir = dirname(fileURLToPath(import.meta.url));
const config = String(readFileSync(join(packagesDir, '../packages/dx-site/gatsby-config.js')));
writeFileSync(join(packagesDir, '../packages/dx-site/gatsby-config.js'), config.replace('pathPrefix: \'/devextreme-reactive\'', `pathPrefix: \'/devextreme-reactive${tagPath}\'`));
execSync('yarn run build:site', { stdio: 'ignore' });

console.log('Preparing output directory...');
Expand All @@ -40,10 +44,10 @@ const script = async () => {
execSync(`git worktree add -B ${BRANCH} ${SITE_PUBLISHING_DIRECTORY} upstream/${BRANCH}`, { stdio: 'ignore' });

console.log('Copying generated site...');
copySync(join(__dirname, '../packages/dx-site/public/'), join(SITE_PUBLISHING_DIRECTORY, tagPath));
copySync(join(packagesDir, '../packages/dx-site/public/'), join(SITE_PUBLISHING_DIRECTORY, tagPath));

console.log('Copying github stuff...');
copySync(join(__dirname, 'gh-pages-files'), SITE_PUBLISHING_DIRECTORY);
copySync(join(packagesDir, 'gh-pages-files'), SITE_PUBLISHING_DIRECTORY);

console.log('Publishing...');
execSync('git add --all', { cwd: SITE_PUBLISHING_DIRECTORY });
Expand All @@ -53,7 +57,7 @@ const script = async () => {
console.log('Cleaning up...');
removeSync(SITE_PUBLISHING_DIRECTORY);
execSync('git worktree prune');
execSync(`git checkout -- ${join(__dirname, '../packages/dx-site/gatsby-config.js')}`)
execSync(`git checkout -- ${join(packagesDir, '../packages/dx-site/gatsby-config.js')}`)

console.log();
console.log('--------------------');
Expand Down
5 changes: 4 additions & 1 deletion scripts/rm-dist.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
require('fs-extra').removeSync(require('path').join(process.cwd(),'dist'));
import { removeSync } from 'fs-extra';
import { join } from 'path';

removeSync(join(process.cwd(), 'dist'));
21 changes: 11 additions & 10 deletions scripts/update-peer-deps.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
const { join } = require('path');
const {
import { join, dirname } from 'path';
import {
existsSync,
readdirSync,
readFileSync,
writeFileSync
} = require('fs');
writeFileSync,
} from 'fs';
import { fileURLToPath } from 'url';

module.exports = () => {
export default () => {
console.log('Update internal peer dependency versions...');
const packagesDir = join(__dirname, '../packages');
const packagesDir = join(dirname(fileURLToPath(import.meta.url)), '../packages');
const packages = readdirSync(packagesDir);
const verReplacers = packages.map(package =>
new RegExp(`(\\"@devexpress/${package}\\"\\s*:\\s*\\")([^\\"]+)(\\")`, 'gi'));
const verReplacers = packages.map(currentPackage =>
new RegExp(`(\\"@devexpress/${currentPackage}\\"\\s*:\\s*\\")([^\\"]+)(\\")`, 'gi'));

for (let package of packages) {
const configPath = join(packagesDir, `${package}/package.json`);
for (let currentPackage of packages) {
const configPath = join(packagesDir, `${currentPackage}/package.json`);

if (existsSync(configPath)){
const configStr = readFileSync(configPath).toString();
Expand Down

0 comments on commit b7b8e79

Please sign in to comment.