From 8439770c73400fe284a036043e9b0607c3fd9e6e Mon Sep 17 00:00:00 2001 From: Rob Becker Date: Wed, 13 Oct 2021 20:36:04 -0600 Subject: [PATCH] prep 1.0.0 release --- CHANGELOG.md | 5 +++++ README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ bin/replace.dart | 29 +++++++++++++++++++++++++++++ pubspec.yaml | 21 +++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 CHANGELOG.md create mode 100644 bin/replace.dart create mode 100644 pubspec.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..62c3d6b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## [1.0.0] - 2021-10-13 +### Added +- Initial Version + +[1.0.0]: https://github.com/robrbecker/replace/releases/tag/1.0.0 \ No newline at end of file diff --git a/README.md b/README.md index 6b03cd5..c49e8f7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,46 @@ # replace Easy to use cross-platform regex replace command line util + +### Installing +`pub global activate replace` + +or more advanced install +- clone the project +- `pub get` +- `dart compile exe bin/replace.dart -o replace` +- Place the `replace` executable in your path + +### Running +`replace ` + +Regexes and globs are Dart style +Glob Syntax: https://pub.dev/packages/glob#syntax + +The replacement may contain references to the capture groups in regexp using a backslash followed by the group number. Backslashes not followed by a number return the character immediately following them. + +Examples: + +Simple strings and filename +`replace word newword filename` + +Regex and glob (w/ quotes around arguments) +`replace "(war).*(worlds)" "\1 of the monkeys" **` + +### Developing +This project uses cider to maintain the changelog. + +`cider log ` +type is one of: added, changed, deprecated, removed, fixed, security + +Examples: +``` +cider log changed 'New turbo V6 engine installed' +cider log added 'Support for rocket fuel and kerosene' +cider log fixed 'Wheels falling off sporadically' +``` + +When ready to release just run + +`cider bump ` (part is major, minor, patch) +and +`cider release` \ No newline at end of file diff --git a/bin/replace.dart b/bin/replace.dart new file mode 100644 index 0000000..923688a --- /dev/null +++ b/bin/replace.dart @@ -0,0 +1,29 @@ +import 'dart:io'; +import 'package:cli_script/cli_script.dart'; +import 'package:file/local.dart'; +import 'package:glob/glob.dart'; + +void main(List args) async { + var usage = 'replace '; + if (args.length < 3) { + print(usage); + return; + } + var regexp = args[0]; + var replacement = args[1]; + var glob = Glob(args[2]); + + var files = await glob + .listFileSystem(const LocalFileSystem()).toList(); + var transformer = replace(regexp, replacement, all: true, caseSensitive: false); + + for (var f in files) { + print(f.path); + var contents = (await asStream(f).transform(transformer).toList()).first; + File(f.path).writeAsStringSync(contents); + } +} + +Stream asStream(FileSystemEntity f) async* { + yield await File(f.path).readAsString(); +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..2d09881 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,21 @@ +name: replace +version: 1.0.0 +description: An easy to use cross-platform regex replace command line util. +repository: https://github.com/robrbecker/replace + +environment: + sdk: '>=2.12.0 <3.0.0' + +dependencies: + args: ^2.0.0 + cli_script: ^0.2.3 + file: ^6.0.0 + glob: ^2.0.0 + +executables: + replace: + +cider: + link_template: + tag: https://github.com/robrbecker/replace/releases/tag/%tag% + diff: https://github.com/robrbecker/replace/compare/%from%...%to% \ No newline at end of file