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
ffe5197e
Unverified
Commit
ffe5197e
authored
Nov 20, 2020
by
Chris Yang
Committed by
GitHub
Nov 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor (#70959)
parent
8e73bab9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
22 deletions
+28
-22
create.dart
packages/flutter_tools/lib/src/commands/create.dart
+3
-8
create_base.dart
packages/flutter_tools/lib/src/commands/create_base.dart
+25
-14
No files found.
packages/flutter_tools/lib/src/commands/create.dart
View file @
ffe5197e
...
@@ -160,7 +160,7 @@ class CreateCommand extends CreateBase {
...
@@ -160,7 +160,7 @@ class CreateCommand extends CreateBase {
// If the project directory exists and isn't empty, then try to determine the template
// If the project directory exists and isn't empty, then try to determine the template
// type from the project directory.
// type from the project directory.
if
(
projectDir
.
existsSync
()
&&
projectDir
.
listSync
().
isNotEmpty
)
{
if
(
projectDir
.
existsSync
()
&&
projectDir
.
listSync
().
isNotEmpty
)
{
detectedProjectType
=
determineTemplateType
(
projectDir
);
detectedProjectType
=
determineTemplateType
();
if
(
detectedProjectType
==
null
&&
metadataExists
)
{
if
(
detectedProjectType
==
null
&&
metadataExists
)
{
// We can only be definitive that this is the wrong type if the .metadata file
// We can only be definitive that this is the wrong type if the .metadata file
// exists and contains a type that we don't understand, or doesn't contain a type.
// exists and contains a type that we don't understand, or doesn't contain a type.
...
@@ -189,10 +189,6 @@ class CreateCommand extends CreateBase {
...
@@ -189,10 +189,6 @@ class CreateCommand extends CreateBase {
}
}
validateOutputDirectoryArg
();
validateOutputDirectoryArg
();
final
String
flutterRoot
=
getFlutterRoot
();
final
Directory
projectDir
=
globals
.
fs
.
directory
(
argResults
.
rest
.
first
);
final
String
projectDirPath
=
globals
.
fs
.
path
.
normalize
(
projectDir
.
absolute
.
path
);
String
sampleCode
;
String
sampleCode
;
if
(
argResults
[
'sample'
]
!=
null
)
{
if
(
argResults
[
'sample'
]
!=
null
)
{
...
@@ -223,11 +219,10 @@ class CreateCommand extends CreateBase {
...
@@ -223,11 +219,10 @@ class CreateCommand extends CreateBase {
exitCode:
2
);
exitCode:
2
);
}
}
final
String
organization
=
await
getOrganization
(
projectDir
);
final
String
organization
=
await
getOrganization
();
final
bool
overwrite
=
boolArg
(
'overwrite'
);
final
bool
overwrite
=
boolArg
(
'overwrite'
);
validateProjectDir
(
projectDirPath
,
flutterRoot:
flutterRoot
,
overwrite:
overwrite
);
validateProjectDir
(
overwrite:
overwrite
);
final
String
projectName
=
getProjectName
(
projectDirPath
);
if
(
boolArg
(
'with-driver-test'
))
{
if
(
boolArg
(
'with-driver-test'
))
{
globals
.
printError
(
globals
.
printError
(
...
...
packages/flutter_tools/lib/src/commands/create_base.dart
View file @
ffe5197e
...
@@ -105,6 +105,18 @@ abstract class CreateBase extends FlutterCommand {
...
@@ -105,6 +105,18 @@ abstract class CreateBase extends FlutterCommand {
);
);
}
}
/// The output directory of the command.
@protected
Directory
get
projectDir
{
return
globals
.
fs
.
directory
(
argResults
.
rest
.
first
);
}
/// The normalized absolute path of [projectDir].
@protected
String
get
projectDirPath
{
return
globals
.
fs
.
path
.
normalize
(
projectDir
.
absolute
.
path
);
}
/// Adds a `--platforms` argument.
/// Adds a `--platforms` argument.
///
///
/// The help message of the argument is replaced with `customHelp` if `customHelp` is not null.
/// The help message of the argument is replaced with `customHelp` if `customHelp` is not null.
...
@@ -140,7 +152,7 @@ abstract class CreateBase extends FlutterCommand {
...
@@ -140,7 +152,7 @@ abstract class CreateBase extends FlutterCommand {
///
///
/// Throw with exit code 2 if the flutter sdk installed is invalid.
/// Throw with exit code 2 if the flutter sdk installed is invalid.
@protected
@protected
String
get
FlutterRoot
()
{
String
get
flutterRoot
{
if
(
Cache
.
flutterRoot
==
null
)
{
if
(
Cache
.
flutterRoot
==
null
)
{
throwToolExit
(
throwToolExit
(
'The FLUTTER_ROOT environment variable was not specified. Unable to find package:flutter.'
,
'The FLUTTER_ROOT environment variable was not specified. Unable to find package:flutter.'
,
...
@@ -177,10 +189,10 @@ abstract class CreateBase extends FlutterCommand {
...
@@ -177,10 +189,10 @@ abstract class CreateBase extends FlutterCommand {
/// Otherwise, we don't presume to know what type of project it could be, since
/// Otherwise, we don't presume to know what type of project it could be, since
/// many of the files could be missing, and we can't really tell definitively.
/// many of the files could be missing, and we can't really tell definitively.
///
///
/// Throws assertion if
projectDir
does not exist or empty.
/// Throws assertion if
[projectDir]
does not exist or empty.
/// Returns null if no project type can be determined.
/// Returns null if no project type can be determined.
@protected
@protected
FlutterProjectType
determineTemplateType
(
Directory
projectDir
)
{
FlutterProjectType
determineTemplateType
()
{
assert
(
projectDir
.
existsSync
()
&&
projectDir
.
listSync
().
isNotEmpty
);
assert
(
projectDir
.
existsSync
()
&&
projectDir
.
listSync
().
isNotEmpty
);
final
File
metadataFile
=
globals
.
fs
final
File
metadataFile
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
projectDir
.
absolute
.
path
,
'.metadata'
));
.
file
(
globals
.
fs
.
path
.
join
(
projectDir
.
absolute
.
path
,
'.metadata'
));
...
@@ -215,7 +227,7 @@ abstract class CreateBase extends FlutterCommand {
...
@@ -215,7 +227,7 @@ abstract class CreateBase extends FlutterCommand {
/// If `--org` is specified in the command, returns that directly.
/// If `--org` is specified in the command, returns that directly.
/// If `--org` is not specified, returns the organization from the existing project.
/// If `--org` is not specified, returns the organization from the existing project.
@protected
@protected
Future
<
String
>
getOrganization
(
Directory
projectDir
)
async
{
Future
<
String
>
getOrganization
()
async
{
String
organization
=
stringArg
(
'org'
);
String
organization
=
stringArg
(
'org'
);
if
(!
argResults
.
wasParsed
(
'org'
))
{
if
(!
argResults
.
wasParsed
(
'org'
))
{
final
FlutterProject
project
=
FlutterProject
.
fromDirectory
(
projectDir
);
final
FlutterProject
project
=
FlutterProject
.
fromDirectory
(
projectDir
);
...
@@ -233,20 +245,19 @@ abstract class CreateBase extends FlutterCommand {
...
@@ -233,20 +245,19 @@ abstract class CreateBase extends FlutterCommand {
/// Throws with exit 2 if the project directory is illegal.
/// Throws with exit 2 if the project directory is illegal.
@protected
@protected
void
validateProjectDir
(
String
dirPath
,
void
validateProjectDir
({
bool
overwrite
=
false
})
{
{
String
flutterRoot
,
bool
overwrite
=
false
})
{
if
(
globals
.
fs
.
path
.
isWithin
(
flutterRoot
,
projectDirPath
))
{
if
(
globals
.
fs
.
path
.
isWithin
(
flutterRoot
,
dirPath
))
{
throwToolExit
(
throwToolExit
(
'Cannot create a project within the Flutter SDK. '
'Cannot create a project within the Flutter SDK. '
"Target directory '
$
d
irPath
' is within the Flutter SDK at '
$flutterRoot
'."
,
"Target directory '
$
projectD
irPath
' is within the Flutter SDK at '
$flutterRoot
'."
,
exitCode:
2
);
exitCode:
2
);
}
}
// If the destination directory is actually a file, then we refuse to
// If the destination directory is actually a file, then we refuse to
// overwrite, on the theory that the user probably didn't expect it to exist.
// overwrite, on the theory that the user probably didn't expect it to exist.
if
(
globals
.
fs
.
isFileSync
(
d
irPath
))
{
if
(
globals
.
fs
.
isFileSync
(
projectD
irPath
))
{
final
String
message
=
final
String
message
=
"Invalid project name: '
$
d
irPath
' - refers to an existing file."
;
"Invalid project name: '
$
projectD
irPath
' - refers to an existing file."
;
throwToolExit
(
throwToolExit
(
overwrite
overwrite
?
'
$message
Refusing to overwrite a file with a directory.'
?
'
$message
Refusing to overwrite a file with a directory.'
...
@@ -258,17 +269,17 @@ abstract class CreateBase extends FlutterCommand {
...
@@ -258,17 +269,17 @@ abstract class CreateBase extends FlutterCommand {
return
;
return
;
}
}
final
FileSystemEntityType
type
=
globals
.
fs
.
typeSync
(
d
irPath
);
final
FileSystemEntityType
type
=
globals
.
fs
.
typeSync
(
projectD
irPath
);
switch
(
type
)
{
switch
(
type
)
{
case
FileSystemEntityType
.
file
:
case
FileSystemEntityType
.
file
:
// Do not overwrite files.
// Do not overwrite files.
throwToolExit
(
"Invalid project name: '
$
d
irPath
' - file exists."
,
throwToolExit
(
"Invalid project name: '
$
projectD
irPath
' - file exists."
,
exitCode:
2
);
exitCode:
2
);
break
;
break
;
case
FileSystemEntityType
.
link
:
case
FileSystemEntityType
.
link
:
// Do not overwrite links.
// Do not overwrite links.
throwToolExit
(
"Invalid project name: '
$
d
irPath
' - refers to a link."
,
throwToolExit
(
"Invalid project name: '
$
projectD
irPath
' - refers to a link."
,
exitCode:
2
);
exitCode:
2
);
break
;
break
;
default
:
default
:
...
@@ -279,7 +290,7 @@ abstract class CreateBase extends FlutterCommand {
...
@@ -279,7 +290,7 @@ abstract class CreateBase extends FlutterCommand {
///
///
/// Use the current directory path name if the `--project-name` is not specified explicitly.
/// Use the current directory path name if the `--project-name` is not specified explicitly.
@protected
@protected
String
get
ProjectName
(
String
projectDirPath
)
{
String
get
projectName
{
final
String
projectName
=
final
String
projectName
=
stringArg
(
'project-name'
)
??
globals
.
fs
.
path
.
basename
(
projectDirPath
);
stringArg
(
'project-name'
)
??
globals
.
fs
.
path
.
basename
(
projectDirPath
);
if
(!
boolArg
(
'skip-name-checks'
))
{
if
(!
boolArg
(
'skip-name-checks'
))
{
...
...
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