Skip to content

Commit 51a0754

Browse files
authored
Merge pull request #12 from widgetbook/cli
added cli
2 parents e0c5b19 + c2cfef0 commit 51a0754

18 files changed

Lines changed: 288 additions & 40 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
# Conventional directory for build output.
66
build/
77

8-
.DS_Store
8+
.DS_Store
9+
10+
assets/
11+
web.zip

.vscode/launch.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"--api_key",
1616
"zYzp8bqsbjZaKPIEVMmXaAxlki6rAe0xPbz5qvMiINdzwrmndu1Qe2lfFlQ9PWdw7c5986lTqJXVOk1MjIJJ6Q=="
1717
]
18-
},{
18+
},
19+
{
1920
"name": "run (gitlab)",
2021
"request": "launch",
2122
"type": "dart",
@@ -27,6 +28,19 @@
2728
"--api_key",
2829
"zYzp8bqsbjZaKPIEVMmXaAxlki6rAe0xPbz5qvMiINdzwrmndu1Qe2lfFlQ9PWdw7c5986lTqJXVOk1MjIJJ6Q=="
2930
]
31+
},
32+
{
33+
"name": "debug (cli)",
34+
"request": "launch",
35+
"type": "dart",
36+
"program": "bin/cli.dart",
37+
"cwd": "packages/cli",
38+
"args": [
39+
"--path",
40+
"../../assets/web",
41+
"--api-key",
42+
"MKaFf0zMJYwWzSV2HclF8G2gVAkHmvTw"
43+
]
3044
}
3145

3246
]

packages/bitbucket/bin/bitbucket_deployment_parser.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ class BitbucketDeploymentParser extends DeploymentParser {
99
final branchName = map['BITBUCKET_BRANCH'];
1010
final repositoryName = map['BITBUCKET_REPO_FULL_NAME'];
1111
final commitSha = map['BITBUCKET_COMMIT'];
12+
final apikey = map['WIDGETBOOK_API_KEY'];
1213

1314
if (actor == null ||
1415
branchName == null ||
1516
repositoryName == null ||
16-
commitSha == null) {
17+
commitSha == null ||
18+
apikey == null) {
1719
throw Exception('Not able to find expected information');
1820
}
1921

@@ -23,6 +25,7 @@ class BitbucketDeploymentParser extends DeploymentParser {
2325
commitSha: commitSha,
2426
repositoryName: repositoryName,
2527
provider: 'BitBucket',
28+
apiKey: apikey,
2629
);
2730
}
2831
}

packages/bitbucket/bin/main.dart

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ import 'bitbucket_deployment_parser.dart';
66

