-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(versioning-scheme): derive extension version from prisma version
Fixes #121
- Loading branch information
Divyendu Singh
committed
May 4, 2020
1 parent
0aeedd0
commit 4433775
Showing
5 changed files
with
268 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
function nextExtensionVersion({ prismaVersion, extensionVersion }) { | ||
const derivedExtensionVersion = getDerivedExtensionVersion( | ||
stripPreReleaseText(prismaVersion), | ||
) //? | ||
|
||
const derivedExistingExtensionVersion = getDerivedExtensionVersion( | ||
extensionVersion, | ||
) //? | ||
|
||
if (derivedExtensionVersion === derivedExistingExtensionVersion) { | ||
// Extension only publish | ||
return bumpExtensionOnlyVersion(derivedExtensionVersion) | ||
} | ||
return derivedExtensionVersion | ||
} | ||
|
||
function stripPreReleaseText(version) { | ||
return version.replace('-alpha', '').replace('-beta', '').replace('-dev', '') | ||
} | ||
|
||
function getDerivedExtensionVersion(version) { | ||
const tokens = version.split('.') | ||
if (tokens.length === 4) { | ||
return tokens.slice(1).join('.') | ||
} | ||
if (tokens.length === 3) { | ||
return version | ||
} | ||
throw new Error( | ||
`Version ${version} must have 3 or 4 tokens separated by "." character`, | ||
) | ||
} | ||
|
||
function bumpExtensionOnlyVersion(version) { | ||
const tokens = version.split('.') | ||
if (tokens.length === 3) { | ||
return tokens.join('.') + '.1' | ||
} | ||
if (tokens.length === 4) { | ||
return tokens.slice(0, 3).join('.') + (parseInt(tokens[4]) + 1) | ||
} | ||
throw new Error( | ||
`Version ${version} must have 3 or 4 tokens separated by "." character`, | ||
) | ||
} | ||
|
||
module.exports = { nextExtensionVersion } | ||
|
||
if (require.main === module) { | ||
const args = process.argv.slice(2) | ||
const version = nextExtensionVersion({ | ||
prismaVersion: args[0], | ||
extensionVersion: args[1], | ||
}) | ||
console.log(version) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
const { expect } = require('chai') | ||
|
||
const { nextExtensionVersion } = require('./extension-version') | ||
|
||
describe('next extension version', () => { | ||
it('it should work with stable channel and current version to new version schema', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.0-beta.3', | ||
extensionVersion: '0.0.35', | ||
}), | ||
).to.eq('0.0.3') | ||
}) | ||
|
||
it('it should work with stable channel and extension only push', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.0-beta.3', | ||
extensionVersion: '0.0.3', | ||
}), | ||
).to.eq('0.0.3.1') | ||
}) | ||
|
||
it('it should work with stable channel and new prisma version', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.0-beta.4', | ||
extensionVersion: '0.0.3', | ||
}), | ||
).to.eq('0.0.4') | ||
}) | ||
|
||
it('it should work with stable channel and new prisma version after an extension only publish', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.0-beta.4', | ||
extensionVersion: '0.0.3.1', | ||
}), | ||
).to.eq('0.0.4') | ||
}) | ||
|
||
it('it should work with unstable channel and current version to new version schema', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.0-alpha.1149', | ||
extensionVersion: '0.0.38', | ||
}), | ||
).to.eq('0.0.1149') | ||
}) | ||
|
||
it('it should work with unstable channel and extension only push', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.0-alpha.1149', | ||
extensionVersion: '0.0.1149', | ||
}), | ||
).to.eq('0.0.1149.1') | ||
}) | ||
|
||
it('it should work with unstable channel and new prisma version', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.0-alpha.1150', | ||
extensionVersion: '0.0.1149', | ||
}), | ||
).to.eq('0.0.1150') | ||
}) | ||
|
||
it('it should work with unstable channel and new prisma version after an extension only publish', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.0-alpha.1150', | ||
extensionVersion: '0.0.1149.1', | ||
}), | ||
).to.eq('0.0.1150') | ||
}) | ||
|
||
it('it should work with stable channel after the ga versioning scheme and current version to new version schema', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.1', | ||
extensionVersion: '0.0.3', | ||
}), | ||
).to.eq('2.0.1') | ||
}) | ||
|
||
it('it should work with stable channel after the ga versioning scheme and extension only push', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.1', | ||
extensionVersion: '0.0.3.1', | ||
}), | ||
).to.eq('2.0.1') | ||
}) | ||
|
||
it('it should work with stable channel after the ga versioning scheme and new prisma version', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.2', | ||
extensionVersion: '2.0.1', | ||
}), | ||
).to.eq('2.0.2') | ||
}) | ||
|
||
it('it should work with stable channel after the ga versioning scheme and new prisma version after an extension only publish', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.2', | ||
extensionVersion: '2.0.1.1', | ||
}), | ||
).to.eq('2.0.2') | ||
}) | ||
|
||
it('it should work with unstable channel after the ga versioning scheme and current version to new version schema', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.1-dev.1', | ||
extensionVersion: '0.0.1150', | ||
}), | ||
).to.eq('0.1.1') | ||
}) | ||
|
||
it('it should work with unstable channel after the ga versioning scheme and extension only push', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.1-dev.1', | ||
extensionVersion: '0.1.1', | ||
}), | ||
).to.eq('0.1.1.1') | ||
}) | ||
|
||
it('it should work with unstable channel after the ga versioning scheme and new prisma version', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.1-dev.2', | ||
extensionVersion: '0.1.1', | ||
}), | ||
).to.eq('0.1.2') | ||
}) | ||
|
||
it('it should work with unstable channel after the ga versioning scheme and new prisma version after an extension only publish', () => { | ||
expect( | ||
nextExtensionVersion({ | ||
prismaVersion: '2.0.1-dev.2', | ||
extensionVersion: '0.1.1.1', | ||
}), | ||
).to.eq('0.1.2') | ||
}) | ||
}) |