Skip to content

Commit

Permalink
introduce a script that publishes a staging from fork (#3684)
Browse files Browse the repository at this point in the history
  • Loading branch information
VasilyStrelyaev authored Dec 12, 2024
1 parent 0d98407 commit eabf5bf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"test:watch": "jest --watch",
"publish:prepare": "yarn && node ./scripts/prepare-commit.js",
"publish:npm": "yarn && node ./scripts/publish-npm.js",
"publish:site": "yarn && node ./scripts/publish-site.js",
"publish:site": "yarn && node ./scripts/publish-prod-site.js",
"publish:staging": "yarn && node ./scripts/publish-staging.js",
"update-api": "lerna run update-api -- --local",
"update-api:ci": "lerna run update-api",
"start-demo-servers": "yarn build:generator && lerna run --parallel start-demo-server:prod",
Expand Down
3 changes: 3 additions & 0 deletions scripts/publish-prod-site.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { publishSite } from './publish-site';

publishSite(true);
33 changes: 19 additions & 14 deletions scripts/publish-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,31 @@ const SITE_PUBLISHING_DIRECTORY = join(process.cwd(), 'tmp');
const BRANCH = 'gh-pages';
const COMMIT_MESSAGE = 'chore: update site';

const script = async () => {
export const publishSite = async (prod = false) => {
const currentBranchName = getCurrentBranchName();
ensureRepoUpToDate(currentBranchName);

if (prod) {
ensureRepoUpToDate(currentBranchName);
}

console.log();
console.log('====================');
console.log(`| Publishing site`);
console.log('====================');
console.log();

const version = loadJSON('../lerna.json').version;
const suggestedTag = prerelease(version) !== null ? 'next' : 'latest';
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}` : '';
let tagPath = '';

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

console.log('Building site content...');
const packagesDir = dirname(fileURLToPath(import.meta.url));
Expand All @@ -54,7 +61,7 @@ const script = async () => {
console.log('Publishing...');
execSync('git add --all', { cwd: SITE_PUBLISHING_DIRECTORY });
execSync(`git commit -m "${COMMIT_MESSAGE}"`, { cwd: SITE_PUBLISHING_DIRECTORY });
execSync(`git push upstream ${BRANCH}`, { cwd: SITE_PUBLISHING_DIRECTORY });
execSync(`git push ${prod ? 'upstream' : 'origin'} ${BRANCH}`, { cwd: SITE_PUBLISHING_DIRECTORY });

console.log('Cleaning up...');
removeSync(SITE_PUBLISHING_DIRECTORY);
Expand All @@ -65,9 +72,7 @@ const script = async () => {
console.log('--------------------');
console.log('Done!');
console.log();
console.log(`You have to check that everything is good at https://devexpress.github.io/devextreme-reactive${tagPath}/`);
console.log(`You have to check that everything is good${prod ? `at https://devexpress.github.io/devextreme-reactive${tagPath}/` : ''}`);
console.log('--------------------');
console.log();
};

script();
3 changes: 3 additions & 0 deletions scripts/publish-staging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { publishSite } from './publish-site';

publishSite(false);

0 comments on commit eabf5bf

Please sign in to comment.