refactor: improve build configuration and code organization

- Add build scripts for Android and iOS platforms
- Remove duplicate web implementation (src/web.ts)
- Add proper TypeScript configuration
- Add module documentation to index.ts
- Clean up package.json scripts

This commit improves the project structure and build process by:
1. Adding dedicated build scripts for native platforms
2. Removing redundant web implementation
3. Adding proper TypeScript configuration with strict mode
4. Improving code documentation
5. Organizing package.json scripts

The changes maintain backward compatibility while improving
the development experience and code quality.
This commit is contained in:
Matthew Raymer
2025-03-25 13:13:55 +00:00
parent e946767cba
commit 71e0f297ff
92 changed files with 11523 additions and 69 deletions

146
scripts/build-native.sh Executable file
View File

@@ -0,0 +1,146 @@
#!/bin/bash
# Exit on error
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Validation functions
check_command() {
if ! command -v $1 &> /dev/null; then
log_error "$1 is not installed. Please install it first."
exit 1
fi
}
check_environment() {
# Check for required tools
check_command "node"
check_command "npm"
check_command "java"
check_command "gradle"
# Check Node.js version
NODE_VERSION=$(node -v | cut -d. -f1 | tr -d 'v')
if [ "$NODE_VERSION" -lt 14 ]; then
log_error "Node.js version 14 or higher is required"
exit 1
fi
# Check Java version
JAVA_VERSION=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2 | cut -d. -f1)
if [ "$JAVA_VERSION" -lt 11 ]; then
log_error "Java version 11 or higher is required"
exit 1
fi
# Check for Android SDK
if [ -z "$ANDROID_HOME" ]; then
log_error "ANDROID_HOME environment variable is not set"
exit 1
fi
}
# Build functions
build_typescript() {
log_info "Building TypeScript..."
npm run clean
if ! npm run build; then
log_error "TypeScript build failed"
exit 1
fi
}
build_android() {
log_info "Building Android..."
cd android || exit 1
# Check for gradle wrapper
if [ ! -f "./gradlew" ]; then
log_error "Gradle wrapper not found"
exit 1
fi
# Clean and build
if ! ./gradlew clean; then
log_error "Android clean failed"
exit 1
fi
if ! ./gradlew assembleRelease; then
log_error "Android build failed"
exit 1
fi
# Verify AAR file exists
AAR_FILE="build/outputs/aar/daily-notification-release.aar"
if [ ! -f "$AAR_FILE" ]; then
log_error "AAR file not found at $AAR_FILE"
exit 1
fi
log_info "Android build successful: $AAR_FILE"
cd ..
}
# Main build process
main() {
log_info "Starting build process..."
# Parse command line arguments
BUILD_PLATFORM="all"
while [[ $# -gt 0 ]]; do
case $1 in
--platform)
BUILD_PLATFORM="$2"
shift 2
;;
*)
log_error "Unknown option: $1"
exit 1
;;
esac
done
# Check environment
check_environment
# Build TypeScript
build_typescript
# Build based on platform
case $BUILD_PLATFORM in
"android")
build_android
;;
"all")
build_android
;;
*)
log_error "Invalid platform: $BUILD_PLATFORM. Use 'android' or 'all'"
exit 1
;;
esac
log_info "Build completed successfully!"
}
# Run main function with all arguments
main "$@"

View File

