Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
0d1574c3
Unverified
Commit
0d1574c3
authored
6 years ago
by
Mikkel Nygaard Ravn
Committed by
GitHub
6 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor flutter create logic in prep for add2app (#17992)
parent
055ad0ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
88 deletions
+108
-88
create.dart
packages/flutter_tools/lib/src/commands/create.dart
+108
-88
No files found.
packages/flutter_tools/lib/src/commands/create.dart
View file @
0d1574c3
...
...
@@ -158,7 +158,6 @@ class CreateCommand extends FlutterCommand {
organization:
organization
,
projectName:
projectName
,
projectDescription:
argResults
[
'description'
],
dirPath:
dirPath
,
flutterRoot:
flutterRoot
,
renderDriverTest:
argResults
[
'with-driver-test'
],
withPluginHook:
generatePlugin
,
...
...
@@ -167,67 +166,127 @@ class CreateCommand extends FlutterCommand {
);
printStatus
(
'Creating project
${fs.path.relative(dirPath)}
...'
);
int
generatedCount
=
0
;
int
generatedFileCount
=
0
;
String
appPath
=
dirPath
;
switch
(
template
)
{
case
'app'
:
generatedFileCount
+=
await
_generateApp
(
dirPath
,
templateContext
);
break
;
case
'package'
:
generatedFileCount
+=
await
_generatePackage
(
dirPath
,
templateContext
);
break
;
case
'plugin'
:
appPath
=
fs
.
path
.
join
(
dirPath
,
'example'
);
generatedFileCount
+=
await
_generatePlugin
(
dirPath
,
appPath
,
templateContext
);
break
;
}
printStatus
(
'Wrote
$generatedFileCount
files.'
);
printStatus
(
''
);
if
(
generatePackage
)
{
final
String
description
=
argResults
.
wasParsed
(
'description'
)
?
argResults
[
'description'
]
:
'A new flutter package project.'
;
templateContext
[
'description'
]
=
description
;
generatedCount
+=
_renderTemplate
(
'package'
,
dirPath
,
templateContext
);
if
(
argResults
[
'pub'
])
await
pubGet
(
context:
PubContext
.
createPackage
,
directory:
dirPath
,
offline:
argResults
[
'offline'
],
);
final
String
relativePath
=
fs
.
path
.
relative
(
dirPath
);
printStatus
(
'Wrote
$generatedCount
files.'
);
printStatus
(
''
);
printStatus
(
'Your package code is in lib/
$projectName
.dart in the
$relativePath
directory.'
);
return
;
printStatus
(
'Your package code is in lib/
${templateContext['projectName']}
.dart in the
$relativePath
directory.'
);
}
else
{
// Run doctor; tell the user the next steps.
final
String
relativeAppPath
=
fs
.
path
.
relative
(
appPath
);
final
String
relativePluginPath
=
fs
.
path
.
relative
(
dirPath
);
if
(
doctor
.
canLaunchAnything
)
{
// Let them know a summary of the state of their tooling.
await
doctor
.
summary
();
printStatus
(
'''
All done! In order to run your application, type:
\$
cd
$relativeAppPath
\$
flutter run
Your main program file is lib/main.dart in the
$relativeAppPath
directory.
'''
);
if
(
generatePlugin
)
{
printStatus
(
'''
Your plugin code is in lib/
$projectName
.dart in the
$relativePluginPath
directory.
Host platform code is in the android/ and ios/ directories under
$relativePluginPath
.
To edit platform code in an IDE see https://flutter.io/platform-plugins/#edit-code.
'''
);
}
}
else
{
printStatus
(
"You'll need to install additional components before you can run "
'your Flutter app:'
);
printStatus
(
''
);
// Give the user more detailed analysis.
await
doctor
.
diagnose
();
printStatus
(
''
);
printStatus
(
"After installing components, run 'flutter doctor' in order to "
're-validate your setup.'
);
printStatus
(
"When complete, type 'flutter run' from the '
$relativeAppPath
' "
'directory in order to launch your app.'
);
printStatus
(
'Your main program file is:
$relativeAppPath
/lib/main.dart'
);
}
}
}
String
appPath
=
dirPath
;
if
(
generatePlugin
)
{
final
String
description
=
argResults
.
wasParsed
(
'description'
)
?
argResults
[
'description'
]
:
'A new flutter plugin project.'
;
templateContext
[
'description'
]
=
description
;
generatedCount
+=
_renderTemplate
(
'plugin'
,
dirPath
,
templateContext
);
if
(
argResults
[
'pub'
])
await
pubGet
(
context:
PubContext
.
createPlugin
,
directory:
dirPath
,
offline:
argResults
[
'offline'
],
);
Future
<
int
>
_generatePackage
(
String
dirPath
,
Map
<
String
,
dynamic
>
templateContext
)
async
{
int
generatedCount
=
0
;
final
String
description
=
argResults
.
wasParsed
(
'description'
)
?
argResults
[
'description'
]
:
'A new flutter package project.'
;
templateContext
[
'description'
]
=
description
;
generatedCount
+=
_renderTemplate
(
'package'
,
dirPath
,
templateContext
);
if
(
android_sdk
.
androidSdk
!=
null
)
gradle
.
updateLocalProperties
(
projectPath:
dirPath
);
appPath
=
fs
.
path
.
join
(
dirPath
,
'example'
);
final
String
androidPluginIdentifier
=
templateContext
[
'androidIdentifier'
];
final
String
exampleProjectName
=
projectName
+
'_example'
;
templateContext
[
'projectName'
]
=
exampleProjectName
;
templateContext
[
'androidIdentifier'
]
=
_createAndroidIdentifier
(
organization
,
exampleProjectName
);
templateContext
[
'iosIdentifier'
]
=
_createUTIIdentifier
(
organization
,
exampleProjectName
);
templateContext
[
'description'
]
=
'Demonstrates how to use the
$projectName
plugin.'
;
templateContext
[
'pluginProjectName'
]
=
projectName
;
templateContext
[
'androidPluginIdentifier'
]
=
androidPluginIdentifier
;
if
(
argResults
[
'pub'
])
{
await
pubGet
(
context:
PubContext
.
createPackage
,
directory:
dirPath
,
offline:
argResults
[
'offline'
],
);
}
return
generatedCount
;
}
Future
<
int
>
_generatePlugin
(
String
dirPath
,
String
appPath
,
Map
<
String
,
dynamic
>
templateContext
)
async
{
int
generatedCount
=
0
;
final
String
description
=
argResults
.
wasParsed
(
'description'
)
?
argResults
[
'description'
]
:
'A new flutter plugin project.'
;
templateContext
[
'description'
]
=
description
;
generatedCount
+=
_renderTemplate
(
'plugin'
,
dirPath
,
templateContext
);
if
(
argResults
[
'pub'
])
{
await
pubGet
(
context:
PubContext
.
createPlugin
,
directory:
dirPath
,
offline:
argResults
[
'offline'
],
);
}
if
(
android_sdk
.
androidSdk
!=
null
)
gradle
.
updateLocalProperties
(
projectPath:
dirPath
);
final
String
projectName
=
templateContext
[
'projectName'
];
final
String
organization
=
templateContext
[
'organization'
];
final
String
androidPluginIdentifier
=
templateContext
[
'androidIdentifier'
];
final
String
exampleProjectName
=
projectName
+
'_example'
;
templateContext
[
'projectName'
]
=
exampleProjectName
;
templateContext
[
'androidIdentifier'
]
=
_createAndroidIdentifier
(
organization
,
exampleProjectName
);
templateContext
[
'iosIdentifier'
]
=
_createUTIIdentifier
(
organization
,
exampleProjectName
);
templateContext
[
'description'
]
=
'Demonstrates how to use the
$projectName
plugin.'
;
templateContext
[
'pluginProjectName'
]
=
projectName
;
templateContext
[
'androidPluginIdentifier'
]
=
androidPluginIdentifier
;
generatedCount
+=
await
_generateApp
(
appPath
,
templateContext
);
return
generatedCount
;
}
Future
<
int
>
_generateApp
(
String
appPath
,
Map
<
String
,
dynamic
>
templateContext
)
async
{
int
generatedCount
=
0
;
generatedCount
+=
_renderTemplate
(
'create'
,
appPath
,
templateContext
);
generatedCount
+=
_injectGradleWrapper
(
appPath
);
if
(
argResults
[
'with-driver-test'
])
{
final
String
testPath
=
fs
.
path
.
join
(
appPath
,
'test_driver'
);
generatedCount
+=
_renderTemplate
(
'driver'
,
testPath
,
templateContext
);
}
printStatus
(
'Wrote
$generatedCount
files.'
);
printStatus
(
''
);
if
(
argResults
[
'pub'
])
{
await
pubGet
(
context:
PubContext
.
create
,
directory:
appPath
,
offline:
argResults
[
'offline'
]);
new
FlutterProject
(
fs
.
directory
(
appPath
)).
ensureReadyForPlatformSpecificTooling
();
...
...
@@ -236,45 +295,7 @@ class CreateCommand extends FlutterCommand {
if
(
android_sdk
.
androidSdk
!=
null
)
gradle
.
updateLocalProperties
(
projectPath:
appPath
);
printStatus
(
''
);
// Run doctor; tell the user the next steps.
final
String
relativeAppPath
=
fs
.
path
.
relative
(
appPath
);
final
String
relativePluginPath
=
fs
.
path
.
relative
(
dirPath
);
if
(
doctor
.
canLaunchAnything
)
{
// Let them know a summary of the state of their tooling.
await
doctor
.
summary
();
printStatus
(
'''
All done! In order to run your application, type:
\$
cd
$relativeAppPath
\$
flutter run
Your main program file is lib/main.dart in the
$relativeAppPath
directory.
'''
);
if
(
generatePlugin
)
{
printStatus
(
'''
Your plugin code is in lib/
$projectName
.dart in the
$relativePluginPath
directory.
Host platform code is in the android/ and ios/ directories under
$relativePluginPath
.
To edit platform code in an IDE see https://flutter.io/platform-plugins/#edit-code.
'''
);
}
}
else
{
printStatus
(
"You'll need to install additional components before you can run "
'your Flutter app:'
);
printStatus
(
''
);
// Give the user more detailed analysis.
await
doctor
.
diagnose
();
printStatus
(
''
);
printStatus
(
"After installing components, run 'flutter doctor' in order to "
're-validate your setup.'
);
printStatus
(
"When complete, type 'flutter run' from the '
$relativeAppPath
' "
'directory in order to launch your app.'
);
printStatus
(
'Your main program file is:
$relativeAppPath
/lib/main.dart'
);
}
return
generatedCount
;
}
Map
<
String
,
dynamic
>
_templateContext
({
...
...
@@ -283,7 +304,6 @@ To edit platform code in an IDE see https://flutter.io/platform-plugins/#edit-co
String
projectDescription
,
String
androidLanguage
,
String
iosLanguage
,
String
dirPath
,
String
flutterRoot
,
bool
renderDriverTest:
false
,
bool
withPluginHook:
false
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment