Skip to content

Commit 8607b9e

Browse files
committed
Merge branch 'release/1.4.0'
2 parents f0d8e6b + 43f608f commit 8607b9e

File tree

11 files changed

+461
-298
lines changed

11 files changed

+461
-298
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.4.0
2+
* Have added `gen` command to generate directory and common files for a modified tdd structure
3+
* Fixed adding multiple instance of plugins if already exists
4+
* Made all functions private
5+
16
## 1.3.3
27
* Google services version upgraded
38

lib/android_signing.dart

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import 'dart:io';
2-
import './commons.dart' as commons;
1+
part of flutter_automation;
32

43
String alias;
54
String keystorePath = "keys/keystore.jks";
@@ -8,14 +7,14 @@ String keystorePass;
87
const String keyPropertiesPath = "./android/key.properties";
98

109
/// Main function that uses other helper functions to setup android signing
11-
void androidSign() {
12-
generateKeystore();
13-
createKeyProperties();
14-
configureBuildConfig();
10+
void _androidSign() {
11+
_generateKeystore();
12+
_createKeyProperties();
13+
_configureBuildConfig();
1514
}
1615

1716
/// Generates the keystore with the given settings
18-
void generateKeystore() {
17+
void _generateKeystore() {
1918
String defDname =
2019
"CN=popupbits.com, OU=DD, O=Popup Bits Ltd., L=Kathmandu, S=Bagmati, C=NP";
2120

@@ -69,8 +68,8 @@ void generateKeystore() {
6968
}
7069

7170
/// Creates key.properties file required by signing config in build.gradle file
72-
void createKeyProperties() {
73-
commons.writeStringToFile(keyPropertiesPath, """storePassword=$keystorePass
71+
void _createKeyProperties() {
72+
_Commons.writeStringToFile(keyPropertiesPath, """storePassword=$keystorePass
7473
keyPassword=$keyPass
7574
keyAlias=$alias
7675
storeFile=../../$keystorePath
@@ -79,38 +78,44 @@ storeFile=../../$keystorePath
7978
}
8079

8180
/// configures build.gradle with release config with the generated key details
82-
void configureBuildConfig() {
83-
List<String> buildfile = commons.getFileAsLines(commons.appBuildPath);
84-
buildfile = buildfile.map((line) {
85-
if (line.contains(RegExp("android.*{"))) {
86-
return """
87-
def keystoreProperties = new Properties()
88-
def keystorePropertiesFile = rootProject.file('key.properties')
89-
if (keystorePropertiesFile.exists()) {
90-
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
91-
}
92-
93-
android {
94-
""";
95-
} else if (line.contains(RegExp("buildTypes.*{"))) {
96-
return """
97-
signingConfigs {
98-
release {
99-
keyAlias keystoreProperties['keyAlias']
100-
keyPassword keystoreProperties['keyPassword']
101-
storeFile file(keystoreProperties['storeFile'])
102-
storePassword keystoreProperties['storePassword']
103-
}
81+
void _configureBuildConfig() {
82+
String bfString = _Commons.getFileAsString(_Commons.appBuildPath);
83+
List<String> buildfile = _Commons.getFileAsLines(_Commons.appBuildPath);
84+
if (!bfString.contains("deft keystoreProperties") &&
85+
!bfString.contains("keystoreProperties['keyAlias']")) {
86+
buildfile = buildfile.map((line) {
87+
if (line.contains(RegExp("android.*{"))) {
88+
return """
89+
def keystoreProperties = new Properties()
90+
def keystorePropertiesFile = rootProject.file('key.properties')
91+
if (keystorePropertiesFile.exists()) {
92+
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
10493
}
105-
buildTypes {
106-
""";
107-
} else if (line.contains("signingConfig signingConfigs.debug")) {
108-
return " signingConfig signingConfigs.release";
109-
} else {
110-
return line;
94+
95+
android {
96+
""";
97+
} else if (line.contains(RegExp("buildTypes.*{"))) {
98+
return """
99+
signingConfigs {
100+
release {
101+
keyAlias keystoreProperties['keyAlias']
102+
keyPassword keystoreProperties['keyPassword']
103+
storeFile file(keystoreProperties['storeFile'])
104+
storePassword keystoreProperties['storePassword']
105+
}
111106
}
112-
}).toList();
107+
buildTypes {
108+
""";
109+
} else if (line.contains("signingConfig signingConfigs.debug")) {
110+
return " signingConfig signingConfigs.release";
111+
} else {
112+
return line;
113+
}
114+
}).toList();
113115

114-
commons.writeStringToFile(commons.appBuildPath, buildfile.join("\n"));
115-
stdout.writeln("configured release configs");
116+
_Commons.writeStringToFile(_Commons.appBuildPath, buildfile.join("\n"));
117+
stdout.writeln("configured release configs");
118+
} else {
119+
stdout.writeln("release configs already configured");
120+
}
116121
}

lib/commons.dart

Lines changed: 95 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,108 @@
1-
import 'dart:io';
2-
import 'package:yaml/yaml.dart';
3-
import 'package:path/path.dart' as path;
1+
part of flutter_automation;
42

5-
String scriptRoot = path.dirname(Platform.script.toFilePath()) + "${path.separator}..";
3+
class _Commons {
4+
static final String scriptRoot =
5+
path.dirname(Platform.script.toFilePath()) + "${path.separator}..";
6+
static final String basePath = "./lib";
7+
static final String pubspecPath = './pubspec.yaml';
8+
static final String stringsPath =
9+
"./android/app/src/main/res/values/strings.xml";
10+
static final String manifestPath =
11+
"./android/app/src/main/AndroidManifest.xml";
12+
static final String appBuildPath = "./android/app/build.gradle";
13+
static final String projectBuildPath = "./android/build.gradle";
614

7-
const String pubspecPath = './pubspec.yaml';
8-
const String stringsPath = "./android/app/src/main/res/values/strings.xml";
9-
const String manifestPath = "./android/app/src/main/AndroidManifest.xml";
10-
const String appBuildPath = "./android/app/build.gradle";
11-
const String projectBuildPath = "./android/build.gradle";
12-
/// Default plugin versions
13-
Map<String, dynamic> defaultConfig = {
14-
"plugins": {
15-
"firebase_auth": "^0.14.0+5",
16-
"google_sign_in": "^4.0.7",
17-
"provider": "^3.1.0",
18-
"google_maps": "^0.5.21+2",
19-
"firestore": "^0.12.9+4"
20-
},
21-
"google_services": "4.3.3"
22-
};
15+
/// Default plugin versions
16+
static Map<String, dynamic> defaultConfig = {
17+
"plugins": {
18+
"firebase_auth": "^0.14.0+5",
19+
"google_sign_in": "^4.0.7",
20+
"provider": "^3.1.0",
21+
"google_maps": "^0.5.21+2",
22+
"firestore": "^0.12.9+4"
23+
},
24+
"google_services": "4.3.3"
25+
};
2326

24-
/// Loads config either from the flutter_automation.yaml config file or default config
25-
Map<String, dynamic> loadConfig() {
26-
if (!File("./flutter_automation.yaml").existsSync()) return defaultConfig;
27-
String configcontent = File("./flutter_automation.yaml").readAsStringSync();
28-
var configFile = loadYaml(configcontent);
29-
return Map<String, dynamic>.from(configFile);
30-
}
27+
/// Loads config either from the flutter_automation.yaml config file or default config
28+
static Map<String, dynamic> loadConfig() {
29+
if (!File("./flutter_automation.yaml").existsSync()) return defaultConfig;
30+
String configcontent = File("./flutter_automation.yaml").readAsStringSync();
31+
var configFile = loadYaml(configcontent);
32+
return Map<String, dynamic>.from(configFile);
33+
}
3134

32-
/// Adds provided dependencies to pubspec.yaml file
33-
void addDependencise(String dependencies) {
34-
replaceFirstStringInfile(
35-
pubspecPath, "dev_dependencies:", "$dependencies\ndev_dependencies:");
36-
}
35+
static bool fileContainsString(String path, String pattern) {
36+
String file = getFileAsString(path);
37+
return file.contains(pattern);
38+
}
3739

38-
/// replace string in a file at [path] from [from] to [to]
39-
void replaceFirstStringInfile(String path, Pattern from, String to) {
40-
String contents = getFileAsString(path);
41-
contents = contents.replaceFirst(from, to);
42-
writeStringToFile(path, contents);
43-
}
40+
static bool pluginExists(String plugin) {
41+
return fileContainsString(pubspecPath, plugin);
42+
}
4443

45-
/// Reads a file at [path] as string
46-
String getFileAsString(String path) {
47-
return File(path).readAsStringSync();
48-
}
44+
/// Adds provided dependencies to pubspec.yaml file
45+
static void addDependencise(String dependencies) {
46+
replaceFirstStringInfile(
47+
pubspecPath, "dev_dependencies:", "$dependencies\ndev_dependencies:");
48+
}
4949

50-
/// writes a string [contents] to a file at [path]
51-
void writeStringToFile(String path, String contents) {
52-
File(path).writeAsStringSync(contents);
53-
}
50+
/// replace string in a file at [path] from [from] to [to]
51+
static void replaceFirstStringInfile(String path, Pattern from, String to) {
52+
String contents = getFileAsString(path);
53+
contents = contents.replaceFirst(from, to);
54+
writeStringToFile(path, contents);
55+
}
5456

55-
/// Reads a file at [path] as a list of lines
56-
List<String> getFileAsLines(String path) {
57-
return File(path).readAsLinesSync();
58-
}
57+
/// Reads a file at [path] as string
58+
static String getFileAsString(String path) {
59+
return File(path).readAsStringSync();
60+
}
61+
62+
/// writes a string [contents] to a file at [path]
63+
static void writeStringToFile(String path, String contents) {
64+
File(path).writeAsStringSync(contents);
65+
}
5966

60-
/// Copies files recursively from [from] directory to [to] directory
61-
void copyFilesRecursive(String from, String to, {String renameBaseDir}) {
62-
Process.run(
63-
"cp",
64-
["-r", from, to],
65-
).then((res) {
66-
stdout.write(res.stdout);
67-
if (res.stderr.toString().isNotEmpty) {
68-
stderr.write(res.stderr);
69-
} else {
70-
if (renameBaseDir != null) {
71-
renameStockFiles(renameBaseDir);
67+
/// Reads a file at [path] as a list of lines
68+
static List<String> getFileAsLines(String path) {
69+
return File(path).readAsLinesSync();
70+
}
71+
72+
/// Copies files recursively from [from] directory to [to] directory
73+
static void copyFilesRecursive(String from, String to,
74+
{String renameBaseDir}) {
75+
Process.run(
76+
"cp",
77+
["-r", from, to],
78+
).then((res) {
79+
stdout.write(res.stdout);
80+
if (res.stderr.toString().isNotEmpty) {
81+
stderr.write(res.stderr);
82+
} else {
83+
if (renameBaseDir != null) {
84+
renameStockFiles(renameBaseDir);
85+
}
86+
stdout.writeln("copied stock files");
7287
}
73-
stdout.writeln("copied stock files");
74-
}
75-
});
76-
}
88+
});
89+
}
7790

78-
/// Renames all stock files in [basedir]
79-
void renameStockFiles(String basedir) {
80-
Directory dir = Directory(basedir);
81-
List<FileSystemEntity> files = dir.listSync(recursive: true);
82-
files.forEach((file) {
83-
if (file is File) {
84-
String filename = path.basename(file.path);
85-
if (filename.substring(filename.length - 5, filename.length) == ".temp") {
86-
String newFilename = filename.substring(0, filename.length - 5);
87-
file.renameSync(path.dirname(file.path) + path.separator + newFilename);
91+
/// Renames all stock files in [basedir]
92+
static void renameStockFiles(String basedir) {
93+
Directory dir = Directory(basedir);
94+
List<FileSystemEntity> files = dir.listSync(recursive: true);
95+
files.forEach((file) {
96+
if (file is File) {
97+
String filename = path.basename(file.path);
98+
if (filename.substring(filename.length - 5, filename.length) ==
99+
".temp") {
100+
String newFilename = filename.substring(0, filename.length - 5);
101+
file.renameSync(
102+
path.dirname(file.path) + path.separator + newFilename);
103+
}
88104
}
89-
}
90-
});
91-
stdout.writeln("renamed stock files");
105+
});
106+
stdout.writeln("renamed stock files");
107+
}
92108
}

0 commit comments

Comments
 (0)