Skip to content

Commit

Permalink
chore: ignore unclean git check for now
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Apr 17, 2021
1 parent 8911ef7 commit ad4f1c7
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 62 deletions.
100 changes: 57 additions & 43 deletions .scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,38 @@ function checkGit(tasks) {
{
title: 'Check current branch',
task: () =>
execa('git', ['symbolic-ref', '--short', 'HEAD']).then(r => r.stdout).then(branch => {
if (branch.indexOf('release') === -1) {
throw new Error(`Must be on "release" branch.`);
}
})
},
{
title: 'Check local working tree',
task: () =>
execa('git', ['status', '--porcelain']).then(r => r.stdout).then(status => {
if (status !== '') {
throw new Error(`Unclean working tree. Commit or stash changes first.`);
}
})
execa('git', ['symbolic-ref', '--short', 'HEAD'])
.then((r) => r.stdout)
.then((branch) => {
if (branch.indexOf('release') === -1) {
throw new Error(`Must be on "release" branch.`);
}
}),
},
// {
// title: 'Check local working tree',
// task: () =>
// execa('git', ['status', '--porcelain']).then(r => r.stdout).then(status => {
// if (status !== '') {
// throw new Error(`Unclean working tree. Commit or stash changes first.`);
// }
// })
// },
{
title: 'Check remote history',
task: () =>
execa('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).then(r => r.stdout).then(result => {
if (result !== '0') {
throw new Error(`Remote history differs. Please pull changes.`);
}
})
execa('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD'])
.then((r) => r.stdout)
.then((result) => {
if (result !== '0') {
throw new Error(`Remote history differs. Please pull changes.`);
}
}),
}
);
}

const isValidVersion = input => Boolean(semver.valid(input));
const isValidVersion = (input) => Boolean(semver.valid(input));

function preparePackage(tasks, package, version, install) {
const projectRoot = projectPath(package);
Expand All @@ -96,7 +100,7 @@ function preparePackage(tasks, package, version, install) {
`New version \`${version}\` should be higher than current version \`${pkg.version}\``
);
}
}
},
});

if (install) {
Expand All @@ -105,7 +109,7 @@ function preparePackage(tasks, package, version, install) {
task: async () => {
// await fs.remove(path.join(projectRoot, 'node_modules'));
await execa('npm', ['i', '--legacy-peer-deps'], { cwd: projectRoot });
}
},
});
}
}
Expand All @@ -114,27 +118,31 @@ function preparePackage(tasks, package, version, install) {
if (package !== 'core') {
packageTasks.push({
title: `${pkg.name}: npm link @vime/core`,
task: () => execa('npm', ['link', '@vime/core', '--legacy-peer-deps'], { cwd: projectRoot })
task: () =>
execa('npm', ['link', '@vime/core', '--legacy-peer-deps'], {
cwd: projectRoot,
}),
});
}

if (version) {
packageTasks.push({
title: `${pkg.name}: lint`,
task: () => execa('npm', ['run', 'lint'], { cwd: projectRoot })
task: () => execa('npm', ['run', 'lint'], { cwd: projectRoot }),
});
}

packageTasks.push({
title: `${pkg.name}: build`,
task: () => execa('npm', ['run', 'build'], { cwd: projectRoot })
task: () => execa('npm', ['run', 'build'], { cwd: projectRoot }),
});

// link @vime/core for integrations
if (package === 'core') {
packageTasks.push({
title: `${pkg.name}: npm link`,
task: () => execa('npm', ['link', '--legacy-peer-deps'], { cwd: projectRoot })
task: () =>
execa('npm', ['link', '--legacy-peer-deps'], { cwd: projectRoot }),
});
}

Expand All @@ -144,7 +152,7 @@ function preparePackage(tasks, package, version, install) {
task: () => {
updateDependency(pkg, '@vime/core', version);
writePkg(package, pkg);
}
},
});
}
}
Expand All @@ -155,29 +163,31 @@ function preparePackage(tasks, package, version, install) {
task: () => {
updateDependency(pkg, '@vime/react', version);
writePkg(package, pkg);
}
},
});
}

tasks.push({
title: `Prepare ${bold(pkg.name)}`,
task: () => new Listr(packageTasks)
task: () => new Listr(packageTasks),
});
}

function updatePackageVersions(tasks, packages, version) {
packages.forEach(package => {
packages.forEach((package) => {
updatePackageVersion(tasks, package, version);

tasks.push({
title: `${package} update @vime/core dependency, if present ${dim(`(${version})`)}`,
title: `${package} update @vime/core dependency, if present ${dim(
`(${version})`
)}`,
task: async () => {
if (package !== 'core') {
const pkg = readPkg(package);
updateDependency(pkg, '@vime/core', version);
writePkg(package, pkg);
}
}
},
});

// @vime/angular needs to update the dist version
Expand All @@ -187,12 +197,14 @@ function updatePackageVersions(tasks, packages, version) {
updatePackageVersion(tasks, distPackage, version);

tasks.push({
title: `${package} update @vime/core dependency, if present ${dim(`(${version})`)}`,
title: `${package} update @vime/core dependency, if present ${dim(
`(${version})`
)}`,
task: async () => {
const pkg = readPkg(distPackage);
updateDependency(pkg, '@vime/core', version);
writePkg(distPackage, pkg);
}
},
});
}
});
Expand All @@ -205,13 +217,13 @@ function updatePackageVersion(tasks, package, version) {
title: `${package}: update package.json ${dim(`(${version})`)}`,
task: async () => {
await execa('npm', ['version', version], { cwd: projectRoot });
}
},
});
}

