fs-extra#statSync TypeScript Examples
The following examples show how to use
fs-extra#statSync.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From cli with MIT License | 7 votes |
docopy = async (
sourceDir: string,
targetDir: string,
paths: string[],
log?
) => {
const limit = plimit(20);
await Promise.all(
paths.map((path: string) => {
const source = join(sourceDir, path);
const target = join(targetDir, path);
if (existsSync(target)) {
const sourceStat = statSync(source);
const targetStat = statSync(target);
// source 修改时间小于目标文件 修改时间,则不拷贝
if (sourceStat.mtimeMs <= targetStat.mtimeMs) {
return;
}
}
if (log) {
log(path);
}
return limit(() => {
return new Promise(resolve => {
copy(source, target)
.then(resolve)
.catch(e => {
if (log) {
log(`Error!!! From '${source}' to '${target}'`, e);
}
resolve(void 0);
});
});
});
})
);
}
Example #2
Source File: code-loader.ts From malagu with MIT License | 6 votes |
protected async doLoad(codeDir: string, zip: JSZip, codeUri?: CodeUri) {
const files = readdirSync(codeDir);
for (const fileName of files) {
const fullPath = join(codeDir, fileName);
if (!codeUri?.include || !this.match(codeUri.include, fullPath)) {
if (codeUri?.exclude && this.match(codeUri.exclude, fullPath)) {
continue;
}
}
const file = statSync(fullPath);
if (file.isDirectory()) {
const dir = zip.folder(fileName);
if (dir) {
await this.doLoad(fullPath, dir, codeUri);
}
} else {
zip.file(fileName, readFileSync(fullPath), {
unixPermissions: '755'
});
}
}
}
Example #3
Source File: detector-filesystem.ts From malagu with MIT License | 5 votes |
protected async doIsFile(name: string): Promise<boolean> {
const stat = statSync(resolve(this.projectPath, name));
if (stat.isFile()) {
return true;
}
return false;
}
Example #4
Source File: fs.ts From DefinitelyTyped-tools with MIT License | 5 votes |
isDirectory(dirPath: string): boolean {
return statSync(this.getPath(dirPath)).isDirectory();
}
Example #5
Source File: index.ts From cli with MIT License | 5 votes |
async package() {
this.core.cli.log('Package artifact...');
// 跳过打包
if (this.options.skipZip) {
this.core.cli.log(' - Zip artifact skip');
if (this.core.service?.experimentalFeatures?.removeUselessFiles) {
this.core.cli.log(' - Experimental Feature RemoveUselessFiles');
await removeUselessFiles(this.midwayBuildPath);
}
return;
}
// 构建打包
const packageObj: any = this.core.service.package || {};
let file = join(this.servicePath, this.zipCodeDefaultName);
if (packageObj.artifact) {
if (isAbsolute(packageObj.artifact)) {
file = packageObj.artifact;
} else {
file = join(this.servicePath, packageObj.artifact);
}
}
this.setStore('artifactFile', file, true);
this.core.cli.log(` - Artifact file ${relative(this.servicePath, file)}`);
// 保证文件存在,然后删了文件,只留目录
await ensureFile(file);
await remove(file);
await this.makeZip(this.midwayBuildPath, file);
const stat = statSync(file);
this.setStore('zipSize', stat.size, true);
this.core.cli.log(
` - Zip size ${Number(stat.size / (1024 * 1024)).toFixed(2)}MB`
);
if (this.options.package) {
const to = resolve(this.servicePath, this.options.package);
await move(file, to);
}
}
Example #6
Source File: index.ts From nx-dotnet with MIT License | 5 votes |
export function directoryExists(filePath: string): boolean {
try {
return statSync(filePath).isDirectory();
} catch (err) {
return false;
}
}
Example #7
Source File: index.ts From nx-dotnet with MIT License | 5 votes |
export function fileExists(filePath: string): boolean {
try {
return statSync(filePath).isFile();
} catch (err) {
return false;
}
}
Example #8
Source File: index.ts From nx-dotnet with MIT License | 5 votes |
export function getSize(filePath: string): number {
return statSync(filePath).size;
}