mirror of https://github.com/AMT-Cheif/drift.git
Host api docs on moor website
This commit is contained in:
parent
02d949d5b9
commit
40a1c91e25
|
@ -1,4 +1,4 @@
|
||||||
//@dart=2.9
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:build_runner_core/build_runner_core.dart';
|
import 'package:build_runner_core/build_runner_core.dart';
|
||||||
|
@ -10,8 +10,37 @@ import 'package:path/path.dart' as p;
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
final isReleaseEnv = Platform.environment['IS_RELEASE'];
|
final isReleaseEnv = Platform.environment['IS_RELEASE'];
|
||||||
print('Is release build: $isReleaseEnv');
|
print('Is release build: $isReleaseEnv');
|
||||||
|
|
||||||
final isRelease = isReleaseEnv == 'true';
|
final isRelease = isReleaseEnv == 'true';
|
||||||
|
|
||||||
|
final output = Directory('deploy');
|
||||||
|
if (output.existsSync()) {
|
||||||
|
output.deleteSync(recursive: true);
|
||||||
|
}
|
||||||
|
output.createSync();
|
||||||
|
|
||||||
|
await Future.wait([
|
||||||
|
_runBuildAndCopyFiles(output, isRelease),
|
||||||
|
_createApiDocumentation(output),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _waitForProcess(Process p, String name) async {
|
||||||
|
Future<void> forward(Stream<List<int>> source, IOSink out) {
|
||||||
|
return source
|
||||||
|
.transform(utf8.decoder)
|
||||||
|
.transform(const LineSplitter())
|
||||||
|
.forEach((line) => out.writeln('$name: $line'));
|
||||||
|
}
|
||||||
|
|
||||||
|
await Future.wait([
|
||||||
|
forward(p.stdout, stdout),
|
||||||
|
forward(p.stderr, stderr),
|
||||||
|
]);
|
||||||
|
await stdout.flush();
|
||||||
|
await stderr.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _runBuildAndCopyFiles(Directory output, bool isRelease) async {
|
||||||
final buildArgs = [
|
final buildArgs = [
|
||||||
'run',
|
'run',
|
||||||
'build_runner',
|
'build_runner',
|
||||||
|
@ -19,9 +48,8 @@ Future<void> main() async {
|
||||||
'--release',
|
'--release',
|
||||||
if (isRelease) '--config=deploy',
|
if (isRelease) '--config=deploy',
|
||||||
];
|
];
|
||||||
final build = await Process.start('dart', buildArgs,
|
final build = await Process.start('dart', buildArgs);
|
||||||
mode: ProcessStartMode.inheritStdio);
|
await _waitForProcess(build, 'build');
|
||||||
await build.exitCode;
|
|
||||||
|
|
||||||
print('Copying generated sources into deploy/');
|
print('Copying generated sources into deploy/');
|
||||||
// Advanced build magic because --output creates weird files that we don't
|
// Advanced build magic because --output creates weird files that we don't
|
||||||
|
@ -32,12 +60,6 @@ Future<void> main() async {
|
||||||
AssetGraph.deserialize(await (await _findAssetGraph()).readAsBytes());
|
AssetGraph.deserialize(await (await _findAssetGraph()).readAsBytes());
|
||||||
final reader = BuildCacheReader(env.reader, assets, graph.root.name);
|
final reader = BuildCacheReader(env.reader, assets, graph.root.name);
|
||||||
|
|
||||||
final output = Directory('deploy');
|
|
||||||
if (output.existsSync()) {
|
|
||||||
output.deleteSync(recursive: true);
|
|
||||||
}
|
|
||||||
output.createSync();
|
|
||||||
|
|
||||||
final idsToRead = assets.allNodes
|
final idsToRead = assets.allNodes
|
||||||
.where((node) => !_shouldSkipNode(node, graph))
|
.where((node) => !_shouldSkipNode(node, graph))
|
||||||
.map((e) => e.id);
|
.map((e) => e.id);
|
||||||
|
@ -49,6 +71,39 @@ Future<void> main() async {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _createApiDocumentation(Directory output) async {
|
||||||
|
final gitRevResult =
|
||||||
|
await Process.run('git', ['rev-parse', 'HEAD'], stdoutEncoding: utf8);
|
||||||
|
final rev = (gitRevResult.stdout as String).replaceAll('\n', '');
|
||||||
|
|
||||||
|
// Dartdoc supports %r% for the revision, %f% for the file name and %l% for
|
||||||
|
// the line number.
|
||||||
|
const source = 'https://github.com/simolus3/moor/blob/%r%/%f%/#L%l%';
|
||||||
|
final dartDoc = await Process.start(
|
||||||
|
'dartdoc',
|
||||||
|
[
|
||||||
|
'--rel-canonical-prefix=https://pub.dev/documentation/moor/latest',
|
||||||
|
'--link-to-source-revision=$rev',
|
||||||
|
'--link-to-source-root=..',
|
||||||
|
'--link-to-source-uri-template=$source',
|
||||||
|
],
|
||||||
|
workingDirectory: '../moor',
|
||||||
|
);
|
||||||
|
await _waitForProcess(dartDoc, 'dartdoc');
|
||||||
|
|
||||||
|
final docOutput = Directory('../moor/doc/api');
|
||||||
|
final targetForDocs = p.join(output.path, 'api');
|
||||||
|
|
||||||
|
await for (final file in docOutput.list(recursive: true)) {
|
||||||
|
if (file is! File) continue;
|
||||||
|
|
||||||
|
final target =
|
||||||
|
p.join(targetForDocs, p.relative(file.path, from: docOutput.path));
|
||||||
|
File(target).parent.createSync(recursive: true);
|
||||||
|
await file.copy(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<File> _findAssetGraph() {
|
Future<File> _findAssetGraph() {
|
||||||
final dir = Directory('.dart_tool/build');
|
final dir = Directory('.dart_tool/build');
|
||||||
return dir.list().firstWhere((e) {
|
return dir.list().firstWhere((e) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ site:
|
||||||
- name: "GitHub"
|
- name: "GitHub"
|
||||||
url: "https://github.com/simolus3/moor/"
|
url: "https://github.com/simolus3/moor/"
|
||||||
- name: "API docs"
|
- name: "API docs"
|
||||||
url: "https://pub.dev/documentation/moor/latest/"
|
url: "/api/"
|
||||||
|
|
||||||
environments:
|
environments:
|
||||||
dev:
|
dev:
|
||||||
|
|
Loading…
Reference in New Issue