feat: add string extension, log level
This commit is contained in:
parent
fcf31a4a54
commit
908611d32d
@ -50,7 +50,9 @@ class FileSystemUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
Logger.info('Variable ${variable?.name} added in ${file.path}');
|
||||
Logger.debug(
|
||||
'Variable `${variable?.name}` replaced in ${file.path}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,6 +92,9 @@ class FileSystemUtils {
|
||||
|
||||
await File(newPath).create(recursive: true);
|
||||
await file.rename(newPath);
|
||||
Logger.debug(
|
||||
'${file.path} renamed with variable `${variable.name}`',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,10 @@ class Logger {
|
||||
stdout.writeln('${level.prefix} ${message.toString()}');
|
||||
}
|
||||
|
||||
static void debug(Object? message) {
|
||||
log(message, level: LogLevel.debug);
|
||||
}
|
||||
|
||||
static void info(Object? message) {
|
||||
log(message);
|
||||
}
|
||||
|
@ -80,9 +80,6 @@ description: $description
|
||||
|
||||
version: $version
|
||||
|
||||
environment:
|
||||
mason: ">=0.1.0-dev.26 <0.1.0"
|
||||
|
||||
''';
|
||||
|
||||
if (variables?.isNotEmpty ?? false) {
|
||||
|
@ -15,6 +15,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
enum LogLevel {
|
||||
debug('💡'),
|
||||
info('🍺'),
|
||||
success('✅'),
|
||||
error('❌');
|
||||
|
@ -1,16 +1,16 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
@ -25,7 +25,9 @@ enum VariableStringSyntax {
|
||||
paramCase('param_case', 'paramCase'),
|
||||
sentenceCase('sentence_case', 'sentenceCase'),
|
||||
titleCase('title_case', 'titleCase'),
|
||||
upperCase('upper_case', 'upperCase');
|
||||
upperCase('upper_case', 'upperCase'),
|
||||
pathCase('path_case', 'pathCase'),
|
||||
mustacheCase('mustache_case', 'mustacheCase');
|
||||
|
||||
final String mapKey;
|
||||
final String id;
|
||||
|
@ -29,6 +29,8 @@ extension StringExtension on String {
|
||||
'title_case': title(),
|
||||
'upper_case': upper(),
|
||||
'snake_case': snake(),
|
||||
'mustache_case': mustache(),
|
||||
'path_case': path(),
|
||||
};
|
||||
|
||||
/// ```dart
|
||||
@ -214,6 +216,30 @@ extension StringExtension on String {
|
||||
}
|
||||
}
|
||||
|
||||
/// ```dart
|
||||
/// print('Hello World'.path()) // hello/world
|
||||
/// print('helloWorld'.path()) // hello/world
|
||||
/// print('long space'.path()) // long/space
|
||||
/// ```
|
||||
String path() {
|
||||
switch (length) {
|
||||
case 0:
|
||||
return this;
|
||||
case 1:
|
||||
return toLowerCase();
|
||||
default:
|
||||
return splitMapJoin(
|
||||
RegExp('[A-Z]'),
|
||||
onMatch: (m) => ' ${m[0]}',
|
||||
onNonMatch: (n) => n,
|
||||
).trim().splitMapJoin(
|
||||
_defaultMatcher,
|
||||
onMatch: (m) => '/',
|
||||
onNonMatch: (n) => n.toLowerCase(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// ```dart
|
||||
/// print('Hello World'.upper()) // HELLO WORLD
|
||||
/// print('helloWorld'.upper()) // HELLO WORLD
|
||||
@ -280,4 +306,12 @@ extension StringExtension on String {
|
||||
onNonMatch: (n) => n,
|
||||
);
|
||||
}
|
||||
|
||||
/// ```dart
|
||||
/// print('Hello World'.mustache()) // {{ Hello World }}
|
||||
/// print('helloWorld'.mustache()) // {{ Hello World }}
|
||||
/// ```
|
||||
String mustache() {
|
||||
return '{{ ${title()} }}';
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user