andrud 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Command registration and main CLI entry point
3
+ */
4
+
5
+ import { cac } from 'cac';
6
+ import pc from 'picocolors';
7
+ import { createCommand } from './commands/create.js';
8
+ import { createNewCommand } from './commands/new.js';
9
+ import { createInitCommand } from './commands/init.js';
10
+ import { createInfoCommand } from './commands/info.js';
11
+ import { createListCommand } from './commands/list.js';
12
+
13
+ const pkg = { version: '1.0.0' };
14
+
15
+ const cli = cac('andrud');
16
+
17
+ cli.version(pkg.version);
18
+
19
+ // Clean minimal help
20
+ function printHelp(): void {
21
+ console.log('');
22
+ console.log(` ${pc.cyan('andrud')} - Android Project Scaffolding`);
23
+ console.log('');
24
+ console.log(` ${pc.gray('andrud create')} Create a new project`);
25
+ console.log(` ${pc.gray('andrud list')} Show available templates`);
26
+ console.log(` ${pc.gray('andrud info <template>')} View template details`);
27
+ console.log('');
28
+ console.log(` ${pc.gray('andrud create MyApp')} Create with name`);
29
+ console.log('');
30
+ }
31
+
32
+ // Commands
33
+ cli
34
+ .command('create', 'Create a new Android project')
35
+ .alias('c')
36
+ .option('-f, --force', 'Overwrite existing files')
37
+ .example('andrud create')
38
+ .example('andrud create --force')
39
+ .action(createCommand);
40
+
41
+ cli
42
+ .command('new [name]', 'Create a new project')
43
+ .alias('n')
44
+ .option('-t, --template <type>', 'Template type')
45
+ .option('-p, --package <name>', 'Package name')
46
+ .option('-f, --force', 'Overwrite')
47
+ .example('andrud new MyApp -t kotlin-compose')
48
+ .action(createNewCommand);
49
+
50
+ cli
51
+ .command('init', 'Initialize in current directory')
52
+ .alias('i')
53
+ .option('-f, --force', 'Overwrite')
54
+ .example('andrud init')
55
+ .action(createInitCommand);
56
+
57
+ cli
58
+ .command('info [template]', 'Show template info')
59
+ .example('andrud info kotlin-compose')
60
+ .action(createInfoCommand);
61
+
62
+ cli
63
+ .command('list', 'List all templates')
64
+ .alias('ls')
65
+ .option('--json', 'Output as JSON')
66
+ .action(createListCommand);
67
+
68
+ cli.on('command:!', () => {
69
+ console.error(pc.red(` Unknown command. See ${pc.cyan('--help')}\n`));
70
+ });
71
+
72
+ process.on('uncaughtException', (error) => {
73
+ console.error(pc.red(` ${error.message}\n`));
74
+ process.exit(1);
75
+ });
76
+
77
+ process.on('unhandledRejection', (reason) => {
78
+ console.error(pc.red(` ${reason}\n`));
79
+ process.exit(1);
80
+ });
81
+
82
+ export function runCli(): void {
83
+ try {
84
+ const args = process.argv.slice(2);
85
+
86
+ // Show help
87
+ if (args.includes('--help') || args.includes('-h')) {
88
+ printHelp();
89
+ return;
90
+ }
91
+
92
+ // Show version
93
+ if (args.includes('--version') || args.includes('-V')) {
94
+ console.log(pkg.version);
95
+ return;
96
+ }
97
+
98
+ // Quick help on no args
99
+ if (args.length === 0) {
100
+ console.log('');
101
+ console.log(` ${pc.cyan('andrud')} - Create Android projects`);
102
+ console.log('');
103
+ console.log(` ${pc.gray('andrud create')} Start interactive setup`);
104
+ console.log(` ${pc.gray('andrud --help')} Show all commands`);
105
+ console.log('');
106
+ return;
107
+ }
108
+
109
+ cli.parse(process.argv, { run: true });
110
+ } catch (error) {
111
+ console.error(pc.red(` ${(error as Error).message}\n`));
112
+ process.exit(1);
113
+ }
114
+ }
115
+
116
+ // Note: runCli() is called from bin/andrud.js
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Configuration constants for Android and Gradle versions
3
+ */
4
+
5
+ /**
6
+ * Default Android SDK configuration
7
+ */
8
+ export const ANDROID_SDK_DEFAULTS = {
9
+ MIN_SDK: 24,
10
+ TARGET_SDK: 36,
11
+ COMPILE_SDK: 36,
12
+ BUILD_TOOLS_VERSION: '36.0.0'
13
+ };
14
+
15
+ /**
16
+ * Gradle-related versions
17
+ */
18
+ export const GRADLE_VERSIONS = {
19
+ AGP: '8.7.3',
20
+ GRADLE: '8.14',
21
+ KOTLIN: '2.0.21',
22
+ COMPOSE_COMPILER: '1.5.14',
23
+ COMPOSE_BOM: '2024.09.03',
24
+ NDK: '28.2.13676358'
25
+ };
26
+
27
+ /**
28
+ * AndroidX library versions
29
+ */
30
+ export const ANDROIDX_VERSIONS = {
31
+ CORE_KTX: '1.15.0',
32
+ APP_COMPAT: '1.7.0',
33
+ MATERIAL: '1.12.0',
34
+ LIFECYCLE: '2.8.7',
35
+ ACTIVITY: '1.9.3',
36
+ CONSTRAINT_LAYOUT: '2.2.0',
37
+ RECYCLER_VIEW: '1.3.2',
38
+ CARD_VIEW: '1.0.0',
39
+ SWIPE_REFRESH: '1.1.0',
40
+ NAVIGATION: '2.8.4',
41
+ ROOM: '2.6.1',
42
+ WORK: '2.10.0',
43
+ HILT: '2.52'
44
+ };
45
+
46
+ /**
47
+ * Compose versions
48
+ */
49
+ export const COMPOSE_VERSIONS = {
50
+ BOM: '2025.01.00',
51
+ UI: '1.3.0',
52
+ UI_GRAPHICS: '1.3.0',
53
+ UI_TOOLING: '1.3.0',
54
+ MATERIAL3: '1.3.0',
55
+ MATERIAL_ICONS: '1.3.0',
56
+ FOUNDATION: '1.3.0',
57
+ ACTIVITY: '1.9.3',
58
+ LIFECYCLE: '2.8.7',
59
+ NAVIGATION: '2.8.4'
60
+ };
61
+
62
+ /**
63
+ * Default Gradle properties for Android projects
64
+ */
65
+ export function getDefaultGradleProperties(): Record<string, string | number | boolean> {
66
+ return {
67
+ 'org.gradle.jvmargs': '-Xmx2048m -Dfile.encoding=UTF-8',
68
+ 'android.useAndroidX': true,
69
+ 'android.enableJetifier': true,
70
+ 'kotlin.code.style': 'official',
71
+ 'org.gradle.parallel': true,
72
+ 'org.gradle.caching': true,
73
+ 'org.gradle.configureondemand': true,
74
+ 'android.nonTransitiveRClass': true,
75
+ 'android.defaults.buildfeatures.buildconfig': true
76
+ };
77
+ }
78
+
79
+ /**
80
+ * Get recommended minimum SDK based on year
81
+ */
82
+ export function getRecommendedMinSdk(): number {
83
+ return 24; // Android 7.0 Nougat
84
+ }
85
+
86
+ /**
87
+ * Get target SDK for a given year
88
+ */
89
+ export function getTargetSdkForYear(year: number): number {
90
+ // By default, target the latest stable SDK
91
+ if (year >= 2024) {
92
+ return 35; // Android 15
93
+ } else if (year >= 2023) {
94
+ return 34; // Android 14
95
+ } else if (year >= 2022) {
96
+ return 33; // Android 13
97
+ } else {
98
+ return 32; // Android 12L
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Template-specific configurations
104
+ */
105
+ export interface TemplateConfig {
106
+ language: 'kotlin' | 'java';
107
+ uiFramework: 'xml' | 'compose' | 'none';
108
+ minSdk: number;
109
+ targetSdk: number;
110
+ compileSdk: number;
111
+ kotlinVersion: string;
112
+ agpVersion: string;
113
+ gradleVersion: string;
114
+ composeEnabled: boolean;
115
+ ndkVersion?: string;
116
+ }
117
+
118
+ export const TEMPLATE_CONFIGS: Record<string, TemplateConfig> = {
119
+ 'kotlin-compose': {
120
+ language: 'kotlin',
121
+ uiFramework: 'compose',
122
+ minSdk: 31,
123
+ targetSdk: 36,
124
+ compileSdk: 36,
125
+ kotlinVersion: GRADLE_VERSIONS.KOTLIN,
126
+ agpVersion: GRADLE_VERSIONS.AGP,
127
+ gradleVersion: GRADLE_VERSIONS.GRADLE,
128
+ composeEnabled: true
129
+ },
130
+ 'kotlin-xml': {
131
+ language: 'kotlin',
132
+ uiFramework: 'xml',
133
+ minSdk: 31,
134
+ targetSdk: 36,
135
+ compileSdk: 36,
136
+ kotlinVersion: GRADLE_VERSIONS.KOTLIN,
137
+ agpVersion: GRADLE_VERSIONS.AGP,
138
+ gradleVersion: GRADLE_VERSIONS.GRADLE,
139
+ composeEnabled: false
140
+ },
141
+ 'java-xml': {
142
+ language: 'java',
143
+ uiFramework: 'xml',
144
+ minSdk: 31,
145
+ targetSdk: 36,
146
+ compileSdk: 36,
147
+ kotlinVersion: '', // Not used for Java
148
+ agpVersion: GRADLE_VERSIONS.AGP,
149
+ gradleVersion: GRADLE_VERSIONS.GRADLE,
150
+ composeEnabled: false
151
+ },
152
+ 'native-cpp': {
153
+ language: 'kotlin',
154
+ uiFramework: 'xml',
155
+ minSdk: 31,
156
+ targetSdk: 36,
157
+ compileSdk: 36,
158
+ kotlinVersion: GRADLE_VERSIONS.KOTLIN,
159
+ agpVersion: GRADLE_VERSIONS.AGP,
160
+ gradleVersion: GRADLE_VERSIONS.GRADLE,
161
+ composeEnabled: false,
162
+ ndkVersion: GRADLE_VERSIONS.NDK
163
+ }
164
+ };
165
+
166
+ /**
167
+ * Get template configuration
168
+ */
169
+ export function getTemplateConfig(template: string): TemplateConfig {
170
+ const config = TEMPLATE_CONFIGS[template];
171
+ return config ?? TEMPLATE_CONFIGS['kotlin-xml']!;
172
+ }
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Context builder for generating Android project context
3
+ */
4
+
5
+ import { camelCase, kebabCase, pascalCase, snakeCase } from '../utils/validation.js';
6
+ import { GRADLE_VERSIONS, ANDROID_SDK_DEFAULTS, getTemplateConfig } from './config.js';
7
+ import type { TemplateType, TemplateContext, AndroidSdkConfig, GradleConfig, ProjectFeatures, NativeCppConfig } from './types.js';
8
+
9
+ const GENERATOR_VERSION = '1.0.0';
10
+
11
+ /**
12
+ * Build default context from basic parameters
13
+ */
14
+ export function buildDefaultProjectContext(
15
+ appName: string,
16
+ packageName: string,
17
+ projectDirectory: string,
18
+ template: TemplateType,
19
+ features: Partial<ProjectFeatures> = {},
20
+ minSdk?: number,
21
+ targetSdk?: number
22
+ ): Omit<TemplateContext, 'packagePath' | 'appNameSnake' | 'appNameKebab' | 'appNamePascal' | 'appNameCamel' | 'appNameLower' | 'year' | 'generatorVersion'> {
23
+ // Determine language and UI framework from template
24
+ const isCompose = template === 'kotlin-compose';
25
+ const isNativeCpp = template === 'native-cpp';
26
+ const isKotlin = template !== 'java-xml';
27
+ const isXml = !isCompose;
28
+
29
+ // Get template config for version info
30
+ const templateConfig = getTemplateConfig(template);
31
+
32
+ // Create Android SDK config
33
+ const android: AndroidSdkConfig = {
34
+ minSdk: minSdk ?? templateConfig.minSdk,
35
+ targetSdk: targetSdk ?? templateConfig.targetSdk,
36
+ compileSdk: templateConfig.compileSdk,
37
+ buildToolsVersion: ANDROID_SDK_DEFAULTS.BUILD_TOOLS_VERSION
38
+ };
39
+
40
+ // Create Gradle config
41
+ const gradle: GradleConfig = {
42
+ agpVersion: templateConfig.agpVersion,
43
+ gradleVersion: templateConfig.gradleVersion,
44
+ kotlinVersion: isKotlin ? templateConfig.kotlinVersion : undefined,
45
+ composeCompilerVersion: isCompose ? GRADLE_VERSIONS.COMPOSE_COMPILER : undefined,
46
+ composeBomVersion: isCompose ? GRADLE_VERSIONS.COMPOSE_BOM : undefined
47
+ };
48
+
49
+ // Build project features
50
+ const projectFeatures: ProjectFeatures = {
51
+ git: features.git ?? true,
52
+ readme: features.readme ?? true,
53
+ androidX: features.androidX ?? true,
54
+ kotlinDsl: features.kotlinDsl ?? true,
55
+ adaptiveIcon: features.adaptiveIcon ?? true,
56
+ material3: isCompose || (features.material3 ?? true),
57
+ viewBinding: features.viewBinding ?? isXml,
58
+ dataBinding: features.dataBinding ?? false,
59
+ jetpackCompose: isCompose ? true : (features.jetpackCompose ?? false)
60
+ };
61
+
62
+ // Build native C++ config if needed
63
+ const nativeCpp: NativeCppConfig | undefined = isNativeCpp ? {
64
+ cppStandard: 'c++17',
65
+ ndkVersion: templateConfig.ndkVersion ?? GRADLE_VERSIONS.NDK,
66
+ stlType: 'c++_shared',
67
+ abiFilters: ['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64']
68
+ } : undefined;
69
+
70
+ // Build base context - spread features at top level to match TemplateContext (which extends ProjectFeatures)
71
+ const baseContext = {
72
+ appName,
73
+ packageName,
74
+ projectDirectory,
75
+ template,
76
+ language: templateConfig.language,
77
+ uiFramework: templateConfig.uiFramework,
78
+ android,
79
+ gradle,
80
+ ...projectFeatures,
81
+ nativeCpp
82
+ };
83
+
84
+ // Cast to Omit<TemplateContext, ...> for the fields that buildTemplateContext adds
85
+ const contextForBuildTemplate: Omit<TemplateContext, 'packagePath' | 'appNameSnake' | 'appNameKebab' | 'appNamePascal' | 'appNameCamel' | 'appNameLower' | 'year' | 'generatorVersion'> = baseContext as unknown as Omit<TemplateContext, 'packagePath' | 'appNameSnake' | 'appNameKebab' | 'appNamePascal' | 'appNameCamel' | 'appNameLower' | 'year' | 'generatorVersion'>;
86
+ return contextForBuildTemplate;
87
+ }
88
+
89
+ /**
90
+ * Build full template context with all derived values
91
+ */
92
+ export function buildTemplateContext(
93
+ context: {
94
+ appName: string;
95
+ packageName: string;
96
+ projectDirectory: string;
97
+ template: string;
98
+ uiFramework: string;
99
+ language: 'kotlin' | 'java';
100
+ android: { minSdk: number; targetSdk: number; compileSdk: number };
101
+ gradle: {
102
+ agpVersion: string;
103
+ gradleVersion: string;
104
+ kotlinVersion?: string;
105
+ composeCompilerVersion?: string;
106
+ composeBomVersion?: string;
107
+ };
108
+ features: Record<string, boolean>;
109
+ nativeCpp?: { cppStandard: string; ndkVersion?: string; stlType?: string; abiFilters?: string[] };
110
+ year?: string;
111
+ }
112
+ ): TemplateContext {
113
+ // Transform app name to various cases
114
+ const normalizedAppName = context.appName.replace(/\s+/g, '_');
115
+ const appNameSnake = snakeCase(context.appName);
116
+ const appNameKebab = kebabCase(context.appName);
117
+ const appNamePascal = pascalCase(context.appName);
118
+ const appNameCamel = camelCase(context.appName);
119
+ const appNameLower = context.appName.toLowerCase().replace(/\s+/g, '');
120
+
121
+ // Convert package name to path format (e.g., "com.example.myapp" -> "com/example/myapp")
122
+ const packagePath = context.packageName.replace(/\./g, '/');
123
+
124
+ // Get current year
125
+ const year = context.year ?? new Date().getFullYear().toString();
126
+
127
+ // Build native C++ config
128
+ const nativeCpp: NativeCppConfig | undefined = context.nativeCpp ? {
129
+ cppStandard: (context.nativeCpp.cppStandard === 'c++20' ? 'c++20' : 'c++17') as 'c++17' | 'c++20',
130
+ ndkVersion: context.nativeCpp.ndkVersion,
131
+ stlType: (context.nativeCpp.stlType as NativeCppConfig['stlType']) ?? 'c++_shared',
132
+ abiFilters: context.nativeCpp.abiFilters
133
+ } : undefined;
134
+
135
+ // Build project features from context (features may be at top level or nested)
136
+ const featuresObj = context.features as Record<string, unknown> || {};
137
+ const features: ProjectFeatures = {
138
+ git: typeof featuresObj.git === 'boolean' ? featuresObj.git : true,
139
+ readme: typeof featuresObj.readme === 'boolean' ? featuresObj.readme : true,
140
+ androidX: typeof featuresObj.androidX === 'boolean' ? featuresObj.androidX : true,
141
+ kotlinDsl: typeof featuresObj.kotlinDsl === 'boolean' ? featuresObj.kotlinDsl : true,
142
+ adaptiveIcon: typeof featuresObj.adaptiveIcon === 'boolean' ? featuresObj.adaptiveIcon : true,
143
+ material3: typeof featuresObj.material3 === 'boolean' ? featuresObj.material3 : true,
144
+ viewBinding: typeof featuresObj.viewBinding === 'boolean' ? featuresObj.viewBinding : undefined,
145
+ dataBinding: typeof featuresObj.dataBinding === 'boolean' ? featuresObj.dataBinding : undefined,
146
+ jetpackCompose: typeof featuresObj.jetpackCompose === 'boolean' ? featuresObj.jetpackCompose : undefined
147
+ };
148
+
149
+ // Build the complete template context
150
+ const templateContext: TemplateContext = {
151
+ appName: context.appName,
152
+ packageName: context.packageName,
153
+ projectDirectory: context.projectDirectory,
154
+ template: context.template as TemplateType,
155
+ language: context.language,
156
+ uiFramework: context.uiFramework as 'xml' | 'compose',
157
+ android: {
158
+ minSdk: context.android.minSdk,
159
+ targetSdk: context.android.targetSdk,
160
+ compileSdk: context.android.compileSdk,
161
+ buildToolsVersion: context.android.compileSdk > 34 ? '35.0.0' : '34.0.0'
162
+ },
163
+ gradle: {
164
+ agpVersion: context.gradle.agpVersion,
165
+ gradleVersion: context.gradle.gradleVersion,
166
+ kotlinVersion: context.gradle.kotlinVersion,
167
+ composeCompilerVersion: context.gradle.composeCompilerVersion,
168
+ composeBomVersion: context.gradle.composeBomVersion
169
+ },
170
+ appNameSnake,
171
+ appNameKebab,
172
+ appNamePascal,
173
+ appNameCamel,
174
+ appNameLower,
175
+ packagePath,
176
+ year,
177
+ generatorVersion: GENERATOR_VERSION,
178
+ ...features,
179
+ nativeCpp
180
+ };
181
+
182
+ return templateContext;
183
+ }
184
+
185
+ /**
186
+ * Validate context has all required fields
187
+ */
188
+ export function validateContext(context: Partial<TemplateContext>): { valid: boolean; errors: string[] } {
189
+ const errors: string[] = [];
190
+
191
+ if (!context.appName) errors.push('appName is required');
192
+ if (!context.packageName) errors.push('packageName is required');
193
+ if (!context.projectDirectory) errors.push('projectDirectory is required');
194
+ if (!context.template) errors.push('template is required');
195
+ if (!context.language) errors.push('language is required');
196
+ if (!context.uiFramework) errors.push('uiFramework is required');
197
+ if (!context.android) errors.push('android config is required');
198
+ if (!context.gradle) errors.push('gradle config is required');
199
+
200
+ if (context.android) {
201
+ if (!context.android.minSdk) errors.push('android.minSdk is required');
202
+ if (!context.android.targetSdk) errors.push('android.targetSdk is required');
203
+ if (!context.android.compileSdk) errors.push('android.compileSdk is required');
204
+ }
205
+
206
+ if (context.gradle) {
207
+ if (!context.gradle.agpVersion) errors.push('gradle.agpVersion is required');
208
+ if (!context.gradle.gradleVersion) errors.push('gradle.gradleVersion is required');
209
+ }
210
+
211
+ return { valid: errors.length === 0, errors };
212
+ }