Skip to content

Commit 398a03d

Browse files
committed
resolving issue #7
1 parent f2caf1d commit 398a03d

File tree

2 files changed

+73
-73
lines changed

2 files changed

+73
-73
lines changed

GenerateCommand.php

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ private function createProject()
7777
}
7878

7979
$this->_mkdir($this->projectName);
80-
$this->copyr(__DIR__ . '/stubs/gradle', $this->projectName . DIRECTORY_SEPARATOR . 'gradle');
81-
copy(__DIR__ . '/stubs/gradlew', $this->projectName . DIRECTORY_SEPARATOR . 'gradlew');
82-
copy(__DIR__ . '/stubs/gradlew.bat', $this->projectName . DIRECTORY_SEPARATOR . 'gradlew.bat');
83-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . 'build');
80+
$this->copyr(__DIR__ . '/stubs/gradle', $this->projectName . '/gradle');
81+
copy(__DIR__ . '/stubs/gradlew', $this->projectName . '/gradlew');
82+
copy(__DIR__ . '/stubs/gradlew.bat', $this->projectName . '/gradlew.bat');
83+
$this->_mkdir($this->projectName . '/build');
8484

85-
file_put_contents($this->projectName . DIRECTORY_SEPARATOR . 'build.gradle', "buildscript {\r\n\trepositories {\r\n\t\tgoogle()\r\n\t\tjcenter()\r\n\t}\r\n\tdependencies {\r\n\t\tclasspath 'com.android.tools.build:gradle:3.5.1'\r\n\t}\r\n}\r\n\nallprojects {\r\n\trepositories {\r\n\t\tgoogle()\r\n\t\tjcenter()\r\n\t}\r\n}\r\n\ntask clean(type: Delete) {\r\n\tdelete rootProject.buildDir\r\n}\r\n", 0);
86-
file_put_contents($this->projectName . DIRECTORY_SEPARATOR . '.gitignore', "*.iml\r\n.gradle\r\n/local.properties\r\n/.idea/caches\r\n/.idea/libraries\r\n/.idea/modules.xml\r\n/.idea/workspace.xml\r\n/.idea/navEditor.xml\r\n/.idea/assetWizardSettings.xml\r\n.DS_Store\r\n/build\r\n/captures\r\n.externalNativeBuild\r\n/backup\r\n/priv", 0);
87-
file_put_contents($this->projectName . DIRECTORY_SEPARATOR . 'gradle.properties', "org.gradle.jvmargs=-Xmx1536m\r\nandroid.useAndroidX=" . ($this->input->getOption('androidX') ? "true" : "false") . "\r\nandroid.enableJetifier=" . ($this->input->getOption('jetifier') ? "true" : "false") . "\r\n", 0);
85+
file_put_contents($this->projectName . '/build.gradle', "buildscript {\n\trepositories {\n\t\tgoogle()\n\t\tjcenter()\n\t}\n\tdependencies {\n\t\tclasspath 'com.android.tools.build:gradle:3.5.1'\n\t}\n}\n\nallprojects {\n\trepositories {\n\t\tgoogle()\n\t\tjcenter()\n\t}\n}\n\ntask clean(type: Delete) {\n\tdelete rootProject.buildDir\n}\n", 0);
86+
file_put_contents($this->projectName . '/.gitignore', "*.iml\n.gradle\n/local.properties\n/.idea/caches\n/.idea/libraries\n/.idea/modules.xml\n/.idea/workspace.xml\n/.idea/navEditor.xml\n/.idea/assetWizardSettings.xml\n.DS_Store\n/build\n/captures\n.externalNativeBuild\n/backup\n/priv", 0);
87+
file_put_contents($this->projectName . '/gradle.properties', "org.gradle.jvmargs=-Xmx1536m\nandroid.useAndroidX=" . ($this->input->getOption('androidX') ? "true" : "false") . "\nandroid.enableJetifier=" . ($this->input->getOption('jetifier') ? "true" : "false") . "\n", 0);
8888

