-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop: Merge
@techor/version
into techor
- Loading branch information
Showing
210 changed files
with
116 additions
and
346 deletions.
There are no files selected for viewing
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
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,97 @@ | ||
import type { Command } from 'commander' | ||
import { explorePathsSync } from '@techor/glob' | ||
import path from 'path' | ||
import log, { paint } from '@techor/log' | ||
import { readJSONFileSync, writeFileSync } from '@techor/fs' | ||
import { readPNPMWorkspaces, readWorkspaces, explorePackageManager } from '@techor/npm' | ||
|
||
export default (program: Command) => program.command('version <version>') | ||
.description('Bump to specific version for workspace\'s packages') | ||
.option('-p, --prefix <symbol>', 'Version prefix `^`, `~`, `>`, `>=`, `<`, `<=` ', '^') | ||
.option('-w, --workspaces <paths>', 'Specific your workspaces') | ||
.option('-ls, --list', 'List current bumpable dependency tree in workspaces', false) | ||
.action(async function (version, options) { | ||
if (!options.workspaces) { | ||
const packageManager = explorePackageManager() | ||
switch (packageManager) { | ||
case 'pnpm': | ||
options.workspaces = readPNPMWorkspaces() | ||
break | ||
case 'npm': | ||
options.workspaces = readWorkspaces() | ||
break | ||
} | ||
} | ||
if (!options.workspaces?.length) { | ||
log.x`workspaces is not defined in package.json` | ||
} | ||
const packagesOfPath = {} | ||
const packagesOfName = {} | ||
const workspacePackagePaths = options.workspaces.map((eachWorkspace) => path.join(eachWorkspace, '*package.json')) | ||
const resolveVersion = (eachVersion: string) => { | ||
if (eachVersion.startsWith('workspace:')) { | ||
return eachVersion.replace('workspace:', '') + version | ||
} else if (eachVersion === '') { | ||
return options.prefix + version | ||
} | ||
} | ||
const updateDependencies = (eachDependencies) => { | ||
for (const dependencyName in eachDependencies) { | ||
if (dependencyName in packagesOfName) { | ||
const dependencyVersion = eachDependencies[dependencyName] | ||
const resolvedVersion = resolveVersion(dependencyVersion) | ||
if (resolvedVersion) { | ||
eachDependencies[dependencyName] = resolvedVersion | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Read package.json by workspaces | ||
for (const eachPackagePath of explorePathsSync(workspacePackagePaths)) { | ||
const eachPackage = readJSONFileSync(path.resolve(eachPackagePath)) | ||
// Prevent version bumps of private package | ||
packagesOfPath[eachPackagePath] = eachPackage | ||
packagesOfName[eachPackage.name] = eachPackage | ||
// Bump to next verion | ||
eachPackage.version = version | ||
} | ||
|
||
for (const eachPackagePath in packagesOfPath) { | ||
const eachPackage = packagesOfPath[eachPackagePath] | ||
const { dependencies, devDependencies, peerDependencies } = packagesOfPath[eachPackagePath] | ||
dependencies && updateDependencies(dependencies) | ||
devDependencies && updateDependencies(devDependencies) | ||
peerDependencies && updateDependencies(peerDependencies) | ||
if (!options.list) { | ||
writeFileSync(eachPackagePath, eachPackage) | ||
} | ||
} | ||
|
||
const workspaceDepsTree = {} | ||
for (const name in packagesOfName) { | ||
const { dependencies, peerDependencies, devDependencies } = packagesOfName[name] | ||
const workspacePackage: any = workspaceDepsTree[paint('**' + name + '**')] = {} | ||
const analyzeDeps = (eachDeps, key: string) => { | ||
if (eachDeps) { | ||
workspacePackage[key] = {} | ||
for (const dependencyName in eachDeps) { | ||
if (dependencyName in packagesOfName) { | ||
const eachDependencyVersion = eachDeps[dependencyName] | ||
workspacePackage[key][paint('**' + dependencyName + '**')] = eachDependencyVersion || null | ||
} | ||
} | ||
} | ||
} | ||
analyzeDeps(dependencies, 'dependencies') | ||
analyzeDeps(peerDependencies, 'peerDependencies') | ||
analyzeDeps(devDependencies, 'devDependencies') | ||
/* 防止沒有印出空 {} 的項目 */ | ||
if (!Object.keys(workspaceDepsTree[paint('**' + name + '**')]).length) { | ||
workspaceDepsTree[paint('**' + name + '**')] = null | ||
} | ||
} | ||
log`📦` | ||
log.tree(workspaceDepsTree) | ||
log.success`bump version to ${version} for ${Object.keys(packagesOfName).length} packages in all workspace` | ||
}) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
packages/version/tests/master/sources/packages/renderer/jest.config.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.