pelulu-cli 1.0.1 → 1.0.5
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/package.json +1 -1
- package/src/core/update-checker.js +37 -31
- package/src/index.js +11 -4
- package/src/mcp/activation.js +2 -5
- package/DailyNotesApp/app/build.gradle.kts +0 -57
- package/DailyNotesApp/app/src/main/java/com/dailynotes/app/MainActivity.kt +0 -48
- package/DailyNotesApp/app/src/main/java/com/dailynotes/app/Note.kt +0 -13
- package/DailyNotesApp/app/src/main/java/com/dailynotes/app/NoteDatabase.kt +0 -9
- package/DailyNotesApp/build.gradle.kts +0 -5
- package/DailyNotesApp/settings.gradle.kts +0 -17
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Update Checker — compare local version with
|
|
3
|
-
* Uses: https://
|
|
2
|
+
* Update Checker — compare local version with npm registry
|
|
3
|
+
* Uses: https://registry.npmjs.org/PACKAGE_NAME/latest
|
|
4
4
|
*/
|
|
5
5
|
import { readFile } from 'fs/promises';
|
|
6
6
|
import { join } from 'path';
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const NPM_REGISTRY_URL = 'https://registry.npmjs.org';
|
|
9
9
|
const TIMEOUT_MS = 8000;
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -43,36 +43,41 @@ async function getLocalVersion(root) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
47
|
-
* Returns { tag, name, body, url, publishedAt } or null on failure.
|
|
46
|
+
* Read package name from package.json
|
|
48
47
|
*/
|
|
49
|
-
async function
|
|
48
|
+
async function getPackageName(root) {
|
|
49
|
+
try {
|
|
50
|
+
const raw = await readFile(join(root, 'package.json'), 'utf-8');
|
|
51
|
+
const pkg = JSON.parse(raw);
|
|
52
|
+
return pkg.name || 'pelulu-cli';
|
|
53
|
+
} catch {
|
|
54
|
+
return 'pelulu-cli';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Fetch latest version from npm registry.
|
|
60
|
+
* Returns { version, url } or null on failure.
|
|
61
|
+
*/
|
|
62
|
+
async function fetchLatestFromNpm(packageName) {
|
|
50
63
|
const controller = new AbortController();
|
|
51
64
|
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
52
65
|
|
|
53
66
|
try {
|
|
54
|
-
const res = await fetch(
|
|
67
|
+
const res = await fetch(`${NPM_REGISTRY_URL}/${packageName}/latest`, {
|
|
55
68
|
signal: controller.signal,
|
|
56
|
-
headers: {
|
|
57
|
-
'Accept': 'application/vnd.github+json',
|
|
58
|
-
'User-Agent': 'Pelulu-CLI',
|
|
59
|
-
},
|
|
69
|
+
headers: { 'Accept': 'application/json' },
|
|
60
70
|
});
|
|
61
71
|
|
|
62
72
|
if (!res.ok) return null;
|
|
63
73
|
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// Filter out prerelease/draft, pick latest stable
|
|
68
|
-
const stable = releases.find(r => !r.prerelease && !r.draft) || releases[0];
|
|
74
|
+
const data = await res.json();
|
|
75
|
+
const version = data.version;
|
|
76
|
+
if (!version) return null;
|
|
69
77
|
|
|
70
78
|
return {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
body: stable.body || '',
|
|
74
|
-
url: stable.html_url || '',
|
|
75
|
-
publishedAt: stable.published_at || '',
|
|
79
|
+
version,
|
|
80
|
+
url: `https://www.npmjs.com/package/${packageName}`,
|
|
76
81
|
};
|
|
77
82
|
} catch {
|
|
78
83
|
return null;
|
|
@@ -82,9 +87,9 @@ async function fetchLatestRelease() {
|
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
/**
|
|
85
|
-
* Check for updates.
|
|
90
|
+
* Check for updates (from npm registry).
|
|
86
91
|
* Returns:
|
|
87
|
-
* { available: true, local, remote,
|
|
92
|
+
* { available: true, local, remote, npm_url } — update available
|
|
88
93
|
* { available: false, local, remote } — up to date
|
|
89
94
|
* { available: false, error: true, message } — check failed
|
|
90
95
|
*/
|
|
@@ -94,16 +99,17 @@ export async function checkForUpdates(root) {
|
|
|
94
99
|
return { available: false, error: true, message: 'Could not read local version from package.json' };
|
|
95
100
|
}
|
|
96
101
|
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
const packageName = await getPackageName(root);
|
|
103
|
+
const npm = await fetchLatestFromNpm(packageName);
|
|
104
|
+
if (!npm) {
|
|
105
|
+
return { available: false, error: true, local: localVersion, message: 'Could not fetch npm registry' };
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
const localParsed = parseSemver(localVersion);
|
|
103
|
-
const remoteParsed = parseSemver(
|
|
109
|
+
const remoteParsed = parseSemver(npm.version);
|
|
104
110
|
|
|
105
111
|
if (!localParsed || !remoteParsed) {
|
|
106
|
-
return { available: false, error: true, local: localVersion, remote:
|
|
112
|
+
return { available: false, error: true, local: localVersion, remote: npm.version, message: 'Invalid version format' };
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
const cmp = compareSemver(remoteParsed, localParsed);
|
|
@@ -112,14 +118,14 @@ export async function checkForUpdates(root) {
|
|
|
112
118
|
return {
|
|
113
119
|
available: true,
|
|
114
120
|
local: localVersion,
|
|
115
|
-
remote:
|
|
116
|
-
release,
|
|
121
|
+
remote: npm.version,
|
|
122
|
+
release: { url: npm.url },
|
|
117
123
|
};
|
|
118
124
|
}
|
|
119
125
|
|
|
120
126
|
return {
|
|
121
127
|
available: false,
|
|
122
128
|
local: localVersion,
|
|
123
|
-
remote:
|
|
129
|
+
remote: npm.version,
|
|
124
130
|
};
|
|
125
131
|
}
|
package/src/index.js
CHANGED
|
@@ -101,10 +101,17 @@ async function main() {
|
|
|
101
101
|
const mqtt = new MqttClient(config);
|
|
102
102
|
|
|
103
103
|
bus.on('activation:required', ({ code }) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
// Display DIRECTLY to console (not buffered) — user must see this!
|
|
105
|
+
origLog('');
|
|
106
|
+
origLog(chalk.red(' ╔══════════════════════════════════════════╗'));
|
|
107
|
+
origLog(chalk.red(' ║') + chalk.bold.white(' ACTIVATION REQUIRED ') + chalk.red('║'));
|
|
108
|
+
origLog(chalk.red(' ╠══════════════════════════════════════════╣'));
|
|
109
|
+
origLog(chalk.red(' ║') + chalk.yellow(` Code: ${code}`) + ' '.repeat(33 - code.length) + chalk.red('║'));
|
|
110
|
+
origLog(chalk.red(' ║') + chalk.cyan(' https://xiaozhi.me') + ' '.repeat(23) + chalk.red('║'));
|
|
111
|
+
origLog(chalk.red(' ╚══════════════════════════════════════════╝'));
|
|
112
|
+
origLog('');
|
|
113
|
+
origLog(chalk.gray(' Waiting for activation... (checking every 5s)'));
|
|
114
|
+
origLog('');
|
|
108
115
|
});
|
|
109
116
|
|
|
110
117
|
try {
|
package/src/mcp/activation.js
CHANGED
|
@@ -33,9 +33,6 @@ export async function handleActivation(data, otaUrl, deviceId, clientId) {
|
|
|
33
33
|
const a = data.activation;
|
|
34
34
|
if (!a?.code) return data.mqtt;
|
|
35
35
|
|
|
36
|
-
log('warn', `🔐 Activation required`);
|
|
37
|
-
log('info', `📋 Code: ${a.code}`);
|
|
38
|
-
log('info', `[WEB] https://xiaozhi.me`);
|
|
39
36
|
bus.emit('activation:required', { code: a.code });
|
|
40
37
|
|
|
41
38
|
const timeout = a.timeout_ms || 120000;
|
|
@@ -43,10 +40,10 @@ export async function handleActivation(data, otaUrl, deviceId, clientId) {
|
|
|
43
40
|
|
|
44
41
|
while (Date.now() - start < timeout) {
|
|
45
42
|
await new Promise(r => setTimeout(r, 5000));
|
|
46
|
-
log('info', '
|
|
43
|
+
log('info', 'Checking activation...');
|
|
47
44
|
const poll = await fetchOtaConfig(otaUrl, deviceId, clientId);
|
|
48
45
|
if (!poll.activation?.code && poll.mqtt) {
|
|
49
|
-
log('ok', '
|
|
46
|
+
log('ok', 'Activated!');
|
|
50
47
|
return poll.mqtt;
|
|
51
48
|
}
|
|
52
49
|
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
plugins {
|
|
2
|
-
id("com.android.application")
|
|
3
|
-
id("org.jetbrains.kotlin.android")
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
android {
|
|
7
|
-
namespace = "com.dailynotes.app"
|
|
8
|
-
compileSdk = 34
|
|
9
|
-
|
|
10
|
-
defaultConfig {
|
|
11
|
-
applicationId = "com.dailynotes.app"
|
|
12
|
-
minSdk = 24
|
|
13
|
-
targetSdk = 34
|
|
14
|
-
versionCode = 1
|
|
15
|
-
versionName = "1.0"
|
|
16
|
-
|
|
17
|
-
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
buildTypes {
|
|
21
|
-
release {
|
|
22
|
-
isMinifyEnabled = false
|
|
23
|
-
proguardFiles(
|
|
24
|
-
getDefaultProguardFile("proguard-android-optimize.txt"),
|
|
25
|
-
"proguard-rules.pro"
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
compileOptions {
|
|
30
|
-
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
31
|
-
targetCompatibility = JavaVersion.VERSION_1_8
|
|
32
|
-
}
|
|
33
|
-
kotlinOptions {
|
|
34
|
-
jvmTarget = "1.8"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
dependencies {
|
|
39
|
-
implementation("androidx.core:core-ktx:1.12.0")
|
|
40
|
-
implementation("androidx.appcompat:appcompat:1.6.1")
|
|
41
|
-
implementation("com.google.android.material:material:1.11.0")
|
|
42
|
-
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
|
43
|
-
|
|
44
|
-
// Room Database
|
|
45
|
-
val roomVersion = "2.6.1"
|
|
46
|
-
implementation("androidx.room:room-runtime:$roomVersion")
|
|
47
|
-
implementation("androidx.room:room-ktx:$roomVersion")
|
|
48
|
-
ksp("androidx.room:room-compiler:$roomVersion")
|
|
49
|
-
|
|
50
|
-
// Lifecycle
|
|
51
|
-
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")
|
|
52
|
-
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.7.0")
|
|
53
|
-
|
|
54
|
-
testImplementation("junit:junit:4.13.2")
|
|
55
|
-
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
|
56
|
-
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
|
57
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
package com.dailynotes.app
|
|
2
|
-
|
|
3
|
-
import android.os.Bundle
|
|
4
|
-
import androidx.appcompat.app.AppCompatActivity
|
|
5
|
-
import androidx.lifecycle.ViewModelProvider
|
|
6
|
-
import androidx.recyclerview.widget.LinearLayoutManager
|
|
7
|
-
import androidx.recyclerview.widget.RecyclerView
|
|
8
|
-
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
9
|
-
|
|
10
|
-
class MainActivity : AppCompatActivity() {
|
|
11
|
-
|
|
12
|
-
private lateinit var viewModel: NoteViewModel
|
|
13
|
-
private lateinit var adapter: NoteAdapter
|
|
14
|
-
private lateinit var recyclerView: RecyclerView
|
|
15
|
-
|
|
16
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
|
17
|
-
super.onCreate(savedInstanceState)
|
|
18
|
-
setContentView(R.layout.activity_main)
|
|
19
|
-
|
|
20
|
-
viewModel = ViewModelProvider(this)[NoteViewModel::class.java]
|
|
21
|
-
|
|
22
|
-
recyclerView = findViewById(R.id.recyclerView)
|
|
23
|
-
adapter = NoteAdapter { note ->
|
|
24
|
-
// Handle note click - could open edit dialog
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
recyclerView.adapter = adapter
|
|
28
|
-
recyclerView.layoutManager = LinearLayoutManager(this)
|
|
29
|
-
|
|
30
|
-
val fabAdd: FloatingActionButton = findViewById(R.id.fabAdd)
|
|
31
|
-
fabAdd.setOnClickListener {
|
|
32
|
-
// Open add note dialog
|
|
33
|
-
showAddNoteDialog()
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
viewModel.allNotes.observe(this) { notes ->
|
|
37
|
-
adapter.submitList(notes)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private fun showAddNoteDialog() {
|
|
42
|
-
val dialog = AddNoteDialog { title, content ->
|
|
43
|
-
val note = Note(title = title, content = content)
|
|
44
|
-
viewModel.insert(note)
|
|
45
|
-
}
|
|
46
|
-
dialog.show(supportFragmentManager, "AddNoteDialog")
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
package com.dailynotes.app
|
|
2
|
-
|
|
3
|
-
import androidx.room.Entity
|
|
4
|
-
import androidx.room.PrimaryKey
|
|
5
|
-
|
|
6
|
-
@Entity(tableName = "notes")
|
|
7
|
-
data class Note(
|
|
8
|
-
@PrimaryKey(autoGenerate = true)
|
|
9
|
-
val id: Int = 0,
|
|
10
|
-
val title: String,
|
|
11
|
-
val content: String,
|
|
12
|
-
val createdAt: Long = System.currentTimeMillis()
|
|
13
|
-
)
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
pluginManagement {
|
|
2
|
-
repositories {
|
|
3
|
-
google()
|
|
4
|
-
mavenCentral()
|
|
5
|
-
gradlePluginPortal()
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
dependencyResolutionManagement {
|
|
9
|
-
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
|
10
|
-
repositories {
|
|
11
|
-
google()
|
|
12
|
-
mavenCentral()
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
rootProject.name = "DailyNotesApp"
|
|
17
|
-
include(":app")
|