Compare commits

...

3 commits

Author SHA1 Message Date
Patrick Stewart
c7e69edcfc add: adding support for custom after prompts 2024-10-27 22:55:11 -07:00
Patrick Stewart
a63b2097a4 add: adding support for creating dart/flutter packages 2024-10-27 22:54:30 -07:00
Patrick Stewart
d17bfcf09a add: adding support for building apps in the monorepo 2024-10-27 22:53:50 -07:00
8 changed files with 152 additions and 46 deletions

View file

@ -1,6 +1,7 @@
name: protevus_platform name: protevus_platform
repository: https://github.com/protevus/platform repository: https://github.com/protevus/platform
packages: packages:
- apps/**
- packages/** - packages/**
- examples/** - examples/**

View file

@ -1,5 +1,5 @@
scripts: scripts:
_: &workflow_scripts _: &create_scripts
clean: clean:
run: > run: >
melos exec -c 1 --fail-fast -- " melos exec -c 1 --fail-fast -- "

24
.melos/create.yaml Normal file
View file

@ -0,0 +1,24 @@
scripts:
_: &create_scripts
create:
name: Create new package or application
description: |
Creates a new Dart package or Flutter application in the appropriate directory.
Usage: melos run create -- --type dart|flutter --category type --name project_name
Available categories for Dart:
- package : Basic Dart package
- console : Command-line application
- server : Server-side application
- desktop : Desktop application
- plugin : Dart plugin
Available categories for Flutter:
- app : Mobile application
- web : Web application
- desktop : Desktop application
- plugin : Flutter plugin
- module : Flutter module
- package : Flutter package
run: dart run helpers/create_project.dart $MELOS_ARGS

121
helpers/create_project.dart Normal file
View file

@ -0,0 +1,121 @@
import 'dart:io';
void main(List<String> args) async {
// Parse command line arguments
String? projectType;
String? category;
String? name;
for (var arg in args) {
final parts = arg.split(':');
if (parts.length == 2) {
switch (parts[0]) {
case 'project_type':
case 'project-type':
projectType = parts[1];
break;
case 'category':
category = parts[1];
break;
case 'name':
name = parts[1];
break;
}
}
}
// Print received arguments for debugging
print('Received arguments:');
print('Project Type: $projectType');
print('Category: $category');
print('Name: $name');
// Validate inputs
if (projectType == null || category == null || name == null) {
print('Error: Missing required arguments');
print(
'Usage: melos run create project_type:dart|flutter category:type name:project_name');
exit(1);
}
if (projectType != 'dart' && projectType != 'flutter') {
print('Error: project_type must be either "dart" or "flutter"');
exit(1);
}
// Determine base directory
final baseDir = projectType == 'flutter' &&
(category == 'app' || category == 'web' || category == 'desktop')
? 'apps'
: 'packages';
// Create project directory
final projectDir = Directory('$baseDir/$name');
if (await projectDir.exists()) {
print('Error: Project directory already exists at ${projectDir.path}');
exit(1);
}
try {
// Ensure the base directory exists
await Directory(baseDir).create(recursive: true);
// Create the project using the appropriate command
final result = await Process.run(
projectType,
[
'create',
if (projectType == 'flutter') ...[
'--org',
'com.example',
'--project-name',
name,
if (category == 'plugin') '--template=plugin',
if (category == 'package') '--template=package',
if (category == 'module') '--template=module',
if (category == 'web') '--platforms=web',
if (category == 'desktop') '--platforms=windows,macos,linux',
] else ...[
if (category == 'package') '--template=package',
if (category == 'console') '--template=console',
if (category == 'server') '--template=server-shelf',
],
projectDir.path,
],
);
if (result.exitCode != 0) {
print('Error creating project:');
print(result.stderr);
exit(1);
}
print('Successfully created $projectType project at ${projectDir.path}');
// Add additional dependencies based on category
if (category == 'server') {
await Process.run('dart', ['pub', 'add', 'shelf_router'],
workingDirectory: projectDir.path);
await Process.run('dart', ['pub', 'add', 'dotenv'],
workingDirectory: projectDir.path);
await Process.run('dart', ['pub', 'add', 'logger'],
workingDirectory: projectDir.path);
}
if (category == 'desktop') {
await Process.run('dart', ['pub', 'add', 'window_manager'],
workingDirectory: projectDir.path);
await Process.run('dart', ['pub', 'add', 'screen_retriever'],
workingDirectory: projectDir.path);
}
// Format the project
await Process.run('dart', ['format', projectDir.path]);
print('Done! 🎉');
print('To get started, cd into ${projectDir.path}');
} catch (e) {
print('Error: $e');
exit(1);
}
}

View file

@ -11,6 +11,7 @@
name: protevus_platform name: protevus_platform
repository: https://github.com/protevus/platform repository: https://github.com/protevus/platform
packages: packages:
- apps/**
- packages/** - packages/**
- examples/** - examples/**
@ -80,6 +81,10 @@ scripts:
test:custom: test:custom:
run: melos exec --scope="$MELOS_SCOPE" -- dart test run: melos exec --scope="$MELOS_SCOPE" -- dart test
description: Run tests for specified packages (use with MELOS_SCOPE env var) description: Run tests for specified packages (use with MELOS_SCOPE env var)
create:
name: Create new package or application
description: "Creates a new Dart package or Flutter application in the appropriate directory.\n\nUsage: melos run create -- --type dart|flutter --category type --name project_name\n\nAvailable categories for Dart:\n - package : Basic Dart package\n - console : Command-line application\n - server : Server-side application\n - desktop : Desktop application\n - plugin : Dart plugin\n\nAvailable categories for Flutter:\n - app : Mobile application\n - web : Web application\n - desktop : Desktop application\n - plugin : Flutter plugin\n - module : Flutter module\n - package : Flutter package\n"
run: dart run helpers/create_project.dart $MELOS_ARGS
deps:check: deps:check:
run: melos exec -- "dart pub outdated" run: melos exec -- "dart pub outdated"
description: Check for outdated dependencies description: Check for outdated dependencies

View file

@ -1,45 +0,0 @@
#!/bin/bash
# Check if the correct number of arguments is provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <project_name> <project_type>"
echo "Project types: package, web, console"
exit 1
fi
# Assign arguments to variables
PROJECT_NAME=$1
PROJECT_TYPE=$2
# Set the base directory for packages
PACKAGES_DIR="$HOME/Devboxes/platform/packages"
# Create the packages directory if it doesn't exist
mkdir -p "$PACKAGES_DIR"
# Change to the packages directory
cd "$PACKAGES_DIR"
# Validate project type
case $PROJECT_TYPE in
package|web|console)
;;
*)
echo "Invalid project type. Use 'package', 'web', or 'console'."
exit 1
;;
esac
# Create the Dart project
dart create --template=$PROJECT_TYPE $PROJECT_NAME
# Check if the project was created successfully
if [ $? -eq 0 ]; then
echo "Dart $PROJECT_TYPE project '$PROJECT_NAME' created successfully in $PACKAGES_DIR/$PROJECT_NAME"
else
echo "Failed to create the Dart project."
exit 1
fi
# Change into the project directory
cd "$PROJECT_NAME"