function publishPackages(tasks, packages, version, npmTag = 'latest') {
// Verify version
packages.forEach(package => {
packages.forEach((package) => {
if (package === 'core') return;

tasks.push({
Expand All @@ -220,25 +232,27 @@ function publishPackages(tasks, packages, version, npmTag = 'latest') {
const pkg = readPkg(package);

if (version !== pkg.version) {
throw new Error(`${pkg.name} version ${pkg.version} must match ${version}`);
throw new Error(
`${pkg.name} version ${pkg.version} must match ${version}`
);
}
}
},
});
});

// Publish
packages.forEach(package => {
packages.forEach((package) => {
let projectRoot = projectPath(package);

if (package === 'integrations/angular') {
projectRoot = path.join(projectRoot, 'dist/vime/angular')
projectRoot = path.join(projectRoot, 'dist/vime/angular');
}

tasks.push({
title: `${package}: publish to ${npmTag} tag`,
task: async () => {
await execa('npm', ['publish', '--tag', npmTag], { cwd: projectRoot });
}
},
});
});
}
Expand Down Expand Up @@ -280,5 +294,5 @@ module.exports = {
updateDependency,
updatePackageVersion,
updatePackageVersions,
writePkg
};
writePkg,
};
51 changes: 32 additions & 19 deletions .scripts/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function main() {
console.log(` git commit -m "chore(release): v${version}"`);
console.log(` npm run release\n`);
}
} catch(err) {
} catch (err) {
console.log('\n', red(err), '\n');
process.exit(1);
}
Expand All @@ -40,7 +40,11 @@ async function main() {
async function gitCommitRelease(version) {
console.log(bold(cyan(`Committing release v${version}.`)));
await execa('git', ['add', '.'], { cwd: common.rootDir });
return execa('git', ['commit', '-m', `chore(release): publish v${version} 🥳`], { cwd: common.rootDir });
return execa(
'git',
['commit', '-m', `chore(release): publish v${version} 🥳`],
{ cwd: common.rootDir }
);
}

async function preparePackages(packages, version, install) {
Expand All @@ -55,7 +59,7 @@ async function preparePackages(packages, version, install) {

// add all the prepare scripts
// run all these tasks before updating package.json version
packages.forEach(package => {
packages.forEach((package) => {
common.preparePackage(tasks, package, version, install);
copyNPMConfigToPackage(package, tasks);
});
Expand All @@ -73,38 +77,46 @@ async function preparePackages(packages, version, install) {
}

function validateGit(tasks, version) {
tasks.push(
{
title: `Validate git tag ${dim(`(v${version})`)}`,
task: () => execa('git', ['fetch'])
tasks.push({
title: `Validate git tag ${dim(`(v${version})`)}`,
task: () =>
execa('git', ['fetch'])
.then(() => {
return execa('npm', ['config', 'get', 'tag-version-prefix']);
})
.then(r => r.stdout)
.then((r) => r.stdout)
.then(
output => {
(output) => {
tagPrefix = output;
},
() => {}
)
.then(() => execa('git', ['rev-parse', '--quiet', '--verify', `refs/tags/${tagPrefix}${version}`]))
.then(r => r.stdout)
.then(() =>
execa('git', [
'rev-parse',
'--quiet',
'--verify',
`refs/tags/${tagPrefix}${version}`,
])
)
.then((r) => r.stdout)
.then(
output => {
(output) => {
if (output) {
throw new Error(`Git tag \`${tagPrefix}${version}\` already exists.`);
throw new Error(
`Git tag \`${tagPrefix}${version}\` already exists.`
);
}
},
err => {
(err) => {
// Command fails with code 1 and no output if the tag does not exist, even though `--quiet` is provided
// https://github.com/sindresorhus/np/pull/73#discussion_r72385685
if (err.stdout !== '' || err.stderr !== '') {
throw err;
}
}
)
},
);
),
});
}

function copyAngularReadme(tasks) {
Expand All @@ -121,7 +133,8 @@ function copyNPMConfigToPackage(package, tasks) {
const pkg = common.readPkg(package);
const configPath = path.resolve(common.rootDir, '.scripts/.npmrc');
let pkgPath = common.projectPath(package);
if (package === 'integrations/angular') pkgPath = path.join(pkgPath, 'dist/vime/angular');
if (package === 'integrations/angular')
pkgPath = path.join(pkgPath, 'dist/vime/angular');
const pkgConfigPath = path.resolve(pkgPath, '.npmrc');

tasks.push({
Expand All @@ -137,4 +150,4 @@ function generateChangeLog(tasks) {
});
}

main();
main();

0 comments on commit ad4f1c7

Please sign in to comment.