Skip to content

Instantly share code, notes, and snippets.

View qodunpob's full-sized avatar
🥃
Drink Driven Development

Konstantin qodunpob

🥃
Drink Driven Development
View GitHub Profile
const isDiff = !!spawnSync('git', ['diff'], getSpawnOptions(rootDir, 'pipe')).stdout.toString().trim();
/* temporary directory for the builds repository */
const tempDir = join(rootDir, 'temp');
if (existsSync(tempDir)) {
spawnSync('rm', ['-rf', 'temp'], getSpawnOptions(rootDir));
}
mkdirSync(tempDir);
/* getting parameters from the package.json */
const { name, version, repository } = require(join(rootDir, 'package.json'));
const originUrl = repository.url.replace(`${name}-source`, name);
/* current branch name in the module source code repository */
const branch = spawnSync(
'git',
['symbolic-ref', '--short', 'HEAD'],
getSpawnOptions(rootDir, 'pipe')
).stdout.toString().trim();
/* branch name in the builds repository */
const buildBranch = branch === 'develop' ? 'master' : branch;
/* Shortened hash of the last commit in source code repository.
Used for forming of the unstable version tag */
const shortSHA = spawnSync(
'git',
['rev-parse', '--short', 'HEAD'],
getSpawnOptions(rootDir, 'pipe')
).stdout.toString().trim();
const tag = buildBranch === 'master' ? version : `${version}_${shortSHA}`;
/* checking if the created tag exists in build repository */
const isTagExists = !!spawnSync(
'git',
['ls-remote', 'origin', `refs/tags/${tag}`],
getSpawnOptions(tempDir, 'pipe')
).stdout.toString().trim();
/* checking if branch exists in builds repository */
const isBranchExits = !!spawnSync(
'git',
['ls-remote', '--exit-code', 'origin', buildBranch],
getSpawnOptions(tempDir, 'pipe')
).stdout.toString().trim();
if (isBranchExits) {
/* checkout the target branch */
spawnSync('git', ['fetch', 'origin', buildBranch], getSpawnOptions(tempDir));
/* removing the old build files */
spawnSync(
'rm',
['-rf', 'lib', 'package.json', 'package-lock.json', 'README.md'],
getSpawnOptions(tempDir)
);
/* creating build files copies */
spawnSync('cp', ['-r', 'lib', 'temp/lib'], getSpawnOptions(rootDir));
spawnSync('cp', ['package.json', 'temp/package.json'], getSpawnOptions(rootDir));
spawnSync('cp', ['package-lock.json', 'temp/package-lock.json'], getSpawnOptions(rootDir));
spawnSync('cp', ['README.md', 'temp/README.md'], getSpawnOptions(rootDir));
/* indexing the build files */
spawnSync('git', ['add', '--all'], getSpawnOptions(tempDir));
/* message of the last commit in source code repository */
const lastCommitMessage = spawnSync(
'git',
['log', '--oneline', '-1'],
getSpawnOptions(rootDir, 'pipe')
).stdout.toString().trim();
/* commit message in build repository */
const message = buildBranch === 'master' ? version : lastCommitMessage;
/* making commit in builds repository */