本文整理匯總了TypeScript中klaw.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: writeFile
return new Promise<void>((resolve, reject) => {
klaw(srcDir)
.on('data', async (item: klaw.Item) => {
if (item.path.endsWith('.ts')) {
try {
let fileContent = await readFile(item.path);
await writeFile(
item.path,
prettier.format(fileContent.toString(), {
parser: 'typescript',
singleQuote: true,
bracketSpacing: false,
trailingComma: 'all',
semi: true,
}),
);
log(`Format the source code successfully:${item.path}`);
} catch (err) {
log(`Failed to format the source code:${item.path} ${err}`);
console.warn(
`Failed to format the source code:${item.path} ${err}`,
);
reject(err);
}
}
})
.on('end', () => {
resolve();
});
});
示例2: Promise
return new Promise((resolve, reject) => {
var klaw: any = require('klaw');
var members: forceCode.IWorkspaceMember[] = []; // files, directories, symlinks, etc
klaw(vscode.window.forceCode.workspaceRoot)
.on('data', function (item) {
// Check to see if the file represents an actual member...
if (item.stats.isFile()) {
var metadataFileProperties: jsforce.IMetadataFileProperties[] = getMembersFor(item);
if (metadataFileProperties.length) {
var workspaceMember: forceCode.IWorkspaceMember = {
name: metadataFileProperties[0].fullName,
path: item.path,
memberInfo: metadataFileProperties[0],
};
members.push(workspaceMember);
}
}
})
.on('end', function () {
resolve(members);
// console.dir(items) // => [ ... array of files]
});
});
示例3: readFile
.then(rstat => {
if (rstat.isFile()) {
_createInlineTemplate({
name: name,
options: options,
parameters: parameters,
path: inputPath,
})
.then(t => {
res({ Template: t.build() });
})
.catch(e => {
rej(e);
});
} else if (rstat.isDirectory()) {
const zip = new jszip();
const files: Array<string> = [];
klaw(inputPath)
.on('data', ({ path: location, stats }) => {
if (stats.isFile()) {
files.push(location);
}
})
.on('end', () => {
if (
files.length === 1 &&
relative(inputPath, files[0]) === 'index.js'
) {
_createInlineTemplate({
name: name,
options: options,
parameters: parameters,
path: files[0],
})
.then(t => {
res({ Template: t.build() });
})
.catch(e => {
rej(e);
});
} else {
bmap(files, file => {
return readFile(file).then(contents => {
const relPath = relative(inputPath, file);
zip.file(relPath, contents);
});
}).then(results => {
zip.generateAsync({ type: 'nodebuffer' }).then(blob => {
// writeFileSync('final.zip', blob);
let t = Template()
.add(
Parameter(`${name}S3BucketParam`, { Type: 'String' })
)
.add(Parameter(`${name}S3KeyParam`, { Type: 'String' }));
if (parameters && parameters.length > 0) {
parameters.map(p => {
t = t.add(Parameter(`${name}${p}`, { Type: 'String' }));
});
}
t = t
.add(
Lambda.Function(name, {
Code: {
S3Bucket: Ref(`${name}S3BucketParam`),
S3Key: Ref(`${name}S3KeyParam`),
},
FunctionName: options.FunctionName,
Handler: options.Handler,
MemorySize: options.MemorySize,
Role:
parameters && parameters.includes('Role')
? Ref(`${name}Role`)
: options.Role,
Runtime: options.Runtime,
Timeout: options.Timeout,
// Tags: options.Tags ? options.Tags.length > 0 : null
})
)
.putOut(name, `${name}LambdaFunctionOutput`);
res({
Template: t.build(),
Zip: blob,
});
});
});
}
});
}
})
示例4: Promise
return new Promise((res, rej) => {
const zip = new jszip();
const files: Array<string> = [];
klaw(inputPath)
.on('data', ({ path: location, stats }) => {
if (stats.isFile()) {
files.push(location);
}
})
.on('end', () => {
bmap(files, file => {
return readFile(file).then(contents => {
const relPath = relative(inputPath, file);
zip.file(relPath, contents);
});
}).then(results => {
zip.generateAsync({ type: 'nodebuffer' }).then(blob => {
// writeFileSync('final.zip', blob);
let t = Template();
let s3BucketVal = Ref(`${name}S3BucketParam`);
let s3KeyVal = Ref(`${name}S3KeyParam`);
if (bucket) {
s3BucketVal = bucket;
t = t.add(Parameter(`${name}S3BucketParam`, { Type: 'String' }));
}
if (key) {
s3KeyVal = key;
t = t.add(Parameter(`${name}S3KeyParam`, { Type: 'String' }));
}
if (parameters && parameters.length > 0) {
parameters.map(p => {
t = t.add(Parameter(`${name}${p}`, { Type: 'String' }));
});
}
const props: any = {
Code: {
S3Bucket: s3BucketVal,
S3Key: s3KeyVal,
},
FunctionName: options.FunctionName,
Handler: options.Handler,
MemorySize: options.MemorySize,
Role:
parameters && parameters.includes('Role')
? Ref(`${name}Role`)
: options.Role,
Runtime: options.Runtime,
Timeout: options.Timeout,
// Tags: options.Tags ? options.Tags.length > 0 : null
};
if (Object.keys(options.Environment).length > 0) {
props.Environment = options.Environment;
}
if (options.Tags.length > 0) {
props.Tags = options.Tags;
}
const fn = Lambda.Function(name, props);
res({
FunctionResource: fn,
Zip: blob,
});
});
});
});
});