8989
$settingsContent = "include ";
9090

@@ -95,79 +95,79 @@ private function createProject()
9595
$moduleType = isset($exModule[1]) ? $exModule[1] : 'application';
9696
}
9797

98-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName);
98+
$this->_mkdir($this->projectName . '/' . $moduleName);
9999

100-
file_put_contents($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . '.gitignore', "/build\n\n", 0);
100+
file_put_contents($this->projectName . '/' . $moduleName . '/.gitignore', "/build\n\n", 0);
101101

102102
$isAndroidX = $this->input->getOption('androidX');
103103

104104
$fdCount = 0;
105105
$flavorContent = '';
106106
$dimensionContent = '';
107107
if ($count = count($this->flavors)) {
108-
$flavorContent = "productFlavors {\r\n\t\t";
108+
$flavorContent = "productFlavors {\n\t\t";
109109
$dimensionContent = 'flavorDimensions ';
110110
foreach ($this->flavors as $flavor => $dimension) {
111111
$dimenPushed = $this->str_contains($dimensionContent, "'$dimension'");
112112
if (!$dimenPushed) {
113113
$dimensionContent .= "'$dimension'";
114114
}
115-
$flavorContent .= $flavor . " {\r\n\t\t\tdimension '$dimension'\r\n\t\t}";
115+
$flavorContent .= $flavor . " {\n\t\t\tdimension '$dimension'\n\t\t}";
116116

117117
if ($fdCount < ($count - 1)) {
118118
$fdCount = $fdCount + 1;
119119
if (!$dimenPushed) {
120120
$dimensionContent .= ", ";
121121
}
122-
$flavorContent .= "\r\n\t\t";
122+
$flavorContent .= "\n\t\t";
123123
}
124124
}
125-
$flavorContent .= "\r\n\t}\r\n";
125+
$flavorContent .= "\n\t}\n";
126126
}
127-
$fdContent = $dimensionContent . "\r\n\t" . $flavorContent;
127+
$fdContent = $dimensionContent . "\n\t" . $flavorContent;
128128

