load static method
Finds the project that contains start.
The config is the dpk.yaml at the workspace root. When the workspace
root has none, a standalone dpk.yaml in the current package is used.
The current package's own dpk.yaml can add or override scripts.
Implementation
static Project load(String start, {String? cacheDirectoryOverride}) {
if (!Directory(start).existsSync()) {
throw ProjectException('Directory "$start" does not exist.');
}
final workspace = Workspace.discover(start);
if (workspace == null) {
throw ProjectException(
'No pubspec.yaml found in ${displayPath(canonicalPath(start))} or any '
'parent directory.',
);
}
final rootConfig = p.join(workspace.root.path, kConfigFileName);
final currentConfig = p.join(workspace.current.path, kConfigFileName);
final rootHasConfig = File(rootConfig).existsSync();
final configPath = rootHasConfig
? rootConfig
: (File(currentConfig).existsSync() ? currentConfig : null);
if (configPath == null) {
throw ProjectException(
'No $kConfigFileName found in ${displayPath(workspace.root.path)}. '
'Run "dpk init" to create one.',
);
}
final displayConfig = displayPath(configPath);
final reader = ConfigReader(
loadConfigMap(File(configPath).readAsStringSync(), file: displayConfig),
file: displayConfig,
);
_checkVersion(reader);
final config = DpkConfig.parse(reader);
final scripts = {...config.scripts};
final warnings = [...config.warnings];
if (rootHasConfig &&
workspace.current != workspace.root &&
File(currentConfig).existsSync()) {
final displayPackageConfig = displayPath(currentConfig);
final packageReader = ConfigReader(
loadConfigMap(
File(currentConfig).readAsStringSync(),
file: displayPackageConfig,
),
file: displayPackageConfig,
);
if (packageReader.has('version')) {
_checkVersion(packageReader);
}
final package = parsePackageConfig(
packageReader,
rootConfigPath: displayConfig,
);
scripts.addAll(package.scripts);
warnings.addAll(package.warnings);
}
Script.checkReferences(scripts, file: displayConfig);
return Project(
workspace: workspace,
configPath: configPath,
config: config,
scripts: scripts,
warnings: warnings,
cacheDirectoryOverride: cacheDirectoryOverride,
);
}