-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
144 additions
and
133 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
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,89 @@ | ||
// export * from './vsc'; // 兼容性文件需要单独导出使用 | ||
// export * from './vscodePath'; | ||
export * from './utils'; | ||
// export * from './vsHelp'; | ||
import sudo from '@vscode/sudo-prompt'; | ||
import lockfile from 'lockfile'; | ||
|
||
import { LOCK_PATH } from './constants'; | ||
|
||
export namespace utils { | ||
/** | ||
* 等待若干时间 | ||
* | ||
* @export | ||
* @param {number} [delay=0] | ||
* @return {*} | ||
*/ | ||
export function sleep(delay = 0) { | ||
return new Promise<void>(resolve => { | ||
setTimeout(resolve, delay); | ||
}); | ||
} | ||
|
||
/** | ||
* 添加文件锁 | ||
* | ||
* @export | ||
* @return {*} | ||
*/ | ||
export function lock() { | ||
return new Promise<void>((resolve, reject) => { | ||
lockfile.lock( | ||
LOCK_PATH, | ||
{ | ||
wait: 5000 // 应该能撑200的并发了,,,>_<#@! | ||
}, | ||
err => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
/** | ||
* 取消文件锁 | ||
* | ||
* @export | ||
* @return {*} | ||
*/ | ||
export function unlock() { | ||
return new Promise<void>((resolve, reject) => { | ||
lockfile.unlock(LOCK_PATH, err => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* 提权运行 | ||
* | ||
* @export | ||
* @param {string} cmd | ||
* @param {{ name?: string }} [options={}] | ||
* @return {*} {Promise<any>} | ||
*/ | ||
export function sudoExec(cmd: string, options: { name?: string } = {}): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
sudo.exec(cmd, options, (error?: Error, stdout?: string | Buffer, stderr?: string | Buffer) => { | ||
if (error) { | ||
reject(error); | ||
} | ||
resolve([stdout, stderr]); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* wrap with IIFE | ||
* | ||
* @export | ||
* @param {string} source | ||
* @return {*} | ||
*/ | ||
export function withIIFE(source: string) { | ||
return `;(function() { ${source} })();`; | ||
} | ||
} |
Oops, something went wrong.