generatorInstalledPackages top-level property
已安装包生成器
Implementation
final FigGenerator generatorInstalledPackages = FigGenerator(
script: ['pnpm', 'ls'],
postProcess: (String out, [List<String>? tokens]) {
/**
* out 示例:
* ```
* Legend: production dependency, optional only, dev only
*
* /xxxx/xxxx/<package-name> (PRIVATE)
*
* dependencies:
* lodash 4.17.21
* foo link:packages/foo
*
* devDependencies:
* typescript 4.7.4
* ```
*/
if (out.contains('ERR_PNPM')) {
return <FigSuggestion>[];
}
final output = out
.split('\n')
.skip(3)
// 移除空行、"*dependencies:" 行、本地工作区包(例如:"foo":"workspace:*")
.where((item) =>
item.trim().isNotEmpty &&
!item.toLowerCase().contains('dependencies') &&
!item.contains('link:'))
.map((item) => item.replaceFirst(
RegExp(r'\s'), '@')) // typescript 4.7.4 -> typescript@4.7.4
.toList();
return output.map((pkg) {
return FigSuggestion(
name: pkg,
icon: 'fig://icon?type=package',
description: 'Installed package',
);
}).toList();
},
);