@opentiny/tiny-robot-cli 0.4.1-alpha.0 → 0.4.1-alpha.2
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/bin/commands/add.js +45 -14
- package/bin/utils.js +3 -1
- package/package.json +2 -2
package/bin/commands/add.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from '../utils.js'
|
|
21
21
|
|
|
22
22
|
const DEP_NAME = '@opentiny/tiny-robot'
|
|
23
|
-
const TARGET_VERSION = '0.4.2-alpha.
|
|
23
|
+
const TARGET_VERSION = '0.4.2-alpha.6'
|
|
24
24
|
const STYLE_IMPORT = "import '@opentiny/tiny-robot/dist/style.css'"
|
|
25
25
|
|
|
26
26
|
function logUnavailable(label) {
|
|
@@ -154,17 +154,20 @@ function ensureDependency(pkg, name, targetVersion) {
|
|
|
154
154
|
|
|
155
155
|
const currentVersion = pkg.dependencies[name]
|
|
156
156
|
|
|
157
|
+
// 1. 不存在 => 新增(使用 ordered insert)
|
|
157
158
|
if (!currentVersion) {
|
|
158
159
|
pkg.dependencies = insertDependencyOrdered(pkg.dependencies, name, targetVersion)
|
|
159
160
|
|
|
160
161
|
return {
|
|
161
162
|
type: 'added',
|
|
163
|
+
to: targetVersion,
|
|
162
164
|
}
|
|
163
165
|
}
|
|
164
166
|
|
|
165
|
-
|
|
167
|
+
// 2. 已存在 => 只更新版本,不调整顺序
|
|
168
|
+
const current = semver.valid(semver.coerce(currentVersion)?.version)
|
|
166
169
|
|
|
167
|
-
if (
|
|
170
|
+
if (current && current !== targetVersion) {
|
|
168
171
|
pkg.dependencies[name] = targetVersion
|
|
169
172
|
|
|
170
173
|
return {
|
|
@@ -174,6 +177,7 @@ function ensureDependency(pkg, name, targetVersion) {
|
|
|
174
177
|
}
|
|
175
178
|
}
|
|
176
179
|
|
|
180
|
+
// 3. 完全一致 => 跳过
|
|
177
181
|
return {
|
|
178
182
|
type: 'skipped',
|
|
179
183
|
}
|
|
@@ -295,7 +299,7 @@ async function addFeature(targetDir, type) {
|
|
|
295
299
|
|
|
296
300
|
console.log('\nChange Results\n')
|
|
297
301
|
|
|
298
|
-
let
|
|
302
|
+
let needsManualStyleImport = false
|
|
299
303
|
let envChanged = false
|
|
300
304
|
let dependencyChanged = false
|
|
301
305
|
|
|
@@ -311,6 +315,8 @@ async function addFeature(targetDir, type) {
|
|
|
311
315
|
})
|
|
312
316
|
|
|
313
317
|
if (!mainFile?.target) {
|
|
318
|
+
needsManualStyleImport = true
|
|
319
|
+
|
|
314
320
|
logUnavailable('main entry style import (main.ts/js not found)')
|
|
315
321
|
} else {
|
|
316
322
|
if (isSelected(selectedFiles, mainFile.label)) {
|
|
@@ -318,8 +324,6 @@ async function addFeature(targetDir, type) {
|
|
|
318
324
|
|
|
319
325
|
switch (result.type) {
|
|
320
326
|
case 'inserted':
|
|
321
|
-
mainImportChanged = true
|
|
322
|
-
|
|
323
327
|
logSuccess('Inserted TinyRobot style import')
|
|
324
328
|
break
|
|
325
329
|
|
|
@@ -328,6 +332,8 @@ async function addFeature(targetDir, type) {
|
|
|
328
332
|
break
|
|
329
333
|
}
|
|
330
334
|
} else {
|
|
335
|
+
needsManualStyleImport = true
|
|
336
|
+
|
|
331
337
|
logSkippedSelection(mainFile.label)
|
|
332
338
|
}
|
|
333
339
|
}
|
|
@@ -379,27 +385,52 @@ async function addFeature(targetDir, type) {
|
|
|
379
385
|
console.log(`\nSuccessfully added "${type}" feature to ${targetDir}`)
|
|
380
386
|
|
|
381
387
|
printNextSteps({
|
|
382
|
-
|
|
388
|
+
needsManualStyleImport,
|
|
383
389
|
envChanged,
|
|
384
390
|
dependencyChanged,
|
|
385
391
|
})
|
|
386
392
|
}
|
|
387
393
|
|
|
388
|
-
function printNextSteps({
|
|
394
|
+
function printNextSteps({ needsManualStyleImport, envChanged, dependencyChanged }) {
|
|
389
395
|
const steps = []
|
|
390
396
|
|
|
391
|
-
if (
|
|
392
|
-
steps.push(
|
|
397
|
+
if (needsManualStyleImport) {
|
|
398
|
+
steps.push(
|
|
399
|
+
['Import TinyRobot styles in your application entry file.', '', 'Example:', '', ` ${STYLE_IMPORT}`].join('\n'),
|
|
400
|
+
)
|
|
393
401
|
}
|
|
394
402
|
|
|
395
|
-
steps.push(
|
|
403
|
+
steps.push(
|
|
404
|
+
[
|
|
405
|
+
'Render <TinyRobotChat /> near your main application component.',
|
|
406
|
+
'',
|
|
407
|
+
"Example ('src/App.vue'):",
|
|
408
|
+
'',
|
|
409
|
+
' <script setup>',
|
|
410
|
+
" import TinyRobotChat from './TinyRobotChat.vue'",
|
|
411
|
+
' </script>',
|
|
412
|
+
'',
|
|
413
|
+
' <template>',
|
|
414
|
+
' <YourAppComponent />',
|
|
415
|
+
' <TinyRobotChat />',
|
|
416
|
+
' </template>',
|
|
417
|
+
].join('\n'),
|
|
418
|
+
)
|
|
396
419
|
|
|
397
420
|
if (envChanged) {
|
|
398
|
-
steps.push(
|
|
421
|
+
steps.push(
|
|
422
|
+
[
|
|
423
|
+
'Configure your AI provider API key in the .env file.',
|
|
424
|
+
'',
|
|
425
|
+
'Example:',
|
|
426
|
+
'',
|
|
427
|
+
' VITE_DEEPSEEK_API_KEY=your_api_key',
|
|
428
|
+
].join('\n'),
|
|
429
|
+
)
|
|
399
430
|
}
|
|
400
431
|
|
|
401
432
|
if (dependencyChanged) {
|
|
402
|
-
steps.push('
|
|
433
|
+
steps.push(['Install or update project dependencies.', '', 'Example:', '', ' pnpm install'].join('\n'))
|
|
403
434
|
}
|
|
404
435
|
|
|
405
436
|
if (steps.length === 0) {
|
|
@@ -409,7 +440,7 @@ function printNextSteps({ mainImportChanged, envChanged, dependencyChanged }) {
|
|
|
409
440
|
console.log('\nNext Steps\n')
|
|
410
441
|
|
|
411
442
|
for (const [index, step] of steps.entries()) {
|
|
412
|
-
console.log(`${index + 1}. ${step}`)
|
|
443
|
+
console.log(`${index + 1}. ${step}\n`)
|
|
413
444
|
}
|
|
414
445
|
}
|
|
415
446
|
|
package/bin/utils.js
CHANGED
|
@@ -326,7 +326,9 @@ export function mergeEnvFile(templateFile, targetFile) {
|
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
-
const
|
|
329
|
+
const targetTrimmed = targetContent.replace(/\s*$/, '')
|
|
330
|
+
|
|
331
|
+
const nextContent = targetTrimmed ? `${targetTrimmed}\n${appendLines.join('\n')}\n` : `${appendLines.join('\n')}\n`
|
|
330
332
|
|
|
331
333
|
fs.writeFileSync(targetFile, nextContent)
|
|
332
334
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentiny/tiny-robot-cli",
|
|
3
|
-
"version": "0.4.1-alpha.
|
|
3
|
+
"version": "0.4.1-alpha.2",
|
|
4
4
|
"description": "CLI to scaffold TinyRobot product projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"picocolors": "^1.1.1",
|
|
25
25
|
"semver": "^7.8.1"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "a68e9109e840fdf6f37d1dab835ac58546e7cdcb"
|
|
28
28
|
}
|