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
2efd1315
Commit
2efd1315
authored
Aug 07, 2015
by
Devon Carew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a sky_tools init command to create a new project
parent
66657a81
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
298 additions
and
1 deletion
+298
-1
sky_tools.dart
packages/flutter_tools/bin/sky_tools.dart
+47
-0
common.dart
packages/flutter_tools/lib/src/common.dart
+27
-0
init.dart
packages/flutter_tools/lib/src/init.dart
+162
-0
pubspec.yaml
packages/flutter_tools/pubspec.yaml
+7
-0
init_test.dart
packages/flutter_tools/test/init_test.dart
+53
-0
travis.sh
packages/flutter_tools/tool/travis.sh
+2
-1
No files found.
packages/flutter_tools/bin/sky_tools.dart
0 → 100644
View file @
2efd1315
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:io'
;
import
'package:args/args.dart'
;
import
'package:sky_tools/src/common.dart'
;
import
'package:sky_tools/src/init.dart'
;
void
main
(
List
<
String
>
args
)
{
Map
<
String
,
CommandHandler
>
handlers
=
{};
ArgParser
parser
=
new
ArgParser
();
parser
.
addSeparator
(
'options:'
);
parser
.
addFlag
(
'help'
,
abbr:
'h'
,
negatable:
false
,
help:
'Display this help message.'
);
parser
.
addSeparator
(
'commands:'
);
CommandHandler
handler
=
new
InitCommandHandler
();
parser
.
addCommand
(
handler
.
name
,
handler
.
parser
);
handlers
[
handler
.
name
]
=
handler
;
ArgResults
results
=
parser
.
parse
(
args
);
if
(
results
[
'help'
])
{
_printUsage
(
parser
,
handlers
);
}
else
if
(
results
.
command
!=
null
)
{
handlers
[
results
.
command
.
name
].
processArgResults
(
results
.
command
);
}
else
{
_printUsage
(
parser
,
handlers
,
'No command specified.'
);
exit
(
1
);
}
}
void
_printUsage
(
ArgParser
parser
,
Map
<
String
,
CommandHandler
>
handlers
,
[
String
message
])
{
if
(
message
!=
null
)
{
print
(
'
${message}
\n
'
);
}
print
(
'usage: sky_tools <command> [arguments]'
);
print
(
''
);
print
(
parser
.
usage
);
handlers
.
forEach
((
String
command
,
CommandHandler
handler
)
{
print
(
'
${command.padRight(10)}
${handler.description}
'
);
});
}
packages/flutter_tools/lib/src/common.dart
0 → 100644
View file @
2efd1315
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:args/args.dart'
;
abstract
class
CommandHandler
{
final
String
name
;
final
String
description
;
CommandHandler
(
this
.
name
,
this
.
description
);
ArgParser
get
parser
;
void
processArgResults
(
ArgResults
results
);
void
printUsage
([
String
message
])
{
if
(
message
!=
null
)
{
print
(
'
${message}
\n
'
);
}
print
(
'usage: sky_tools
${name}
[arguments]'
);
print
(
''
);
print
(
parser
.
usage
);
}
String
toString
()
=>
name
;
}
packages/flutter_tools/lib/src/init.dart
0 → 100644
View file @
2efd1315
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
library
sky_tools
.
init
;
import
'dart:async'
;
import
'dart:io'
;
import
'package:args/args.dart'
;
import
'package:path/path.dart'
as
p
;
import
'common.dart'
;
class
InitCommandHandler
extends
CommandHandler
{
InitCommandHandler
()
:
super
(
'init'
,
'Create a new sky project.'
);
ArgParser
get
parser
{
ArgParser
parser
=
new
ArgParser
();
parser
.
addFlag
(
'help'
,
abbr:
'h'
,
negatable:
false
,
help:
'Display this help message.'
);
// parser.addOption('template',
// abbr: 't',
// help: "The template to generate; either sky-simple or sky-full.");
parser
.
addOption
(
'out'
,
abbr:
'o'
,
help:
'The output directory.'
);
parser
.
addFlag
(
'pub'
,
defaultsTo:
true
,
help:
'Whether to run pub after the project has been created.'
);
return
parser
;
}
Future
processArgResults
(
ArgResults
results
)
async
{
if
(
results
[
'help'
])
{
printUsage
();
return
new
Future
.
value
();
}
if
(!
results
.
wasParsed
(
'out'
))
{
printUsage
(
'No option specified for the output directory.'
);
return
new
Future
.
value
();
}
Directory
out
=
new
Directory
(
results
[
'out'
]);
// TODO: confirm overwrite with user
//if (out.existsSync())
new
SkySimpleTemplate
().
generateInto
(
out
);
print
(
''
);
String
message
=
'All done! To run your application:
\n
'
'cd
${out.path}
\n
'
'./packages/sky/sky_tool start'
;
if
(
results
[
'pub'
])
{
print
(
"Running pub get..."
);
Process
process
=
await
Process
.
start
(
'pub'
,
[
'get'
],
workingDirectory:
out
.
path
);
stdout
.
addStream
(
process
.
stdout
);
stderr
.
addStream
(
process
.
stderr
);
int
code
=
await
process
.
exitCode
;
if
(
code
==
0
)
{
print
(
'
\n
${message}
'
);
}
}
else
{
print
(
message
);
}
}
}
abstract
class
Template
{
final
String
name
;
final
String
description
;
Map
<
String
,
String
>
files
=
{};
Template
(
this
.
name
,
this
.
description
);
void
generateInto
(
Directory
dir
)
{
String
projectName
=
_normalizeProjectName
(
p
.
basename
(
dir
.
path
));
print
(
'Creating
${p.basename(projectName)}
...'
);
dir
.
createSync
(
recursive:
true
);
files
.
forEach
((
String
path
,
String
contents
)
{
contents
=
contents
.
replaceAll
(
'{{projectName}}'
,
projectName
)
.
replaceAll
(
'{{description}}'
,
description
);
File
file
=
new
File
(
p
.
join
(
dir
.
path
,
path
));
file
.
parent
.
createSync
();
file
.
writeAsStringSync
(
contents
);
print
(
file
.
path
);
});
}
String
toString
()
=>
name
;
}
class
SkySimpleTemplate
extends
Template
{
SkySimpleTemplate
()
:
super
(
'sky-simple'
,
'A minimal Sky project.'
)
{
files
[
'.gitignore'
]=
_gitignore
;
files
[
'pubspec.yaml'
]=
_pubspec
;
files
[
'README.md'
]=
_readme
;
files
[
'lib/main.dart'
]=
_libMain
;
}
}
String
_normalizeProjectName
(
String
name
)
{
name
=
name
.
replaceAll
(
'-'
,
'_'
).
replaceAll
(
' '
,
'_'
);
// Strip any extension (like .dart).
if
(
name
.
contains
(
'.'
))
{
name
=
name
.
substring
(
0
,
name
.
indexOf
(
'.'
));
}
return
name
;
}
const
_gitignore
=
r''
'
.DS_Store
.idea
.packages
.pub/
build/
packages
pubspec.lock
'''
;
const
_readme
=
r''
'
# {{projectName}}
{{description}}
## Getting Started
For help getting started, view our online
[readme](https://github.com/domokit/sky_engine/blob/master/sky/packages/sky/README.md).
'''
;
const
_pubspec
=
r''
'
name: {{projectName}}
description: {{description}}
dependencies:
sky: any
sky_tools: any
'''
;
const
_libMain
=
r''
'
import '
package:
sky
/
widgets
.
dart
';
class HelloWorldApp extends App {
Widget build() {
return new Scaffold(
toolbar: new ToolBar(center: new Text("Demo")),
body: new Material(child: new Center(child: new Text("Hello world!"))),
floatingActionButton: new FloatingActionButton(
child: new Icon(type: '
content
/
add
', size: 24)
)
);
}
}
void main() {
runApp(new HelloWorldApp());
}
'''
;
packages/flutter_tools/pubspec.yaml
View file @
2efd1315
...
...
@@ -9,5 +9,12 @@ environment:
dependencies
:
args
:
^0.13.0
path
:
^1.3.0
shelf
:
^0.6.2
shelf_static
:
^0.2.3
dev_dependencies
:
test
:
^0.12.0
executable
:
sky_tools
:
packages/flutter_tools/test/init_test.dart
0 → 100644
View file @
2efd1315
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:io'
;
import
'package:args/args.dart'
;
import
'package:path/path.dart'
as
p
;
import
'package:sky_tools/src/init.dart'
;
import
'package:test/test.dart'
;
main
()
=>
defineTests
();
defineTests
()
{
group
(
''
,
()
{
Directory
temp
;
setUp
(()
{
temp
=
Directory
.
systemTemp
.
createTempSync
(
'sky_tools'
);
});
tearDown
(()
{
temp
.
deleteSync
(
recursive:
true
);
});
// Verify that we create a project that os well-formed.
test
(
'init sky-simple'
,
()
async
{
InitCommandHandler
handler
=
new
InitCommandHandler
();
_MockArgResults
results
=
new
_MockArgResults
();
results
.
values
[
'help'
]
=
false
;
results
.
values
[
'pub'
]
=
true
;
results
.
values
[
'out'
]
=
temp
.
path
;
await
handler
.
processArgResults
(
results
);
String
path
=
p
.
join
(
temp
.
path
,
'lib/main.dart'
);
print
(
path
);
expect
(
new
File
(
path
).
existsSync
(),
true
);
ProcessResult
exec
=
Process
.
runSync
(
'dartanalyzer'
,
[
path
],
workingDirectory:
temp
.
path
);
expect
(
exec
.
exitCode
,
0
);
});
});
}
class
_MockArgResults
implements
ArgResults
{
Map
values
=
{};
operator
[](
String
name
)
=>
values
[
name
];
List
<
String
>
get
arguments
=>
null
;
ArgResults
get
command
=>
null
;
String
get
name
=>
null
;
Iterable
<
String
>
get
options
=>
values
.
keys
;
List
<
String
>
get
rest
=>
null
;
bool
wasParsed
(
String
name
)
=>
values
.
containsKey
(
name
);
}
packages/flutter_tools/tool/travis.sh
View file @
2efd1315
...
...
@@ -10,4 +10,5 @@ set -e
# Verify that the libraries are error free.
dartanalyzer
--fatal-warnings
\
bin/build_sky_apk.dart
\
bin/sky_server.dart
bin/sky_server.dart
\
bin/sky_tools.dart
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