-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
feat: umi cache #10730
Open
txp1035
wants to merge
34
commits into
umijs:master
Choose a base branch
from
txp-fork:umicache
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: umi cache #10730
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
153748c
feat: init
txp1035 8135f93
chore: init
txp1035 a3a90aa
chore: init
txp1035 d01a19b
feat: clean
txp1035 81469c1
feat: ls and examples
txp1035 f0a3669
chore: lock
txp1035 8cf04c3
chore: details
txp1035 a392ff9
chore: the same parameter as npm
txp1035 bd6a7fb
chore: depth
txp1035 25c8c21
chore: Compatible 0
txp1035 c0f233e
chore: style
txp1035 734ca60
chore: tree
txp1035 7f807b1
fix: ci
txp1035 96a67aa
fix: ci
txp1035 266c0b4
perf: tree
txp1035 ad05fe5
fix: first of tree
txp1035 6fb7ca1
fix: undefined show
txp1035 ac42733
Update packages/preset-umi/src/commands/cache.ts
txp1035 1babcf2
Update packages/preset-umi/src/commands/cache.ts
txp1035 7847ca6
chore: for cr
txp1035 503a523
chore: npm
txp1035 f9d8214
fix: ci
txp1035 34b2b16
feat: mb
txp1035 4742c12
chore(merge): Merge branch 'master' into umicache
txp1035 0ea392f
chore(merge): Merge branch 'master' into umicache
txp1035 e78678b
chore: pkg
txp1035 dc227dd
fix: example
txp1035 c6ce07c
perf: name
txp1035 ad0f247
chore: idr
txp1035 70cba46
chore: api
txp1035 61047c6
chore: compiled
txp1035 02b4f21
perf: yc
txp1035 507b06a
chore: npm
txp1035 8ea3f9d
chore: docs
txp1035 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2012-2018 Luke Plaster <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,28 @@ | ||
// Type definitions for treeify 1.0 | ||
// Project: https://github.com/notatestuser/treeify | ||
// Definitions by: Mike North <https://github.com/mike-north> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 2.1 | ||
|
||
export interface TreeObject { | ||
[k: string]: TreeValue; | ||
} | ||
export type TreeValue = string | TreeObject; | ||
|
||
export function asTree( | ||
treeObj: TreeObject, | ||
showValues: boolean, | ||
hideFunctions: boolean | ||
): string; | ||
|
||
export function asLines( | ||
treeObj: TreeObject, | ||
showValues: boolean, | ||
lineCallback: (line: string) => void | ||
): string; | ||
export function asLines( | ||
treeObj: TreeObject, | ||
showValues: boolean, | ||
hideFunctions: boolean, | ||
lineCallback: (line: string) => void | ||
): string; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"treeify","version":"1.1.0","author":"Luke Plaster <[email protected]>","license":"MIT"} |
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,106 @@ | ||
import { fsExtra, logger } from '@umijs/utils'; | ||
import { join, relative } from 'path'; | ||
import treeify, { type TreeObject } from '../../compiled/treeify'; | ||
import { IApi } from '../types'; | ||
|
||
const details = ` | ||
umi cache | ||
# clear cache directory | ||
umi cache clean | ||
# display directory information, --depth is the number of directory levels | ||
umi cache ls [--depth <depth>] | ||
`; | ||
|
||
export default (api: IApi) => { | ||
api.registerCommand({ | ||
name: 'cache', | ||
description: 'run the script commands, manage umi cache', | ||
details, | ||
configResolveMode: 'loose', | ||
fn: ({ args }) => { | ||
const absCachePath = join( | ||
api.cwd, | ||
api.config.cacheDirectoryPath || 'node_modules/.cache', | ||
); | ||
const position = relative(api.cwd, absCachePath); | ||
if (fsExtra.existsSync(absCachePath)) { | ||
if (args._[0] === 'clean') { | ||
fsExtra.removeSync(absCachePath); | ||
logger.ready(`[umi cache] cache directory is cleaned (${position})`); | ||
} else if (args._[0] === 'ls') { | ||
const depth: number = args.depth ?? 1; | ||
const dirObj = getDirectorySize({ | ||
dir: absCachePath, | ||
depth: depth + 1, | ||
}); | ||
const tree: Tree = {}; | ||
const str = `[${getSize(dirObj.size)}] ${position}`; | ||
tree[str] = dirObj.tree; | ||
logger.info( | ||
`[umi cache] dir info\n${treeify.asTree( | ||
tree as TreeObject, | ||
true, | ||
true, | ||
)}`, | ||
); | ||
} | ||
} else { | ||
logger.warn(`[umi cache] unknown command ${args._[0]}`); | ||
console.log(details); | ||
} | ||
}, | ||
}); | ||
}; | ||
|
||
type Tree = null | { [key: string]: null | Tree }; | ||
|
||
interface IGetDirectorySize { | ||
dir: string; | ||
depth?: number; | ||
current?: number; | ||
} | ||
function getDirectorySize({ dir, depth = 2, current = 1 }: IGetDirectorySize) { | ||
const obj: { | ||
size: number; | ||
tree: Tree; | ||
} = { | ||
size: 0, | ||
tree: null, | ||
}; | ||
const needCreateTree = current < depth; | ||
if (needCreateTree) { | ||
obj.tree = {}; | ||
} | ||
const files = fsExtra.readdirSync(dir); | ||
files.forEach((file) => { | ||
const filePath = join(dir, file); | ||
const stats = fsExtra.statSync(filePath); | ||
|
||
if (stats.isFile()) { | ||
const fileSize = Math.floor(stats.size / 1024); | ||
obj.size += fileSize; | ||
if (obj.tree) { | ||
obj.tree[`[${getSize(fileSize)}] ${file}`] = null; | ||
} | ||
} else { | ||
const objChild = getDirectorySize({ | ||
dir: filePath, | ||
current: current + 1, | ||
depth, | ||
}); | ||
if (obj.tree) { | ||
obj.tree[`[${getSize(objChild.size)}] ${file}`] = objChild.tree; | ||
} | ||
obj.size += objChild.size; | ||
} | ||
}); | ||
|
||
return obj; | ||
} | ||
|
||
function getSize(size: number) { | ||
if (size > 1024) { | ||
return `${(size / 1024).toFixed(2)} MB`; | ||
} | ||
return `${size} KB`; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
这里要不要顺便把 .umi 文件夹删除?临时文件严格来说也算是缓存文件?就顺便把 umi clean 命令做了?
@sorrycc cc