Skip to content
This repository has been archived by the owner on May 13, 2023. It is now read-only.

Commit

Permalink
feat: add release script
Browse files Browse the repository at this point in the history
  • Loading branch information
devCrossNet committed Jan 5, 2023
1 parent a60699a commit 5ff6e14
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 87 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ coverage
cypress/screenshots/**
cypress/videos/**
storybook-static
.DS_Store
113 changes: 30 additions & 83 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"new:page": "hygen new page",
"type-gen:swagger": "openapi-typescript https://petstore.swagger.io/v2/swagger.json --output src/interfaces/swagger.ts",
"extract-i18n-messages": "ts-node ./tools/extract-i18n-messages.ts",
"test:watch": "cross-env NODE_ICU_DATA=node_modules/full-icu vuesion test --coverage --watch",
"test:watch": "cross-env NODE_ICU_DATA=node_modules/full-icu vitest",
"e2e": "cypress run --headless",
"lint": "eslint . --ext ts,vue --fix --cache && tsc --project ./tsconfig.json --noEmit",
"storybook:build": "build-storybook",
"release:major": "vuesion release --major",
"release:minor": "vuesion release --minor",
"release:patch": "vuesion release --patch",
"release:major": "ts-node ./tools/release.ts --major",
"release:minor": "ts-node ./tools/release.ts --minor",
"release:patch": "ts-node ./tools/release.ts --patch",
"build": "nuxt build",
"build:analyze": "nuxt build --analyze",
"build:spa": "nuxt generate",
Expand Down Expand Up @@ -97,6 +97,7 @@
"eslint-plugin-storybook": "0.6.8",
"eslint-plugin-vue": "9.8.0",
"flush-promises": "1.0.2",
"generate-changelog": "1.8.0",
"happy-dom": "8.1.1",
"html-webpack-plugin": "5.5.0",
"husky": "8.0.2",
Expand Down
2 changes: 2 additions & 0 deletions tools/extract-i18n-messages.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-console */

import * as fs from 'fs';
import * as path from 'path';
import * as glob from 'glob';
Expand Down
52 changes: 52 additions & 0 deletions tools/release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable no-console */
import { runProcess } from './utils';

const versionArg = process.argv[2];

const run = async () => {
let npmVersion = 'major';

if (versionArg === '--minor') {
npmVersion = 'minor';
} else if (versionArg === '--patch') {
npmVersion = 'patch';
}

console.log(`Releasing new ${npmVersion} version...`);

try {
console.log('Generating CHANGELOG.md...');

await runProcess('changelog', [versionArg]);

console.log('Adding CHANGELOG.md...');

await runProcess('git', ['add', 'CHANGELOG.md']);

console.log('Running pre-commit hooks...');

await runProcess('git', ['commit', '-m', 'chore: update changelog']);

console.log('Committing changes...');

console.log(`Releasing npm ${npmVersion} version...`);

await runProcess('npm', ['version', npmVersion]);

console.log('Pushing changes...');

await runProcess('git', ['push', 'origin']);

console.log('Pushing tags...');

await runProcess('git', ['push', 'origin', '--tags']);

console.log('');

console.log('New version released.');
} catch (e) {
console.error(e);
}
};

run().catch((e) => console.log(e));
44 changes: 44 additions & 0 deletions tools/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import { spawn, SpawnOptions } from 'child_process';

export const getTranslationsFromString = (content: string): RegExpMatchArray => {
const result: any = [];
Expand Down Expand Up @@ -61,4 +62,47 @@ export const ensureDirectoryExists = (filePath: string) => {
fs.mkdirSync(dirname);
};

export interface IProcessOptions {
cwd?: string;
silent?: boolean;
debug?: boolean;
}

export interface IProcessError {
code: number;
trace: string;
}

export const runProcess = (name: string, args: string[] = [], options?: IProcessOptions): Promise<any> => {
return new Promise((resolve: any, reject: any) => {
options = Object.assign({ cwd: process.cwd(), silent: false, debug: false }, options);

const localOptions: SpawnOptions = Object.assign(
{
detached: false,
cwd: options.cwd,
env: process.env,
},
options.silent === false || options.debug === true ? { stdio: 'inherit' as const } : {},
);
const childProcess: any = spawn(name, args, localOptions);

childProcess.on('exit', (code: number) => {
childProcess.kill();

if (code === 0) {
resolve(undefined);
} else {
const err: IProcessError = { code, trace: '' };
reject(err);
}
});

childProcess.on('error', (e: Error) => {
childProcess.kill();
reject(e);
});
});
};

/* c8 ignore end */

0 comments on commit 5ff6e14

Please sign in to comment.