@kodly.dev/kodly-cli 1.0.16
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.
- package/dist/api/client.js +96 -0
- package/dist/bin/kodly.js +35 -0
- package/dist/commands/auth.js +89 -0
- package/dist/commands/completion.js +90 -0
- package/dist/commands/docs.js +152 -0
- package/dist/commands/man.js +96 -0
- package/dist/commands/org.js +105 -0
- package/dist/commands/project.js +93 -0
- package/dist/commands/push.js +51 -0
- package/dist/commands/scaffold.js +236 -0
- package/dist/commands/status.js +52 -0
- package/dist/commands/task.js +155 -0
- package/dist/utils/changes.js +90 -0
- package/dist/utils/checkout.js +168 -0
- package/dist/utils/config.js +22 -0
- package/dist/utils/org.js +138 -0
- package/dist/utils/project.js +21 -0
- package/dist/utils/session.js +28 -0
- package/dist/utils/task.js +25 -0
- package/llm.txt +90 -0
- package/package.json +46 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { Api } from '../api/client.js';
|
|
5
|
+
import { requireAuthAndOrg } from '../utils/session.js';
|
|
6
|
+
import { printActiveOrg } from '../utils/org.js';
|
|
7
|
+
export const projectCommands = (program) => {
|
|
8
|
+
const projectCmd = program.command('project').description('Manage projects');
|
|
9
|
+
projectCmd
|
|
10
|
+
.command('list')
|
|
11
|
+
.description('List all projects')
|
|
12
|
+
.action(async () => {
|
|
13
|
+
const org = await requireAuthAndOrg();
|
|
14
|
+
if (!org)
|
|
15
|
+
return;
|
|
16
|
+
const spinner = ora('Fetching projects...').start();
|
|
17
|
+
try {
|
|
18
|
+
const res = await Api.projects.list();
|
|
19
|
+
const projects = res.data.data;
|
|
20
|
+
if (!projects || projects.length === 0) {
|
|
21
|
+
spinner.stop();
|
|
22
|
+
printActiveOrg(org);
|
|
23
|
+
console.log(chalk.yellow('No projects found.'));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
spinner.stop();
|
|
27
|
+
printActiveOrg(org);
|
|
28
|
+
console.log(chalk.bold('\nYour Projects:\n'));
|
|
29
|
+
projects.forEach((p) => {
|
|
30
|
+
console.log(` ${chalk.cyan(p.slug)} - ${p.name}`);
|
|
31
|
+
});
|
|
32
|
+
console.log('');
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
spinner.fail(chalk.red('Failed to list projects: ' + (error.message || 'Unknown error')));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
projectCmd
|
|
39
|
+
.command('checkout [slug] [path]')
|
|
40
|
+
.description('Checkout a project to local environment')
|
|
41
|
+
.action(async (slugArg, pathArg) => {
|
|
42
|
+
const org = await requireAuthAndOrg();
|
|
43
|
+
if (!org)
|
|
44
|
+
return;
|
|
45
|
+
let slug = slugArg;
|
|
46
|
+
if (!slug) {
|
|
47
|
+
const cwd = process.cwd();
|
|
48
|
+
const { getProjectData } = await import('../utils/project.js');
|
|
49
|
+
const projectData = getProjectData(cwd);
|
|
50
|
+
slug = projectData?.projectSlug || '';
|
|
51
|
+
if (!slug) {
|
|
52
|
+
console.log(chalk.red('Error: projectSlug is required. Provide it as an argument or run inside a directory with .kodly/project.info.json'));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const spinner = ora(`Checking out project ${slug}...`).start();
|
|
57
|
+
try {
|
|
58
|
+
printActiveOrg(org);
|
|
59
|
+
let projectDir = pathArg ? path.resolve(process.cwd(), pathArg) : null;
|
|
60
|
+
// If path not provided, try to fetch default from project settings
|
|
61
|
+
if (!projectDir) {
|
|
62
|
+
try {
|
|
63
|
+
const projectRes = await Api.projects.get(slug);
|
|
64
|
+
const project = projectRes.data.data;
|
|
65
|
+
if (project && project.userSettings && project.userSettings.codeSyncBasePath) {
|
|
66
|
+
let targetPath = project.userSettings.codeSyncBasePath;
|
|
67
|
+
projectDir = targetPath; // Assign to projectDir
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
// Ignore errors fetching settings
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Default to current directory + slug if still not set
|
|
75
|
+
if (!projectDir) {
|
|
76
|
+
projectDir = path.resolve(process.cwd(), slug);
|
|
77
|
+
}
|
|
78
|
+
spinner.text = `Checking out project files...`;
|
|
79
|
+
// Get Files
|
|
80
|
+
const checkoutRes = await Api.projects.checkout(slug);
|
|
81
|
+
const files = checkoutRes.data.data; // Array of SyncCodeResultDto
|
|
82
|
+
const { syncCheckoutFiles } = await import('../utils/checkout.js');
|
|
83
|
+
const success = await syncCheckoutFiles(projectDir, files, 'project', spinner);
|
|
84
|
+
if (success) {
|
|
85
|
+
spinner.succeed(chalk.green(`Project checked out to ${projectDir}`));
|
|
86
|
+
console.log(`Files synchronized: ${files.length}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
spinner.fail(chalk.red(`Checkout failed: ${error.message || 'Unknown error'}`));
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import { Api } from '../api/client.js';
|
|
4
|
+
import { requireAuthAndOrg } from '../utils/session.js';
|
|
5
|
+
import { printActiveOrg } from '../utils/org.js';
|
|
6
|
+
export const pushCommands = (program) => {
|
|
7
|
+
program
|
|
8
|
+
.command('push')
|
|
9
|
+
.description('Push local changes to Kodly')
|
|
10
|
+
.action(async () => {
|
|
11
|
+
const org = await requireAuthAndOrg();
|
|
12
|
+
if (!org)
|
|
13
|
+
return;
|
|
14
|
+
const cwd = process.cwd();
|
|
15
|
+
const { getTaskData } = await import('../utils/task.js');
|
|
16
|
+
const taskData = getTaskData(cwd);
|
|
17
|
+
const slug = taskData?.slug || '';
|
|
18
|
+
if (!slug) {
|
|
19
|
+
console.log(chalk.red('Error: Could not determine task slug. Validation failed, no valid task-*.json found in .kodly directory.'));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const spinner = ora(`Scanning files in ${slug}...`).start();
|
|
23
|
+
try {
|
|
24
|
+
const { getChangedFiles, updateChecksums } = await import('../utils/changes.js');
|
|
25
|
+
const { filesToPush, newChecksums } = await getChangedFiles(cwd);
|
|
26
|
+
if (filesToPush.length === 0) {
|
|
27
|
+
spinner.succeed(chalk.green('No changes detected. Everything is up to date!'));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
spinner.text = `Pushing ${filesToPush.length} changed files to ${slug}...`;
|
|
31
|
+
printActiveOrg(org);
|
|
32
|
+
// Map to API DTO { filepath, content, base64Encoded, status }
|
|
33
|
+
const payload = filesToPush.map(f => ({
|
|
34
|
+
filepath: f.filepath,
|
|
35
|
+
content: f.content,
|
|
36
|
+
base64Encoded: f.base64Encoded,
|
|
37
|
+
status: f.status === 'TO_BE_DELETED' ? 'TO_BE_DELETED' : null
|
|
38
|
+
}));
|
|
39
|
+
await Api.tasks.push(slug, payload);
|
|
40
|
+
updateChecksums(cwd, newChecksums);
|
|
41
|
+
spinner.succeed(chalk.green('Successfully pushed changes to cloud!'));
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error.response) {
|
|
45
|
+
console.error('API Error Status:', error.response.status);
|
|
46
|
+
console.error('API Error Data:', JSON.stringify(error.response.data, null, 2));
|
|
47
|
+
}
|
|
48
|
+
spinner.fail(chalk.red('Push failed: ' + (error.message || 'Unknown error')));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import ora from 'ora';
|
|
4
|
+
import { scaffold, scaffoldInit, listCachedRecipes, clearRecipeCache, ScaffoldError, } from '@kodly.dev/scaffolder';
|
|
5
|
+
function errorMessage(error) {
|
|
6
|
+
if (error instanceof ScaffoldError)
|
|
7
|
+
return error.message;
|
|
8
|
+
if (error instanceof Error)
|
|
9
|
+
return error.message;
|
|
10
|
+
return 'Unknown error';
|
|
11
|
+
}
|
|
12
|
+
async function runInit(opts) {
|
|
13
|
+
const spinner = ora(`Initializing project ${opts.name}...`).start();
|
|
14
|
+
try {
|
|
15
|
+
const result = await scaffoldInit({
|
|
16
|
+
targetDir: opts.path,
|
|
17
|
+
group: opts.group,
|
|
18
|
+
projectName: opts.name,
|
|
19
|
+
prefix: opts.prefix,
|
|
20
|
+
version: opts.version,
|
|
21
|
+
dryRun: opts.dryRun,
|
|
22
|
+
});
|
|
23
|
+
if (opts.dryRun) {
|
|
24
|
+
spinner.succeed(chalk.green(`Dry run for skeleton init (${result.version})`));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
spinner.succeed(chalk.green(`Initialized project ${result.projectName}`));
|
|
28
|
+
}
|
|
29
|
+
console.log(chalk.dim(` ${result.filesAdded.length} files created (${result.durationMs}ms)`));
|
|
30
|
+
for (const file of result.filesAdded) {
|
|
31
|
+
console.log(chalk.green(` + ${file}`));
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
spinner.fail(chalk.red(errorMessage(error)));
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function runApply(recipe, opts) {
|
|
41
|
+
const spinner = ora(`Applying recipe ${recipe}...`).start();
|
|
42
|
+
try {
|
|
43
|
+
const result = await scaffold({
|
|
44
|
+
recipe,
|
|
45
|
+
workspaceDir: opts.path,
|
|
46
|
+
tokens: {
|
|
47
|
+
targetGroup: opts.group,
|
|
48
|
+
targetPrefix: opts.prefix,
|
|
49
|
+
},
|
|
50
|
+
dryRun: opts.dryRun,
|
|
51
|
+
});
|
|
52
|
+
if (opts.dryRun) {
|
|
53
|
+
spinner.succeed(chalk.green(`Dry run for recipe ${result.recipe}`));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
spinner.succeed(chalk.green(`Applied recipe ${result.recipe}`));
|
|
57
|
+
}
|
|
58
|
+
console.log(chalk.dim(` ${result.filesAdded.length} files added, ${result.filesModified.length} files modified (${result.durationMs}ms)`));
|
|
59
|
+
for (const file of result.filesAdded) {
|
|
60
|
+
console.log(chalk.green(` + ${file}`));
|
|
61
|
+
}
|
|
62
|
+
for (const file of result.filesModified) {
|
|
63
|
+
console.log(chalk.yellow(` ~ ${file}`));
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
spinner.fail(chalk.red(errorMessage(error)));
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function runCreate(opts) {
|
|
73
|
+
const ok = await runInit({
|
|
74
|
+
path: opts.path,
|
|
75
|
+
group: opts.group,
|
|
76
|
+
name: opts.name,
|
|
77
|
+
prefix: opts.prefix,
|
|
78
|
+
version: opts.version,
|
|
79
|
+
dryRun: opts.dryRun,
|
|
80
|
+
});
|
|
81
|
+
if (!ok) {
|
|
82
|
+
process.exitCode = 1;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (opts.recipes.length === 0) {
|
|
86
|
+
console.log(chalk.dim('\nNo recipes requested. Skeleton is ready.'));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
console.log(chalk.bold(`\nApplying ${opts.recipes.length} recipe(s)…\n`));
|
|
90
|
+
for (const recipe of opts.recipes) {
|
|
91
|
+
const applied = await runApply(recipe, {
|
|
92
|
+
path: opts.path,
|
|
93
|
+
group: opts.group,
|
|
94
|
+
prefix: opts.prefix,
|
|
95
|
+
dryRun: opts.dryRun,
|
|
96
|
+
});
|
|
97
|
+
if (!applied) {
|
|
98
|
+
console.error(chalk.red(`\nStopped after failing to apply ${recipe}. Earlier steps (init / previous recipes) were already applied.`));
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
console.log(chalk.green(`\nDone. Project ready at ${opts.path}`));
|
|
104
|
+
}
|
|
105
|
+
function printCachedRecipes() {
|
|
106
|
+
const cached = listCachedRecipes();
|
|
107
|
+
if (cached.length === 0) {
|
|
108
|
+
console.log(chalk.yellow('No cached recipes found.'));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
console.log(chalk.bold('\nCached Recipes\n'));
|
|
112
|
+
for (const item of cached) {
|
|
113
|
+
console.log(` ${chalk.cyan(item.name)}@${item.version}`);
|
|
114
|
+
}
|
|
115
|
+
console.log('');
|
|
116
|
+
}
|
|
117
|
+
function registerApplyOptions(cmd) {
|
|
118
|
+
return cmd
|
|
119
|
+
.option('-p, --path <dir>', 'Target workspace directory', process.cwd())
|
|
120
|
+
.option('-g, --group <group>', 'Override Java package group (e.g. com.rental.app)')
|
|
121
|
+
.option('--prefix <prefix>', 'Override class prefix (e.g. RentalApp)')
|
|
122
|
+
.option('--dry-run', 'Show what would change without writing');
|
|
123
|
+
}
|
|
124
|
+
function collectRecipe(value, previous) {
|
|
125
|
+
return [...previous, value];
|
|
126
|
+
}
|
|
127
|
+
const SCAFFOLD_SUBCOMMANDS = new Set(['init', 'create', 'list', 'cache', 'apply']);
|
|
128
|
+
/** Rewrite `scaffold <recipe>` to `scaffold apply <recipe>` for shorthand. */
|
|
129
|
+
export function normalizeScaffoldArgv(argv) {
|
|
130
|
+
const scaffoldIdx = argv.indexOf('scaffold');
|
|
131
|
+
if (scaffoldIdx < 0)
|
|
132
|
+
return argv;
|
|
133
|
+
const next = argv[scaffoldIdx + 1];
|
|
134
|
+
if (!next || next.startsWith('-') || SCAFFOLD_SUBCOMMANDS.has(next)) {
|
|
135
|
+
return argv;
|
|
136
|
+
}
|
|
137
|
+
const normalized = [...argv];
|
|
138
|
+
normalized.splice(scaffoldIdx + 1, 0, 'apply');
|
|
139
|
+
return normalized;
|
|
140
|
+
}
|
|
141
|
+
export const scaffoldCommands = (program) => {
|
|
142
|
+
const scaffoldCmd = program.command('scaffold').description('Scaffold Spring Boot projects and apply recipes');
|
|
143
|
+
scaffoldCmd
|
|
144
|
+
.command('init')
|
|
145
|
+
.description('Generate a new Spring Boot skeleton with your package and project name')
|
|
146
|
+
.requiredOption('-g, --group <group>', 'Java package group (e.g. com.rental.app)')
|
|
147
|
+
.requiredOption('-n, --name <name>', 'Gradle project name (e.g. rental-app)')
|
|
148
|
+
.option('-p, --path <dir>', 'Target directory (must be empty or not exist)', process.cwd())
|
|
149
|
+
.option('--prefix <prefix>', 'Class prefix (defaults from project name, e.g. RentalApp)')
|
|
150
|
+
.option('--skeleton-version <version>', 'Skeleton template version', '1.0.0')
|
|
151
|
+
.option('--dry-run', 'Show what would be created without writing')
|
|
152
|
+
.action(async (opts) => {
|
|
153
|
+
const ok = await runInit({
|
|
154
|
+
path: opts.path,
|
|
155
|
+
group: opts.group,
|
|
156
|
+
name: opts.name,
|
|
157
|
+
prefix: opts.prefix,
|
|
158
|
+
version: opts.skeletonVersion,
|
|
159
|
+
dryRun: opts.dryRun,
|
|
160
|
+
});
|
|
161
|
+
if (!ok)
|
|
162
|
+
process.exitCode = 1;
|
|
163
|
+
});
|
|
164
|
+
scaffoldCmd
|
|
165
|
+
.command('create')
|
|
166
|
+
.description('Create a Spring Boot project and optionally apply recipes in one step')
|
|
167
|
+
.argument('[recipes...]', 'Recipes to apply after init (name@version)')
|
|
168
|
+
.requiredOption('-g, --group <group>', 'Java package group (e.g. com.rental.app)')
|
|
169
|
+
.requiredOption('-n, --name <name>', 'Gradle project name (e.g. rental-app)')
|
|
170
|
+
.option('-p, --path <dir>', 'Target directory (must be empty or not exist)', process.cwd())
|
|
171
|
+
.option('--prefix <prefix>', 'Class prefix (defaults from project name, e.g. RentalApp)')
|
|
172
|
+
.option('--skeleton-version <version>', 'Skeleton template version', '1.0.0')
|
|
173
|
+
.option('-r, --recipe <ref>', 'Recipe to apply (repeatable; same as positional recipes)', collectRecipe, [])
|
|
174
|
+
.option('--dry-run', 'Show what would be created without writing')
|
|
175
|
+
.action(async (recipes, opts) => {
|
|
176
|
+
const merged = [...recipes, ...(opts.recipe ?? [])];
|
|
177
|
+
// De-dupe while preserving order
|
|
178
|
+
const seen = new Set();
|
|
179
|
+
const unique = merged.filter((r) => {
|
|
180
|
+
if (seen.has(r))
|
|
181
|
+
return false;
|
|
182
|
+
seen.add(r);
|
|
183
|
+
return true;
|
|
184
|
+
});
|
|
185
|
+
await runCreate({
|
|
186
|
+
path: opts.path,
|
|
187
|
+
group: opts.group,
|
|
188
|
+
name: opts.name,
|
|
189
|
+
prefix: opts.prefix,
|
|
190
|
+
version: opts.skeletonVersion,
|
|
191
|
+
dryRun: opts.dryRun,
|
|
192
|
+
recipes: unique,
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
scaffoldCmd
|
|
196
|
+
.command('list')
|
|
197
|
+
.description('List locally cached recipes')
|
|
198
|
+
.action(() => {
|
|
199
|
+
printCachedRecipes();
|
|
200
|
+
});
|
|
201
|
+
const cacheCmd = scaffoldCmd.command('cache').description('Manage recipe cache');
|
|
202
|
+
cacheCmd
|
|
203
|
+
.command('list')
|
|
204
|
+
.description('List locally cached recipes')
|
|
205
|
+
.action(() => {
|
|
206
|
+
printCachedRecipes();
|
|
207
|
+
});
|
|
208
|
+
cacheCmd
|
|
209
|
+
.command('clear [target]')
|
|
210
|
+
.description('Clear recipe cache (all, recipe name, or recipe@version)')
|
|
211
|
+
.action((target) => {
|
|
212
|
+
try {
|
|
213
|
+
clearRecipeCache(target);
|
|
214
|
+
if (!target) {
|
|
215
|
+
console.log(chalk.green('Cleared all cached recipes.'));
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
console.log(chalk.green(`Cleared cache for ${target}.`));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
223
|
+
console.error(chalk.red(`Failed to clear cache: ${message}`));
|
|
224
|
+
process.exitCode = 1;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
const applyCmd = registerApplyOptions(new Command('apply')
|
|
228
|
+
.argument('<recipe>', 'Recipe ref in name@version format')
|
|
229
|
+
.description('Apply a deterministic recipe to the current Spring Boot project'));
|
|
230
|
+
applyCmd.action(async (recipe, opts) => {
|
|
231
|
+
const ok = await runApply(recipe, opts);
|
|
232
|
+
if (!ok)
|
|
233
|
+
process.exitCode = 1;
|
|
234
|
+
});
|
|
235
|
+
scaffoldCmd.addCommand(applyCmd);
|
|
236
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import { requireAuthAndOrg } from '../utils/session.js';
|
|
4
|
+
import { printActiveOrg } from '../utils/org.js';
|
|
5
|
+
export const statusCommands = (program) => {
|
|
6
|
+
program
|
|
7
|
+
.command('status')
|
|
8
|
+
.description('Show the working tree status')
|
|
9
|
+
.action(async () => {
|
|
10
|
+
const org = await requireAuthAndOrg();
|
|
11
|
+
if (!org)
|
|
12
|
+
return;
|
|
13
|
+
const cwd = process.cwd();
|
|
14
|
+
const { getTaskData } = await import('../utils/task.js');
|
|
15
|
+
const taskData = getTaskData(cwd);
|
|
16
|
+
const slug = taskData?.slug || '';
|
|
17
|
+
const title = taskData?.title || '';
|
|
18
|
+
// Basic validation
|
|
19
|
+
if (!slug) {
|
|
20
|
+
console.log(chalk.red('Error: Could not determine task slug. Validation failed, no valid task-*.json found in .kodly directory. Are you in a task directory?'));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const spinner = ora('Checking status...').start();
|
|
24
|
+
try {
|
|
25
|
+
const { getChangedFiles } = await import('../utils/changes.js');
|
|
26
|
+
const { filesToPush } = await getChangedFiles(cwd);
|
|
27
|
+
spinner.stop();
|
|
28
|
+
printActiveOrg(org);
|
|
29
|
+
console.log(chalk.bold(`On task: ${chalk.cyan(slug)} ${title ? '- ' + title : ''}\n`));
|
|
30
|
+
if (filesToPush.length === 0) {
|
|
31
|
+
console.log(chalk.green('nothing to commit, working tree clean'));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
console.log('Changes not pushed to cloud:');
|
|
35
|
+
console.log(` (use "kodly push" to update cloud)\n`);
|
|
36
|
+
filesToPush.forEach(file => {
|
|
37
|
+
let color = chalk.yellow;
|
|
38
|
+
if (file.status === 'NEW')
|
|
39
|
+
color = chalk.green;
|
|
40
|
+
if (file.status === 'TO_BE_DELETED')
|
|
41
|
+
color = chalk.red;
|
|
42
|
+
// file.filepath includes base path
|
|
43
|
+
console.log(`\t${color(file.status.toLowerCase() + ': ' + file.filepath)}`);
|
|
44
|
+
});
|
|
45
|
+
console.log(''); // Newline
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
spinner.fail(chalk.red('Status check failed: ' + (error.message || 'Unknown error')));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { Api } from '../api/client.js'; // Note .js extension for ESM
|
|
5
|
+
import { requireAuthAndOrg } from '../utils/session.js';
|
|
6
|
+
import { printActiveOrg } from '../utils/org.js';
|
|
7
|
+
import { getProjectData } from '../utils/project.js';
|
|
8
|
+
export const taskCommands = (program) => {
|
|
9
|
+
const taskCmd = program.command('task').description('Manage tasks');
|
|
10
|
+
taskCmd
|
|
11
|
+
.command('list')
|
|
12
|
+
.description('List all tasks assigned to you')
|
|
13
|
+
.action(async () => {
|
|
14
|
+
const org = await requireAuthAndOrg();
|
|
15
|
+
if (!org)
|
|
16
|
+
return;
|
|
17
|
+
const spinner = ora('Fetching projects...').start();
|
|
18
|
+
try {
|
|
19
|
+
// 1. Fetch Projects
|
|
20
|
+
const projectRes = await Api.projects.list();
|
|
21
|
+
const projects = projectRes.data.data;
|
|
22
|
+
if (!projects || projects.length === 0) {
|
|
23
|
+
spinner.stop();
|
|
24
|
+
printActiveOrg(org);
|
|
25
|
+
console.log(chalk.yellow('No projects found.'));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Use existing spinner or start new activity
|
|
29
|
+
if (spinner.isSpinning)
|
|
30
|
+
spinner.stop();
|
|
31
|
+
spinner.start('Fetching tasks...');
|
|
32
|
+
let foundAnyTasks = false;
|
|
33
|
+
// Loop through all projects to find tasks
|
|
34
|
+
for (const project of projects) {
|
|
35
|
+
spinner.text = `Checking project: ${project.name}...`;
|
|
36
|
+
try {
|
|
37
|
+
const taskRes = await Api.tasks.list(project.slug);
|
|
38
|
+
const tasks = taskRes.data.data;
|
|
39
|
+
if (tasks && tasks.length > 0) {
|
|
40
|
+
if (!foundAnyTasks) {
|
|
41
|
+
spinner.stop();
|
|
42
|
+
foundAnyTasks = true;
|
|
43
|
+
printActiveOrg(org);
|
|
44
|
+
console.log(chalk.bold('\nYour Tasks:\n'));
|
|
45
|
+
}
|
|
46
|
+
// Print Project Header if we have tasks
|
|
47
|
+
console.log(chalk.dim(`Project: ${project.name} (${project.slug})`));
|
|
48
|
+
tasks.forEach((task) => {
|
|
49
|
+
console.log(` ${chalk.cyan(task.slug)} - ${task.title} [${task.taskStatus}]`);
|
|
50
|
+
});
|
|
51
|
+
console.log('');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
// Ignore error for individual project fetch and continue
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (!foundAnyTasks) {
|
|
59
|
+
spinner.stop();
|
|
60
|
+
printActiveOrg(org);
|
|
61
|
+
console.log(chalk.yellow('No tasks found in any of your projects.'));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if (spinner.isSpinning)
|
|
65
|
+
spinner.stop();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
spinner.fail(chalk.red('Failed to list tasks: ' + (error.message || 'Unknown error')));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
taskCmd
|
|
73
|
+
.command('checkout <slug> [path]')
|
|
74
|
+
.description('Checkout a task to local environment')
|
|
75
|
+
.action(async (slug, pathArg) => {
|
|
76
|
+
const org = await requireAuthAndOrg();
|
|
77
|
+
if (!org)
|
|
78
|
+
return;
|
|
79
|
+
const spinner = ora(`Checking out task ${slug}...`).start();
|
|
80
|
+
try {
|
|
81
|
+
printActiveOrg(org);
|
|
82
|
+
// Get Files (including .kodlyspec)
|
|
83
|
+
const checkoutRes = await Api.tasks.checkout(slug);
|
|
84
|
+
const files = checkoutRes.data.data; // Array of SyncCodeResultDto
|
|
85
|
+
const taskDir = pathArg ? path.resolve(process.cwd(), pathArg) : path.resolve(process.cwd(), slug);
|
|
86
|
+
const { syncCheckoutFiles } = await import('../utils/checkout.js');
|
|
87
|
+
const success = await syncCheckoutFiles(taskDir, files, 'task', spinner);
|
|
88
|
+
if (success) {
|
|
89
|
+
spinner.succeed(chalk.green(`Task checked out to ${pathArg || './' + slug}`));
|
|
90
|
+
console.log(`Files synchronized: ${files.length}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
spinner.fail(chalk.red(`Checkout failed: ${error.message || 'Unknown error'}`));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
taskCmd
|
|
98
|
+
.command('create [args...]')
|
|
99
|
+
.description('Create a new task for a project')
|
|
100
|
+
.action(async (args) => {
|
|
101
|
+
const org = await requireAuthAndOrg();
|
|
102
|
+
if (!org)
|
|
103
|
+
return;
|
|
104
|
+
if (!args || args.length === 0) {
|
|
105
|
+
console.log(chalk.red('Error: Task title is required.'));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
let projectSlug = '';
|
|
109
|
+
let title = '';
|
|
110
|
+
const cwd = process.cwd();
|
|
111
|
+
const projectData = getProjectData(cwd);
|
|
112
|
+
if (projectData && projectData.projectSlug) {
|
|
113
|
+
if (args.length === 1) {
|
|
114
|
+
projectSlug = projectData.projectSlug;
|
|
115
|
+
title = args[0];
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// Check if first arg looks like a project slug and we have 2 args (e.g. `kodly task create my-project "Title"`)
|
|
119
|
+
if (args.length === 2 && /^[a-z0-9-]+$/.test(args[0])) {
|
|
120
|
+
projectSlug = args[0];
|
|
121
|
+
title = args[1];
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
projectSlug = projectData.projectSlug;
|
|
125
|
+
title = args.join(' ');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
if (args.length < 2) {
|
|
131
|
+
console.log(chalk.red('Error: <projectSlug> and <title> are required when not inside a project directory. Usage: kodly task create <projectSlug> <title...>'));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
projectSlug = args[0];
|
|
135
|
+
title = args.slice(1).join(' ');
|
|
136
|
+
}
|
|
137
|
+
const spinner = ora(`Creating task "${title}" in project ${projectSlug}...`).start();
|
|
138
|
+
try {
|
|
139
|
+
printActiveOrg(org);
|
|
140
|
+
const createRes = await Api.tasks.create(projectSlug, title);
|
|
141
|
+
const newTask = createRes.data.data;
|
|
142
|
+
if (newTask) {
|
|
143
|
+
spinner.succeed(chalk.green(`Task created successfully:`));
|
|
144
|
+
console.log(` ${chalk.cyan(newTask.slug)} - ${newTask.title}`);
|
|
145
|
+
console.log(`\nTo checkout this task, run:\n ${chalk.cyan(`kodly task checkout ${newTask.slug} .`)}\n`);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
spinner.succeed(chalk.green(`Task created successfully.`));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
spinner.fail(chalk.red(`Failed to create task: ${error.message || 'Unknown error'}`));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
export async function getChangedFiles(cwd) {
|
|
4
|
+
const crypto = await import('crypto');
|
|
5
|
+
const ignore = (await import('ignore')).default;
|
|
6
|
+
let ig = ignore();
|
|
7
|
+
const gitignorePath = path.join(cwd, '.gitignore');
|
|
8
|
+
if (fs.existsSync(gitignorePath)) {
|
|
9
|
+
ig.add(fs.readFileSync(gitignorePath, 'utf8'));
|
|
10
|
+
}
|
|
11
|
+
// Always ignore .kodly, .git, and common lock files / spec files
|
|
12
|
+
ig.add(['.kodly', '.git', 'node_modules', 'dist', 'build', '.kodlyspec', 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml']);
|
|
13
|
+
const kodlyDir = path.join(cwd, '.kodly');
|
|
14
|
+
const checksumsPath = path.join(kodlyDir, 'checksums.json');
|
|
15
|
+
let storedChecksums = {};
|
|
16
|
+
if (fs.existsSync(checksumsPath)) {
|
|
17
|
+
const rawChecksums = JSON.parse(fs.readFileSync(checksumsPath, 'utf8'));
|
|
18
|
+
// Normalize keys to ensure forward slashes
|
|
19
|
+
Object.keys(rawChecksums).forEach(key => {
|
|
20
|
+
storedChecksums[key.replace(/\\/g, '/')] = rawChecksums[key];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const filesToPush = [];
|
|
24
|
+
const newChecksums = { ...storedChecksums };
|
|
25
|
+
const foundFiles = new Set();
|
|
26
|
+
function scanDirectory(dir, base) {
|
|
27
|
+
const list = fs.readdirSync(dir);
|
|
28
|
+
list.forEach(file => {
|
|
29
|
+
const fullPath = path.join(dir, file);
|
|
30
|
+
const rawRelativePath = path.join(base, file);
|
|
31
|
+
const relativePath = rawRelativePath.replace(/\\/g, '/'); // Ensure forward slashes
|
|
32
|
+
// Check ignore
|
|
33
|
+
if (ig.ignores(relativePath))
|
|
34
|
+
return;
|
|
35
|
+
const stat = fs.statSync(fullPath);
|
|
36
|
+
if (stat.isDirectory()) {
|
|
37
|
+
scanDirectory(fullPath, relativePath);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
foundFiles.add(relativePath);
|
|
41
|
+
const contentBuffer = fs.readFileSync(fullPath);
|
|
42
|
+
const currentHash = crypto.createHash('md5').update(contentBuffer).digest('hex');
|
|
43
|
+
// Check if file changed
|
|
44
|
+
if (storedChecksums[relativePath] !== currentHash) {
|
|
45
|
+
const content = contentBuffer.toString('utf8'); // Assuming text for now
|
|
46
|
+
filesToPush.push({
|
|
47
|
+
filepath: relativePath,
|
|
48
|
+
content,
|
|
49
|
+
base64Encoded: false,
|
|
50
|
+
status: storedChecksums[relativePath] ? 'MODIFIED' : 'NEW',
|
|
51
|
+
currentHash
|
|
52
|
+
});
|
|
53
|
+
// Update local map (pending successful push)
|
|
54
|
+
newChecksums[relativePath] = currentHash;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// Keep existing hash (already copied via spread)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
scanDirectory(cwd, '');
|
|
63
|
+
// Check for deleted files
|
|
64
|
+
Object.keys(storedChecksums).forEach(path => {
|
|
65
|
+
if (!foundFiles.has(path)) {
|
|
66
|
+
if (ig.ignores(path)) {
|
|
67
|
+
// If it's ignored locally now, stop tracking it but don't delete on server.
|
|
68
|
+
delete newChecksums[path];
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
filesToPush.push({
|
|
72
|
+
filepath: path,
|
|
73
|
+
content: '', // Or null if API supports it, but interface says string
|
|
74
|
+
base64Encoded: false,
|
|
75
|
+
status: 'TO_BE_DELETED',
|
|
76
|
+
currentHash: ''
|
|
77
|
+
});
|
|
78
|
+
delete newChecksums[path];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return { filesToPush, newChecksums };
|
|
83
|
+
}
|
|
84
|
+
export function updateChecksums(cwd, newChecksums) {
|
|
85
|
+
const kodlyDir = path.join(cwd, '.kodly');
|
|
86
|
+
const checksumsPath = path.join(kodlyDir, 'checksums.json');
|
|
87
|
+
if (!fs.existsSync(kodlyDir))
|
|
88
|
+
fs.mkdirSync(kodlyDir, { recursive: true });
|
|
89
|
+
fs.writeFileSync(checksumsPath, JSON.stringify(newChecksums, null, 2));
|
|
90
|
+
}
|