(async () => { let result: string[]; result = await globby('*.tmp'); result = await globby(['a.tmp', '*.tmp', '!{c,d,e}.tmp']); result = globby.sync('*.tmp'); result = globby.sync(['a.tmp', '*.tmp', '!{c,d,e}.tmp']); result = await globby('*.tmp', Object.freeze({ignore: Object.freeze([])})); result = globby.sync('*.tmp', Object.freeze({ignore: Object.freeze([])})); })();
export async function enumerateInstalledCommands(config: CliConfig): Promise<string[]> { const { searchPrefixes } = config; const globPaths = searchPrefixes.reduce((globPaths: string[], key) => { return globPaths.concat(config.searchPaths.map((depPath) => pathResolve(depPath, `${key}-*`))); }, []); return globby(globPaths, { ignore: '**/*.{map,d.ts}' }); }
export default async function getSchema() { const files = await globby('typeDefs/*.graphql', { cwd: __dirname }) const typeDefs = await Promise.all( files.map(async file => { const buffer = await readFileAsync(path.join(__dirname, file)) return buffer.toString() }) ) return makeExecutableSchema({ typeDefs, resolvers }) }
export async function analyze( root: string, inputs: string[]): Promise<AnalysisFormat|undefined> { const analyzer = new Analyzer({ urlLoader: new FSUrlLoader(root), urlResolver: new PackageUrlResolver(), }); const isInTests = /(\b|\/|\\)(test)(\/|\\)/; const isNotTest = (f: Feature) => f.sourceRange != null && !isInTests.test(f.sourceRange.file); if (inputs == null || inputs.length === 0) { const _package = await analyzer.analyzePackage(); return generateAnalysis(_package, '', isNotTest); } else { const analysis = await analyzer.analyze(await globby(inputs)); return generateAnalysis(analysis, '', isNotTest); } }
export default async function resource(compiler: NexeCompiler, next: () => Promise<void>) { const resources = compiler.resources if (!compiler.options.resources.length) { return next() } const step = compiler.log.step('Bundling Resources...') let count = 0 await each(globs(compiler.options.resources), async file => { if (await isDirectoryAsync(file)) { return } count++ step.log(`Including file: ${file}`) const contents = await readFileAsync(file) compiler.addResource(file, contents) }) step.log(`Included ${count} file(s). ${(resources.bundle.byteLength / 1e6).toFixed(3)} MB`) return next() }
(async function run() { const root = path.resolve(__dirname, '..'); const resultsPath = path.resolve(root, './src/data/results.json'); const imageNames = await globby([`*.+(png|gif|jpg|jpeg)`], { cwd: `${root}/images/photoshop` }); const toolNames = Object.keys(getEmptyResults()) as ToolName[]; const results: IImage[] = []; for (const imageName of imageNames) { const extension = getType(imageName); const type = imageName.split('_')[0]; const originalSize = await getSize({ toolName: 'photoshop', imageName }); const worstSsimPossible = extension === 'GIF' ? 1 : await getSsim({ toolName: 'worst', imageName }); const memo: IResultMemo = { bestScore: 0, highestSaving: 0, image: { extension, name: imageName, results: getEmptyResults(), type }, leastLoss: 0 }; await Promise.all( toolNames.map(async (toolName) => { if (await exists({ toolName, imageName })) { const result = await getResult(originalSize, worstSsimPossible, { toolName, imageName }); memo.image.results[toolName] = result; memo.bestScore = largest(result.score, memo.bestScore); memo.highestSaving = largest(result.sizeSaving, memo.highestSaving); memo.leastLoss = largest(result.ssim, memo.leastLoss); } }) ); console.log(imageName); for (const toolName of toolNames) { const result = memo.image.results[toolName]; if (result !== null) { result.isBestScore = result.score === memo.bestScore; result.isHighestSaving = result.sizeSaving === memo.highestSaving; result.isLeastLoss = result.sizeSaving > 0 && result.ssim === memo.leastLoss; results.push(memo.image); console.log( [ toolName, result.isBestScore ? ' Best Score' : '', result.isHighestSaving ? ' Highest Saving' : '', result.isLeastLoss ? ' Least Loss' : '' ].join('') ); } else { console.log(toolName, 'has no result'); } } } const previousResults = await readJson(resultsPath); await writeJson(resultsPath, results, { spaces: 2 }); console.log(diffString(previousResults, results)); })();
export async function enumerateBuiltInCommands(config: CliConfig): Promise<string[]> { const builtInCommandParentDirGlob = join(config.builtInCommandLocation, '/*.js'); return globby(builtInCommandParentDirGlob, { ignore: '**/*.{map,d.ts}' }); }