Skip to content

Commit c284da5

Browse files
all react_native cli has been implemented with the version of 1.6.0
1 parent 04d2dcf commit c284da5

File tree

10 files changed

+75
-43
lines changed

10 files changed

+75
-43
lines changed

lib/commands/add/add_component.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import 'dart:convert';
22
import 'dart:io';
3-
4-
import 'package:cli_spin/cli_spin.dart';
53
import 'package:cwa_plugin_core/cwa_plugin_core.dart';
64
import 'package:react_native/config/plugin_config.dart';
75

86
import '../../model/specification.dart';
7+
import '../../utils/cli_spinner.dart';
98
import '../../utils/download_manager.dart';
109

1110
class ReactNativeComponent extends Command {
@@ -53,8 +52,8 @@ class ReactNativeComponent extends Command {
5352
}
5453

5554
Future<void> _handleComponentAndSpecification(String componentName) async {
56-
CliSpin featureLoader =
57-
CliSpin(text: "Adding $componentName to the project").start();
55+
SimpleSpinner spinner = SimpleSpinner();
56+
spinner.start("Adding $componentName to the project");
5857

5958
try {
6059
String filePath = 'specification_config.json';
@@ -88,12 +87,12 @@ class ReactNativeComponent extends Command {
8887

8988
await SpecificationUpdater.updateSpecifications(componentName);
9089

91-
featureLoader.success();
90+
spinner.stop(isSuccess: true);
9291
} else {
9392
CWLogger.i.trace('Failed to fetch specification_config.json');
9493
}
9594
} catch (e) {
96-
featureLoader.fail();
95+
spinner.stop(isSuccess: false);
9796
CWLogger.namedLog(
9897
e.toString(),
9998
loggerColor: CWLoggerColor.red,

lib/commands/add/add_features.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import 'dart:convert';
22
import 'dart:io';
3-
4-
import 'package:cli_spin/cli_spin.dart';
53
import 'package:cwa_plugin_core/cwa_plugin_core.dart';
64
import 'package:react_native/config/plugin_config.dart';
7-
5+
import 'package:react_native/utils/cli_spinner.dart';
86
import '../../model/specification.dart';
97
import '../../utils/download_manager.dart';
108

@@ -56,8 +54,8 @@ class ReactNativeFeature extends Command {
5654
}
5755

5856
Future<void> _handleFeatureAndSpecification(String featureName) async {
59-
CliSpin featureLoader =
60-
CliSpin(text: "Adding $featureName to the project").start();
57+
SimpleSpinner spinner=SimpleSpinner();
58+
spinner.start("Adding $featureName to the project");
6159

6260
try {
6361
String filePath = 'specification_config.json';
@@ -91,12 +89,12 @@ class ReactNativeFeature extends Command {
9189

9290
await SpecificationUpdater.updateSpecifications(featureName);
9391

94-
featureLoader.success();
92+
spinner.stop(isSuccess: true);
9593
} else {
9694
CWLogger.i.trace('Failed to fetch specification_config.json');
9795
}
9896
} catch (e) {
99-
featureLoader.fail();
97+
spinner.stop(isSuccess: false);
10098
CWLogger.i.trace(
10199
'Error downloading Feature $featureName or updating specifications: $e');
102100
}

lib/commands/add/add_service.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import 'dart:convert';
22
import 'dart:io';
3-
4-
import 'package:cli_spin/cli_spin.dart';
53
import 'package:cwa_plugin_core/cwa_plugin_core.dart';
64
import 'package:react_native/config/plugin_config.dart';
7-
5+
import 'package:react_native/utils/cli_spinner.dart';
86
import '../../model/specification.dart';
97
import '../../utils/download_manager.dart';
108

@@ -54,8 +52,8 @@ class ReactNativeService extends Command {
5452
}
5553

5654
Future<void> _handleServiceAndSpecification(String serviceName) async {
57-
CliSpin featureLoader =
58-
CliSpin(text: "Adding $serviceName to the project").start();
55+
SimpleSpinner spinner=SimpleSpinner();
56+
spinner.start("Adding $serviceName to the project");
5957

6058
try {
6159
String filePath = 'specification_config.json';
@@ -89,12 +87,12 @@ class ReactNativeService extends Command {
8987

9088
await SpecificationUpdater.updateSpecifications(serviceName);
9189

92-
featureLoader.success();
90+
spinner.stop(isSuccess: true);
9391
} else {
9492
CWLogger.i.trace('Failed to fetch specification_config.json');
9593
}
9694
} catch (e) {
97-
featureLoader.fail();
95+
spinner.stop(isSuccess: false);
9896
CWLogger.namedLog(
9997
e.toString(),
10098
loggerColor: CWLoggerColor.red,

lib/commands/add/add_utils.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1+
import 'dart:async';
12
import 'dart:convert';
23
import 'dart:io';
3-
4-
import 'package:cli_spin/cli_spin.dart';
54
import 'package:cwa_plugin_core/cwa_plugin_core.dart';
65
import 'package:react_native/config/plugin_config.dart';
7-
86
import '../../model/specification.dart';
7+
import '../../utils/cli_spinner.dart';
98
import '../../utils/download_manager.dart';
10-
119
class ReactNativeUtils extends Command {
1210
ReactNativeUtils(super.args);
1311

@@ -54,8 +52,11 @@ class ReactNativeUtils extends Command {
5452
}
5553

5654
Future<void> _handleUtilityAndSpecification(String utilityName) async {
57-
CliSpin featureLoader =
58-
CliSpin(text: "Adding $utilityName to the project").start();
55+
SimpleSpinner spinner = SimpleSpinner();
56+
57+
spinner.start("Adding $utilityName to the project");
58+
59+
CWLogger.namedLog("message check whether one time call or not");
5960

6061
try {
6162
String filePath = 'specification_config.json';
@@ -69,18 +70,15 @@ class ReactNativeUtils extends Command {
6970
if (specsFileContent != null) {
7071
Map<String, dynamic> specificationData = json.decode(specsFileContent);
7172

72-
// Get the filePath and folderPath from the config
7373
List<dynamic> utilityFilePaths = specificationData['filePath'] ?? [];
7474
List<dynamic> utilityFolderPaths = specificationData['folderPath'] ?? [];
7575

76-
// Handle file paths if available
7776
if (utilityFilePaths.isNotEmpty) {
7877
for (String utilityFilePath in utilityFilePaths) {
7978
await downloadManager.downloadFile(utilityFilePath, utilityName);
8079
}
8180
}
8281

83-
// Handle folder paths if available
8482
if (utilityFolderPaths.isNotEmpty) {
8583
for (String utilityFolderPath in utilityFolderPaths) {
8684
await downloadManager.downloadDirectory(utilityFolderPath, utilityName);
@@ -89,15 +87,15 @@ class ReactNativeUtils extends Command {
8987

9088
await SpecificationUpdater.updateSpecifications(utilityName);
9189

92-
featureLoader.success();
90+
spinner.stop(isSuccess: true);
9391
} else {
9492
CWLogger.i.trace('Failed to fetch specification_config.json');
93+
spinner.stop(isSuccess: false);
9594
}
9695
} catch (e) {
97-
featureLoader.fail();
96+
spinner.stop(isSuccess: false);
9897
CWLogger.i.trace(
9998
'Error downloading utility $utilityName or updating specifications: $e');
10099
}
101100
}
102-
103101
}

lib/commands/init/init.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import 'dart:convert';
22
import 'dart:io';
3-
import 'package:cli_spin/cli_spin.dart';
43
import 'package:cwa_plugin_core/cwa_plugin_core.dart';
54
import '../../config/plugin_config.dart';
65
import '../../config/runtime_config.dart';
6+
import '../../utils/cli_spinner.dart';
77
import '../../utils/package_json.dart'; // Import the new utils file
88

99
class ReactNativeInit extends Command {
@@ -19,6 +19,7 @@ class ReactNativeInit extends Command {
1919
Future<void> run() async {
2020

2121
String branch = 'main';
22+
SimpleSpinner spinner = SimpleSpinner();
2223

2324
List<String>? branches = await GitService.getGitLabBranches(
2425
ReactNativeConfig.i.archManagerProjectID,
@@ -33,9 +34,7 @@ class ReactNativeInit extends Command {
3334
exit(1);
3435
}
3536
await _createTimestampConfigFile();
36-
CliSpin loader = CliSpin(
37-
text: "Adapting architecture $branch in the project")
38-
.start();
37+
spinner.start("Adapting architecture $branch in the project");
3938

4039
List<String> directoriesToDownload = [
4140
'components', 'hooks', 'service', 'redux', 'patches', 'utils', 'apiService', 'config', 'constants'
@@ -86,8 +85,7 @@ class ReactNativeInit extends Command {
8685
ReactNativeConfig.i.archManagerProjectID,
8786
branch
8887
);
89-
90-
loader.success("Project now follows the selected architecture");
88+
spinner.stop(isSuccess: true,successMessage: "Project now follows the selected architecture");
9189

9290
return;
9391
}

lib/config/plugin_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ class ReactNativeConfig extends PluginConfig {
2121
PluginEnvironment get pluginEnvironment => PluginEnvironment.prod;
2222

2323
@override
24-
Version get version => Version.parse("1.5.0");
24+
Version get version => Version.parse("1.6.0");
2525
}

lib/react_native.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ReactNative extends Plugin {
1212
String get pluginName => 'react_native';
1313

1414
@override
15-
Version get version => Version.parse("1.5.0");
15+
Version get version => Version.parse("1.6.0");
1616

1717
@override
1818
String get alias => 'rn';

lib/utils/cli_spinner.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import 'dart:async';
2+
import 'dart:io';
3+
4+
class SimpleSpinner {
5+
final List<String> _spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
6+
int _frameIndex = 0;
7+
late Timer _timer;
8+
bool _isRunning = false;
9+
10+
final String _green = '\x1B[32m'; // Green color
11+
final String _red = '\x1B[31m'; // Red color
12+
final String _reset = '\x1B[0m'; // Reset color to default
13+
14+
void start(String message) {
15+
if (_isRunning) return; // Prevent starting the spinner if it's already running
16+
17+
_isRunning = true;
18+
stdout.write(message);
19+
20+
_timer = Timer.periodic(Duration(milliseconds: 100), (timer) {
21+
stdout.write('\r${_spinnerFrames[_frameIndex]} $message');
22+
_frameIndex = (_frameIndex + 1) % _spinnerFrames.length; // Loop through spinner frames
23+
});
24+
}
25+
26+
// Stop the spinner and show custom success or failure message with colors
27+
void stop({bool isSuccess = true, String successMessage = 'Done!', String failureMessage = 'Failed!'}) {
28+
if (!_isRunning) return; // If spinner isn't running, no need to stop
29+
30+
_isRunning = false;
31+
_timer.cancel();
32+
33+
// Use the provided messages, or default ones if empty
34+
String message = isSuccess ? successMessage : failureMessage;
35+
36+
if (isSuccess) {
37+
stdout.write('\r$_green✔ $message$_reset \n');
38+
} else {
39+
stdout.write('\r$_red❌ $message$_reset \n');
40+
}
41+
}
42+
}

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ packages:
9898
source: hosted
9999
version: "0.2.0"
100100
cli_spin:
101-
dependency: "direct main"
101+
dependency: transitive
102102
description:
103103
name: cli_spin
104104
sha256: d942e605e508820b8bde1cfc26f19810abd6bd6bfa32a4f049c9ebaaccbddb50

pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: react_native
2-
version: 1.5.0
2+
version: 1.6.0
33
description: A sample command-line application.
44
environment:
55
sdk: ^3.2.0
@@ -12,7 +12,6 @@ dependencies:
1212
git:
1313
url: git@gitlab.com-codewave:codewave-technologies/codewave-flutter-core.git
1414
ref: main
15-
cli_spin: ^1.0.1
1615
process_run: ^0.12.4
1716

1817
dev_dependencies:

0 commit comments

Comments
 (0)