Skip to content

Commit

Permalink
Update tests to use create-release-archive script
Browse files Browse the repository at this point in the history
  • Loading branch information
lfdebrux committed Jun 16, 2022
1 parent 15e3d34 commit 6eddedd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
6 changes: 3 additions & 3 deletions __tests__/spec/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function mkdtempSync () {
function getReleaseVersion () {
if (_releaseVersion === undefined) {
_releaseVersion = child_process.execSync(
'git rev-parse HEAD',
'git describe --tags HEAD',
{ cwd: repoDir, encoding: 'utf8' }
).trim()
).trim().slice(1)
}
return _releaseVersion
}
Expand Down Expand Up @@ -67,7 +67,7 @@ function _mkReleaseArchiveSync ({ archive, prefix }) {
const ref = child_process.execSync('git stash create', { cwd: repoDir, encoding: 'utf8' }) || 'HEAD'

child_process.execSync(
`git archive --worktree-attributes --prefix=${prefix}/ --output=${archive} ${ref}`,
`node scripts/create-release-archive -d ${path.dirname(archive)} ${ref}`,
{ cwd: repoDir }
)
}
Expand Down
25 changes: 20 additions & 5 deletions scripts/create-release-archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,26 @@ const packageJsonScriptsInclude = [
function usage () {
console.log(`
Usage:
scripts/create-release-archive [REF]
scripts/create-release-archive [options] [REF]
Options
-h, --help
Options (advanced):
-d DIR, --destDir DIR
`)
}

function parseArgs (args) {
const argv = { _: [] }
for (const arg of args) {
for (var i = 0; i < args.length; i++) {
var arg = args[i]

if (arg === '-h' || arg === '--help') {
argv.help = true
} else if (arg === '-d' || arg === '--destDir') {
i++
argv.dest = args[i]
} else {
argv._.push(arg)
}
Expand All @@ -43,6 +54,10 @@ function cli () {
return
}

if (argv.dest) {
fs.mkdirSync(argv.dest, { recursive: true })
}

const ref = argv.ref || 'HEAD'
const version = getReleaseVersion(argv.ref)
const newVersion = isNewVersion(version) ? 'new version' : 'version'
Expand All @@ -66,12 +81,12 @@ function cli () {
console.log('Updating package.json')
updatePackageJson(path.join(workdir, name, 'package.json'), cleanPackageJson)

// Create the release archive in the project root
// Create the release archive in the project root (or destDir)
zipReleaseFiles({
cwd: workdir, file: path.join(repoDir, releaseArchive), prefix: name
cwd: workdir, file: path.join(argv.dest || repoDir, releaseArchive), prefix: name
})

console.log(`Saved release archive to ${releaseArchive}`)
console.log(`Saved release archive to ${argv.dest ? argv.dest : ''}${releaseArchive}`)

// Clean up
fs.rmSync(workdir, { force: true, recursive: true })
Expand Down

0 comments on commit 6eddedd

Please sign in to comment.