129129
file_put_contents(
130-
$this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'build.gradle',
131-
"apply plugin: 'com.android." . $moduleType . "'\r\n\n" .
132-
"android {\r\n\t" .
133-
"compileSdkVersion " . $this->input->getOption('compileSdk') . "\r\n\t" .
134-
"buildToolsVersion '" . $this->input->getOption('buildTools') . "'\r\n\t" .
135-
"defaultConfig {\r\n\t\t" . ($moduleType === 'library' ? '' : "applicationId '" . ($this->pkgName . ($moduleName === 'app' ? '' : '.' . $moduleName)) . "'\r\n\t\t") .
136-
"minSdkVersion " . $this->input->getOption('minSdk') . "\r\n\t\t" .
137-
"targetSdkVersion " . $this->input->getOption('targetSdk') . "\r\n\t\t" .
138-
"versionCode 1\r\n\t\t" .
139-
"versionName '1.0'\r\n\t\t" .
140-
"testInstrumentationRunner '" . ($isAndroidX ? 'androidx.test.runner.AndroidJUnitRunner' : '') . "'\r\n\t" .
141-
"}\r\n\n\t" .
142-
"buildTypes {\r\n\t\t" .
143-
"debug {\r\n\t\t\tdebuggable true\r\n\t\t}\r\n\t\t" .
144-
"release {\r\n\t\t\tdebuggable false\r\n\t\t\tminifyEnabled true\r\n\t\t\tshrinkResources true\r\n\t\t\tzipAlignEnabled true\r\n\t\t\tproguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'\r\n\t\t}\r\n\t" .
145-
"}\r\n\n\t" .
130+
$this->projectName . '/' . $moduleName . '/build.gradle',
131+
"apply plugin: 'com.android." . $moduleType . "'\n\n" .
132+
"android {\n\t" .
133+
"compileSdkVersion " . $this->input->getOption('compileSdk') . "\n\t" .
134+
"buildToolsVersion '" . $this->input->getOption('buildTools') . "'\n\t" .
135+
"defaultConfig {\n\t\t" . ($moduleType === 'library' ? '' : "applicationId '" . ($this->pkgName . ($moduleName === 'app' ? '' : '.' . $moduleName)) . "'\n\t\t") .
136+
"minSdkVersion " . $this->input->getOption('minSdk') . "\n\t\t" .
137+
"targetSdkVersion " . $this->input->getOption('targetSdk') . "\n\t\t" .
138+
"versionCode 1\n\t\t" .
139+
"versionName '1.0'\n\t\t" .
140+
"testInstrumentationRunner '" . ($isAndroidX ? 'androidx.test.runner.AndroidJUnitRunner' : '') . "'\n\t" .
141+
"}\n\n\t" .
142+
"buildTypes {\n\t\t" .
143+
"debug {\n\t\t\tdebuggable true\n\t\t}\n\t\t" .
144+
"release {\n\t\t\tdebuggable false\n\t\t\tminifyEnabled true\n\t\t\tshrinkResources true\n\t\t\tzipAlignEnabled true\n\t\t\tproguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'\n\t\t}\n\t" .
145+
"}\n\n\t" .
146146
$fdContent .
147-
"}\r\n\n" .
148-
"dependencies {\r\n\t" .
149-
"implementation fileTree(dir: 'libs', include: ['*.jar'])\r\n\t" .
150-
"implementation '" . ($isAndroidX ? 'androidx.appcompat:appcompat:1.0.0' : '') . "'\r\n\t" .
151-
"implementation '" . ($isAndroidX ? 'androidx.constraintlayout:constraintlayout:1.1.3' : '') . "'\r\n\t" .
152-
"testImplementation 'junit:junit:4.12'\r\n\t" .
153-
"androidTestImplementation '" . ($isAndroidX ? 'androidx.test:runner:1.2.0' : '') . "'\r\n\t" .
154-
"androidTestImplementation '" . ($isAndroidX ? 'androidx.test.espresso:espresso-core:3.2.0' : '') . "'\r\n" .
147+
"}\n\n" .
148+
"dependencies {\n\t" .
149+
"implementation fileTree(dir: 'libs', include: ['*.jar'])\n\t" .
150+
"implementation '" . ($isAndroidX ? 'androidx.appcompat:appcompat:1.0.0' : '') . "'\n\t" .
151+
"implementation '" . ($isAndroidX ? 'androidx.constraintlayout:constraintlayout:1.1.3' : '') . "'\n\t" .
152+
"testImplementation 'junit:junit:4.12'\n\t" .
153+
"androidTestImplementation '" . ($isAndroidX ? 'androidx.test:runner:1.2.0' : '') . "'\n\t" .
154+
"androidTestImplementation '" . ($isAndroidX ? 'androidx.test.espresso:espresso-core:3.2.0' : '') . "'\n" .
155155
"}",
156156
0
157157
);
158-
file_put_contents($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'proguard-rules.pro', "\r\n", 0);
158+
file_put_contents($this->projectName . '/' . $moduleName . '/proguard-rules.pro', "\n", 0);
159159

160-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src');
161-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'build');
162-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'libs');
160+
$this->_mkdir($this->projectName . '/' . $moduleName . '/src');
161+
$this->_mkdir($this->projectName . '/' . $moduleName . '/build');
162+
$this->_mkdir($this->projectName . '/' . $moduleName . '/libs');
163163

164-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'androidTest');
165-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'test');
166-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main');
164+
$this->_mkdir($this->projectName . '/' . $moduleName . '/src/androidTest');
165+
$this->_mkdir($this->projectName . '/' . $moduleName . '/src/test');
166+
$this->_mkdir($this->projectName . '/' . $moduleName . '/src/main');
167167

