-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
π Add command to increase project version and implement version increment logic, Closes #94 #387
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,39 @@ | ||||||||||||
import { readFileSync, writeFileSync } from 'fs'; | ||||||||||||
import { join } from 'path'; | ||||||||||||
import { workspace } from 'vscode'; | ||||||||||||
|
||||||||||||
|
||||||||||||
export async function increaseVersion(versionType: 'major' | 'minor' | 'patch') { | ||||||||||||
const wsFolder = workspace.workspaceFolders?.[0]; | ||||||||||||
if (!wsFolder) { | ||||||||||||
throw new Error('Workspace folder not found'); | ||||||||||||
} | ||||||||||||
|
||||||||||||
const packageJsonPath = join(wsFolder.uri.fsPath, 'package.json'); | ||||||||||||
const packageSolutionPath = join(wsFolder.uri.fsPath, 'config/package-solution.json'); | ||||||||||||
Comment on lines
+7
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will not work when the SPFx project was created by TeamsToolkit. We should also support that case. We already have some parts in SPFx Toolkit that add this support and check. Like here vscode-viva/src/services/check/DebuggerCheck.ts Lines 37 to 41 in beaf740
|
||||||||||||
|
||||||||||||
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); | ||||||||||||
const packageSolution = JSON.parse(readFileSync(packageSolutionPath, 'utf8')); | ||||||||||||
|
||||||||||||
const newVersion = incrementVersion(packageJson.version, versionType); | ||||||||||||
packageJson.version = newVersion; | ||||||||||||
packageSolution.solution.version = `${newVersion}.0`; | ||||||||||||
|
||||||||||||
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); | ||||||||||||
writeFileSync(packageSolutionPath, JSON.stringify(packageSolution, null, 2)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
function incrementVersion(version: string, versionType: 'major' | 'minor' | 'patch'): string { | ||||||||||||
const [major, minor, patch] = version.split('.').map(Number); | ||||||||||||
|
||||||||||||
switch (versionType) { | ||||||||||||
case 'major': | ||||||||||||
return `${major + 1}.0.0`; | ||||||||||||
case 'minor': | ||||||||||||
return `${major}.${minor + 1}.0`; | ||||||||||||
case 'patch': | ||||||||||||
return `${major}.${minor}.${patch + 1}`; | ||||||||||||
default: | ||||||||||||
throw new Error('Invalid version type'); | ||||||||||||
} | ||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets pick a different icon. This one is already used in upgrade action which may be just confusing.
we may use any icon from this
https://microsoft.github.io/vscode-codicons/dist/codicon.html
what do you think about
fold-up
icon π€