@@ -0,0 +1,123 @@
/**
* Environment check script for the Daily Notification plugin
* Validates that all required tools and dependencies are installed
*/
const { execSync } = require('child_process');
const os = require('os');
// Constants
const REQUIRED_NODE_VERSION = 14;
const REQUIRED_JAVA_VERSION = 11;
// Colors for output
const GREEN = '\x1b[32m';
const YELLOW = '\x1b[33m';
const RED = '\x1b[31m';
const RESET = '\x1b[0m';
// Logging functions
const log = {
info: (msg) => console.log(`🔍 ${msg}`),
success: (msg) => console.log(`${GREEN}${msg}${RESET}`),
warn: (msg) => console.log(`${YELLOW}⚠️ ${msg}${RESET}`),
error: (msg) => console.log(`${RED}${msg}${RESET}`)
};
// Check if a command exists
function commandExists(command) {
try {
execSync(`which ${command}`, { stdio: 'ignore' });
return true;
} catch {
return false;
}
}
// Get Node.js version
function checkNodeVersion() {
const version = process.version.match(/^v(\d+)/)[1];
if (version < REQUIRED_NODE_VERSION) {
throw new Error(`Node.js version ${REQUIRED_NODE_VERSION} or higher is required`);
}
log.success(`Node.js: v${version}`);
}
// Check npm
function checkNpm() {
if (!commandExists('npm')) {
throw new Error('npm is not installed');
}
log.success('npm is installed');
}
// Get Java version
function checkJava() {
try {
const output = execSync('java -version 2>&1').toString();
const version = output.match(/version "(\d+)/)[1];
if (version < REQUIRED_JAVA_VERSION) {
throw new Error(`Java version ${REQUIRED_JAVA_VERSION} or higher is required`);
}
log.success(`Java: version ${version}`);
} catch (error) {
throw new Error('Java is not installed or invalid version');
}
}
// Check Android environment
function checkAndroid() {
if (!process.env.ANDROID_HOME) {
throw new Error('ANDROID_HOME environment variable is not set');
}
log.success('Android environment is properly configured');
}
// Main function
async function main() {
log.info('Checking development environment...\n');
let hasErrors = false;
try {
checkNodeVersion();
checkNpm();
checkJava();
checkAndroid();
} catch (error) {
log.error(error.message);
hasErrors = true;
}
// Check iOS requirements only on macOS
if (os.platform() === 'darwin') {
try {
if (!commandExists('xcodebuild')) {
log.error('Xcode is not installed');
hasErrors = true;
} else {
log.success('Xcode is installed');
}
} catch (error) {
log.error('Failed to check Xcode installation');
hasErrors = true;
}
} else {
log.warn('iOS development requires macOS');
}
console.log(''); // Empty line for readability
// Exit with appropriate code
if (hasErrors && os.platform() === 'darwin') {
log.error('Environment check failed. Please fix the issues above.');
process.exit(1);
} else {
log.success('Environment check completed successfully for the current platform.');
process.exit(0);
}
}
main().catch(error => {
log.error('Unexpected error:', error);
process.exit(1);
});

1
scripts/setup-gradle.sh Executable file
View File

@@ -0,0 +1 @@

72
scripts/setup-native.js Normal file
View File

@@ -0,0 +1,72 @@
/**
* Setup script for native dependencies
* Configures native build environments and dependencies
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
function setupAndroid() {
console.log('🔧 Setting up Android environment...');
// Create gradle wrapper if it doesn't exist
const gradleWrapper = path.join('android', 'gradlew');
if (!fs.existsSync(gradleWrapper)) {
console.log('Creating Gradle wrapper...');
execSync('cd android && gradle wrapper', { stdio: 'inherit' });
}
// Make gradle wrapper executable
fs.chmodSync(gradleWrapper, '755');
// Create local.properties if it doesn't exist
const localProperties = path.join('android', 'local.properties');
if (!fs.existsSync(localProperties)) {
const androidHome = process.env.ANDROID_HOME;
if (androidHome) {
const content = `sdk.dir=${androidHome.replace(/\\/g, '\\\\')}\n`;
fs.writeFileSync(localProperties, content);
console.log('Created local.properties');
}
}
// Sync Gradle
console.log('Syncing Gradle...');
execSync('cd android && ./gradlew --refresh-dependencies', { stdio: 'inherit' });
}
function setupIOS() {
if (process.platform !== 'darwin') {
console.warn('⚠️ Skipping iOS setup (macOS required)');
return;
}
console.log('🔧 Setting up iOS environment...');
// Install pods
console.log('Installing CocoaPods dependencies...');
execSync('cd ios && pod install', { stdio: 'inherit' });
// Create Xcode project if it doesn't exist
const xcodeProject = path.join('ios', 'DailyNotificationPlugin.xcodeproj');
if (!fs.existsSync(xcodeProject)) {
console.log('Creating Xcode project...');
execSync('cd ios && pod setup', { stdio: 'inherit' });
}
}
function main() {
console.log('🚀 Setting up native development environment...\n');
try {
setupAndroid();
setupIOS();
console.log('\n✅ Native environment setup completed successfully!');
} catch (error) {
console.error('\n❌ Native environment setup failed:', error.message);
process.exit(1);
}
}
main();