168168
if ($moduleType === 'application') {
169169
file_put_contents(
170-
$this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'AndroidManifest.xml',
170+
$this->projectName . '/' . $moduleName . '/src/main/AndroidManifest.xml',
171171
'<?xml version="1.0" encoding="utf-8"?>
172172
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
173173
package="' . $this->pkgName . '">
@@ -193,28 +193,28 @@ private function createProject()
193193
);
194194
} else {
195195
file_put_contents(
196-
$this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'AndroidManifest.xml',
197-
'<manifest xmlns:android="http://schemas.android.com/apk/res/android" ' . "\r\n\t" . 'package="' . $this->pkgName . ('app' === $moduleName ? '' : '.' . $moduleName) . '">' . "\r\n\n\t" . ($moduleType === 'library' ? '' : '<application' . "\r\n\t\t" .
198-
'android:allowBackup="true"' . "\r\n\t\t" .
199-
'android:icon="@mipmap/ic_launcher"' . "\r\n\t\t" .
200-
'android:label="@string/app_name"' . "\r\n\t\t" .
201-
'android:roundIcon="@mipmap/ic_launcher_round"' . "\r\n\t\t" .
202-
'android:supportsRtl="true"' . "\r\n\t\t" .
203-
'android:theme="@style/AppTheme">' . "\r\n\t\t\t" .
204-
"\r\n\t</application>")
205-
. "\r\n</manifest>\r\n",
196+
$this->projectName . '/' . $moduleName . '/src/main/AndroidManifest.xml',
197+
'<manifest xmlns:android="http://schemas.android.com/apk/res/android" ' . "\n\t" . 'package="' . $this->pkgName . ('app' === $moduleName ? '' : '.' . $moduleName) . '">' . "\n\n\t" . ($moduleType === 'library' ? '' : '<application' . "\n\t\t" .
198+
'android:allowBackup="true"' . "\n\t\t" .
199+
'android:icon="@mipmap/ic_launcher"' . "\n\t\t" .
200+
'android:label="@string/app_name"' . "\n\t\t" .
201+
'android:roundIcon="@mipmap/ic_launcher_round"' . "\n\t\t" .
202+
'android:supportsRtl="true"' . "\n\t\t" .
203+
'android:theme="@style/AppTheme">' . "\n\t\t\t" .
204+
"\n\t</application>")
205+
. "\n</manifest>\n",
206206
0
207207
);
208208
}
209-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'java');
209+
$this->_mkdir($this->projectName . '/' . $moduleName . '/src/main/java');
210210
$exPkg = explode('.', $this->pkgName);
211-
$_dir = $this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'java';
211+
$_dir = $this->projectName . '/' . $moduleName . '/src/main/java';
212212
$_newDir = '';
213213
foreach ($exPkg as $key => $pkgDir) {
214-
$_newDir .= DIRECTORY_SEPARATOR . $pkgDir;
214+
$_newDir .= '/' . $pkgDir;
215215
$this->_mkdir($_dir . $_newDir);
216216
if ($key === (count($exPkg) - 1) && $moduleName !== 'app') {
217-
$this->_mkdir($_dir . $_newDir . DIRECTORY_SEPARATOR . $moduleName);
217+
$this->_mkdir($_dir . $_newDir . '/' . $moduleName);
218218
}
219219
}
220220

@@ -227,7 +227,7 @@ private function createProject()
227227

228228
// HelloWorld Activity
229229
file_put_contents(
230-
$this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'java'. DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $this->pkgName) . DIRECTORY_SEPARATOR . 'MainActivity.java',
230+
$this->projectName . '/' . $moduleName . '/src/main/java/' . str_replace('.', '/', $this->pkgName) . '/MainActivity.java',
231231
"package $this->pkgName;
232232
233233
import androidx.appcompat.app.AppCompatActivity;
@@ -247,17 +247,17 @@ private function createProject()
247247
}
248248

