Skip to content

Commit

Permalink
Unify configFile
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Apr 16, 2024
1 parent 53ab489 commit c24e422
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
12 changes: 6 additions & 6 deletions pkgs/native_assets_cli/lib/src/model/build_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ part of '../api/build_config.dart';

final class BuildConfigImpl extends HookConfigImpl implements BuildConfig {
@override
Hook get hook => Hook.build;

@override
//TODO: Should be removed once migration to `hook/` is complete.
Uri get script {
final hookScript =
packageRoot.resolve('hook/').resolve(Hook.build.scriptName);
final hookScript = packageRoot.resolve('hook/').resolve(hook.scriptName);
if (File.fromUri(hookScript).existsSync()) {
return hookScript;
} else {
return packageRoot.resolve(Hook.build.scriptName);
return packageRoot.resolve(hook.scriptName);
}
}

@override
String get outputName =>
version > Version(1, 1, 0) ? 'build_output.json' : 'build_output.yaml';

@override
Uri get configFile => outputDirectory.resolve('../config.json');

/// The folder in which all output and intermediate artifacts should be
/// placed.
@override
Expand Down
12 changes: 7 additions & 5 deletions pkgs/native_assets_cli/lib/src/model/hook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

/// The two types of scripts which are hooked into the compilation process.
///
/// The `build.dart` script runs before, and the `link.dart` script after
/// compilation.
/// The `build.dart` hook runs before, and the `link.dart` hook after
/// compilation. This enum holds static information about these hooks.
enum Hook {
link('link'),
build('build');
link('link', 'link_config'),
build('build', 'config');

final String _scriptName;
final String _configName;

String get scriptName => '$_scriptName.dart';
String get configName => '$_configName.json';

const Hook(this._scriptName);
const Hook(this._scriptName, this._configName);
}
10 changes: 8 additions & 2 deletions pkgs/native_assets_cli/lib/src/model/hook_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@

import 'package:pub_semver/pub_semver.dart';

import 'hook.dart';

abstract class HookConfigImpl {
Uri get configFile;
Hook get hook;

Uri get configFile => outputDirectory.resolve('../${hook.configName}');

Uri get outputFile => outputDirectory.resolve(outputName);

Uri get outputDirectory;

Uri get script;
// This is currently overriden by [BuildConfig], do account for older versions
// still using a top-level build.dart.
Uri get script => packageRoot.resolve('hook/').resolve(hook.scriptName);

String toJsonString();

Expand Down
9 changes: 3 additions & 6 deletions pkgs/native_assets_cli/lib/src/model/link_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ part of '../api/link_config.dart';
/// [assets] from the build step, and the [resources] generated during the
/// kernel compilation.
class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
@override
Hook get hook => Hook.link;

@override
final List<AssetImpl> assets;

Expand All @@ -28,9 +31,6 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
}) : _buildConfig = buildConfig,
resources = fromIdentifiers(resourceIdentifiers);

@override
Uri get configFile => outputDirectory.resolve('../link_config.json');

@override
Uri get outputDirectory => _buildConfig.outputDirectory;

Expand All @@ -43,9 +43,6 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
@override
Uri get packageRoot => _buildConfig.packageRoot;

@override
Uri get script => packageRoot.resolve('hook/').resolve(Hook.link.scriptName);

@override
String toJsonString() =>
const JsonEncoder.withIndent(' ').convert(_args.toJson());
Expand Down

0 comments on commit c24e422

Please sign in to comment.