stamper library
Build-time stamping for Flutter web output (uses dart:io; import it from
scripts and tools, not from app code).
import 'package:web_update_guard/stamper.dart';
final result = stampBuildDirectory('build/web');
print(result.info.buildId);
Classes
- BuildInfo
-
Metadata about one deployed build, as written to
version.jsonby the stamp CLI. - StampResult
- The outcome of stampBuildDirectory.
Constants
- buildIdMetaName → const String
-
The
nameof the<meta>tag the stamp CLI injects intoindex.html. -
cacheBustedScripts
→ const List<
String> - Entry-point file names whose references the stamp CLI cache-busts: the dart2js bundle, the loader scripts and the dart2wasm module + its JS support runtime.
Functions
-
buildTimeFromId(
String buildId) → DateTime? -
Extracts the UTC build time embedded in a build ID made by
formatBuildId, or
nullwhenbuildIdhas another format. -
cacheBustScripts(
String source, String buildId) → String -
Appends
?v=<buildId>to every script reference insource, replacing a previousvparameter and keeping any other parameters. -
formatBuildId(
String contentHash, DateTime builtAt) → String -
Formats a build ID from a hex
contentHashand the build time. -
injectBuildIdMeta(
String html, String buildId) → String -
Inserts the build-ID meta tag just before
</head>, removing any previous one first. -
removeBuildIdMeta(
String html) → String -
Removes every build-ID meta tag (and its line) from
html. -
removeCacheBust(
String source) → String -
Removes the
vparameter added by cacheBustScripts. -
runCli(
List< String> arguments, {StringSink? out, StringSink? err}) → int -
Runs the
web_update_guardcommand line witharguments, writing tooutanderr(stdout/stderr by default), and returns the exit code:0success,64usage error,1stamping failure. -
stampBootstrapJs(
String js, String buildId) → String -
Returns
js(aflutter_bootstrap.js) with script references cache-busted withbuildId. Idempotent. -
stampBuildDirectory(
String buildDir, {String? pubspecPath, String? appVersion, bool force = false, DateTime? now}) → StampResult -
Stamps a
flutter build weboutput directory in place. -
stampIndexHtml(
String html, String buildId) → String -
Returns
html(anindex.html) stamped withbuildId: meta tag injected and script references outside HTML comments cache-busted. Idempotent. -
unstampIndexHtml(
String html) → String -
Returns
html(anindex.html) with the meta tag and cache-busting removed — the form used for content hashing.
Exceptions / Errors
- StampException
- Thrown when a build directory cannot be stamped.