249249
if ($moduleType === 'library') {
250-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'res');
251-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'res' . DIRECTORY_SEPARATOR . 'drawable');
252-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'res' . DIRECTORY_SEPARATOR . 'layout');
253-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'res' . DIRECTORY_SEPARATOR . 'values');
250+
$this->_mkdir($this->projectName . '/' . $moduleName . '/src/main/res');
251+
$this->_mkdir($this->projectName . '/' . $moduleName . '/src/main/res/drawable');
252+
$this->_mkdir($this->projectName . '/' . $moduleName . '/src/main/res/layout');
253+
$this->_mkdir($this->projectName . '/' . $moduleName . '/src/main/res/values');
254254
} else {
255-
$this->copyr(__DIR__ . '/stubs/res', $this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'res');
255+
$this->copyr(__DIR__ . '/stubs/res', $this->projectName . '/' . $moduleName . '/src/main/res');
256256

257257
// HelloWorld Layout
258-
$this->_mkdir($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'res' . DIRECTORY_SEPARATOR . 'layout');
258+
$this->_mkdir($this->projectName . '/' . $moduleName . '/src/main/res/layout');
259259
file_put_contents(
260-
$this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'res' . DIRECTORY_SEPARATOR . 'layout' . DIRECTORY_SEPARATOR . 'activity_main.xml',
260+
$this->projectName . '/' . $moduleName . '/src/main/res/layout/activity_main.xml',
261261
'<?xml version="1.0" encoding="utf-8"?>
262262
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
263263
xmlns:app="http://schemas.android.com/apk/res-auto"
@@ -279,16 +279,16 @@ private function createProject()
279279
0
280280
);
281281
}
282-
file_put_contents($this->projectName . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'res' . DIRECTORY_SEPARATOR . 'values' . DIRECTORY_SEPARATOR . 'strings.xml', "<resources>\r\n\t" . '<string name="app_name">' . ucfirst($moduleName) . "</string>\r\n</resources>\r\n", 0);
282+
file_put_contents($this->projectName . '/' . $moduleName . '/src/main/res/values/strings.xml', "<resources>\n\t" . '<string name="app_name">' . ucfirst($moduleName) . "</string>\n</resources>\n", 0);
283283

284284
$settingsContent .= "':" . $moduleName . "'";
285285

286286
if ($key < (count($this->modules) - 1)) {
287287
$settingsContent .= ",";
288288
}
289289
}
290-
file_put_contents($this->projectName . DIRECTORY_SEPARATOR . 'settings.gradle', $settingsContent . "\r\n", 0);
291-
// file_put_contents($this->projectName . DIRECTORY_SEPARATOR . 'local.properties', "ndk.dir=E\:\\SDK\\ndk-bundle\r\nsdk.dir=E\:\\SDK\r\n", 0);
290+
file_put_contents($this->projectName . '/settings.gradle', $settingsContent . "\n", 0);
291+
// file_put_contents($this->projectName . DIRECTORY_SEPARATOR . 'local.properties', "ndk.dir=E\:\\SDK\\ndk-bundle\nsdk.dir=E\:\\SDK\n", 0);
292292

293293
$this->output->writeln('<info>' . $this->projectName . ' created successfully!</info>');
294294
}

tasks/generate_phar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
define('BASEDIR', dirname(dirname(__FILE__)));
4-
define('BUILDDIR', BASEDIR . DIRECTORY_SEPARATOR . 'tasks');
4+
define('BUILDDIR', BASEDIR . '/tasks');
55

66
$exclude = [
77
'build',
@@ -30,5 +30,5 @@
3030
$phar->setSignatureAlgorithm(\Phar::SHA1);
3131
$phar->startBuffering();
3232
$phar->buildFromIterator($iterator, BASEDIR);
33-
$phar->setStub(file_get_contents(BUILDDIR . DIRECTORY_SEPARATOR . 'stub.php'));
33+
$phar->setStub(file_get_contents(BUILDDIR . '/stub.php'));
3434
$phar->stopBuffering();

0 commit comments

Comments
 (0)