77
Future<void> main(List<String> arguments) async {
88
final deploymentData = BitbucketDeploymentParser().parse();
9-
final apiKey = parseApiKey();
109
final buildPath = parseBuildPath();
1110

1211
final directory = Directory(buildPath);
1312
final file = WidgetbookZipEncoder().encode(directory);
1413
if (file != null) {
15-
await WidgetbookHttpClient(apiKey: apiKey).uploadDeployment(
14+
await WidgetbookHttpClient().uploadDeployment(
1615
deploymentFile: file,
1716
data: deploymentData,
1817
);
@@ -21,16 +20,6 @@ Future<void> main(List<String> arguments) async {
2120
}
2221
}
2322

24-
String parseApiKey() {
25-
final apikey = Platform.environment['WIDGETBOOK_API_KEY'];
26-
27-
if (apikey == null) {
28-
throw Exception('Could not parse API key');
29-
}
30-
31-
return apikey;
32-
}
33-
3423
String parseBuildPath() {
3524
final buildPath = Platform.environment['WIDGETBOOK_BUILD_PATH'];
3625

packages/cli/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Files and directories created by pub.
2+
.dart_tool/
3+
.packages
4+
5+
# Conventional directory for build output.
6+
build/

packages/cli/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
- Initial version.

packages/cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A simple command-line application.

packages/cli/analysis_options.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file configures the static analysis results for your project (errors,
2+
# warnings, and lints).
3+
#
4+
# This enables the 'recommended' set of lints from `package:lints`.
5+
# This set helps identify many issues that may lead to problems when running
6+
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
7+
# style and format.
8+
#
9+
# If you want a smaller set of lints you can change this to specify
10+
# 'package:lints/core.yaml'. These are just the most critical lints
11+
# (the recommended set includes the core lints).
12+
# The core lints are also what is used by pub.dev for scoring packages.
13+
14+
include: package:lints/recommended.yaml
15+
16+
# Uncomment the following section to specify additional rules.
17+
18+
# linter:
19+
# rules:
20+
# - camel_case_types
21+
22+
# analyzer:
23+
# exclude:
24+
# - path/to/excluded/files/**
25+
26+
# For more information about the core and recommended set of lints, see
27+
# https://dart.dev/go/core-lints
28+
29+
# For additional information about configuring this file, see
30+
# https://dart.dev/guides/language/analysis-options

packages/cli/bin/cli.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import 'dart:io';
2+
3+
import 'package:args/args.dart';
4+
import 'package:git/git.dart';
5+
import 'package:helper/helper.dart';
6+
import 'package:parser/parser.dart';
7+
import 'package:path/path.dart' as p;
8+
9+
void main(List<String> arguments) async {
10+
final parser = ArgParser()
11+
..addOption('path', mandatory: true)
12+
..addOption('api-key', mandatory: true);
13+
14+
final args = parser.parse(arguments);
15+
16+
final path = args['path'] as String;
17+
final apiKey = args['api-key'] as String;
18+
19+
if (await GitDir.isGitDir(p.current)) {
20+
final gitDir = await GitDir.fromExisting(
21+
p.current,
22+
allowSubdirectory: true,
23+
);
24+
final branch = await gitDir.currentBranch();
25+
26+
// final status = await gitDir.runCommand(['status']);
27+
// final asString = status.stdout as String;
28+
29+
final branchName = branch.branchName;
30+
final sha = branch.sha;
31+
32+
final directory = Directory(path);
33+
34+
final file = WidgetbookZipEncoder().encode(directory);
35+
if (file != null) {
36+
await WidgetbookHttpClient().uploadDeployment(
37+
deploymentFile: file,
38+
data: DeploymentData(
39+
branchName: branchName,
40+
repositoryName: '',
41+
commitSha: sha,
42+
actor: '',
43+
apiKey: apiKey,
44+
provider: 'CLI',
45+
),
46+
);
47+
} else {
48+
print('Could not create .zip file for upload.');
49+
}
50+
} else {
51+
print('Please make sure to execute this CLI within a git folder.');
52+
}
53+
}

packages/cli/pubspec.lock

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Generated by pub
2+
# See https://dart.dev/tools/pub/glossary#lockfile
3+
packages:
4+
archive:
5+
dependency: transitive
6+
description:
7+
name: archive
8+
url: "https://pub.dartlang.org"
9+
source: hosted
10+
version: "3.2.1"
11+
args:
12+
dependency: "direct main"
13+
description:
14+
name: args
15+
url: "https://pub.dartlang.org"
16+
source: hosted
17+
version: "2.3.0"
18+
charcode:
19+
dependency: transitive
20+
description:
21+
name: charcode
22+
url: "https://pub.dartlang.org"
23+
source: hosted
24+
version: "1.3.1"
25+
collection:
26+
dependency: transitive
27+
description:
28+
name: collection
29+
url: "https://pub.dartlang.org"
30+
source: hosted
31+
version: "1.15.0"
32+
crypto:
33+
dependency: transitive
34+
description:
35+
name: crypto
36+
url: "https://pub.dartlang.org"
37+
source: hosted
38+
version: "3.0.1"
39+
dio:
40+
dependency: transitive
41+
description:
42+
name: dio
43+
url: "https://pub.dartlang.org"
44+
source: hosted
45+
version: "4.0.4"
46+
git:
47+
dependency: "direct main"
48+
description:
49+
name: git
50+
url: "https://pub.dartlang.org"
51+
source: hosted
52+
version: "2.0.0"
53+
helper:
54+
dependency: "direct main"
55+
description:
56+
path: "../helper"
57+
relative: true
58+
source: path
59+
version: "0.0.0"
60+
http_parser:
61+
dependency: transitive
62+
description:
63+
name: http_parser
64+
url: "https://pub.dartlang.org"
65+
source: hosted
66+
version: "4.0.0"
67+
lints:
68+
dependency: "direct dev"
69+
description:
70+
name: lints
71+
url: "https://pub.dartlang.org"
72+
source: hosted
73+
version: "1.0.1"
74+
parser:
75+
dependency: "direct main"
76+
description:
77+
path: "../parser"
78+
relative: true
79+
source: path
80+
version: "1.0.0"
81+
path:
82+
dependency: transitive
83+
description:
84+
name: path
85+
url: "https://pub.dartlang.org"
86+
source: hosted
87+
version: "1.8.1"
88+
source_span:
89+
dependency: transitive
90+
description:
91+
name: source_span
92+
url: "https://pub.dartlang.org"
93+
source: hosted
94+
version: "1.8.2"
95+
string_scanner:
96+
dependency: transitive
97+
description:
98+
name: string_scanner
99+
url: "https://pub.dartlang.org"
100+
source: hosted
101+
version: "1.1.0"
102+
term_glyph:
103+
dependency: transitive
104+
description:
105+
name: term_glyph
106+
url: "https://pub.dartlang.org"
107+
source: hosted
108+
version: "1.2.0"
109+
typed_data:
110+
dependency: transitive
111+
description:
112+
name: typed_data
113+
url: "https://pub.dartlang.org"
114+
source: hosted
115+
version: "1.3.0"
116+
sdks:
117+
dart: ">=2.15.0 <3.0.0"

0 commit comments

Comments
 (0)