Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

chore(cli): add create-user command to manage user creation

johaven203af802f2c1
diff --git a/scripts/npm-sync-in-server.js b/scripts/npm-sync-in-server.js
index 9db42b83..e5c5206f 100644
--- a/scripts/npm-sync-in-server.js
+++ b/scripts/npm-sync-in-server.js
@@ -20,6 +20,7 @@ const fs = require('fs')
// Paths relative to this script
const PKILL_GRACEFUL_TIMEOUT = 10000 // 10s timeout
const ROOT_DIR = path.resolve(__dirname)
+const CREATE_USER_SCRIPT = path.join(ROOT_DIR, 'server', 'infrastructure', 'database', 'scripts', 'create-user.js')
const SERVER_ENTRY = path.join(ROOT_DIR, 'server', 'main.js')
const ENV_DIST_FILE = path.join(ROOT_DIR, 'environment', 'environment.dist.yaml')
const ENV_DIST_MIN_FILE = path.join(ROOT_DIR, 'environment', 'environment.dist.min.yaml')
@@ -40,6 +41,7 @@ Available commands:
status Show server status (daemon mode only)
version Show installed sync-in-server version
migrate-db Run database migrations
+ create-user Create an admin user in the database
update Update the server version
help Show this help message
@@ -47,6 +49,7 @@ Examples:
npx sync-in-server init # copy default environment.yaml
npx sync-in-server start # attached mode
npx sync-in-server start -d # daemon mode
+ npx sync-in-server create-user --role admin --login "userLogin" --password "userPassword"
npx sync-in-server version
npx sync-in-server help
`)
@@ -224,6 +227,17 @@ async function updateVersion() {
console.log('✅ Sync-in Server updated.')
}
+async function createUser(args) {
+ console.log('👤 Creating user in database...')
+ const scriptArgs = [CREATE_USER_SCRIPT, ...args]
+ const result = spawnSync('node', scriptArgs, { stdio: 'inherit' })
+ if (result.status !== 0) {
+ console.error('❌ User creation failed.')
+ process.exit(result.status)
+ }
+ console.log('✅ User created successfully.')
+}
+
function getPackageJson() {
try {
const pkgPath = path.join(ROOT_DIR, 'package.json')
@@ -294,6 +308,9 @@ function waitForProcessExit(pid) {
case 'migrate-db':
migrateDatabase()
break
+ case 'create-user':
+ createUser(args.slice(1)).catch(console.error)
+ break
case 'update':
updateVersion().catch(console.error)
break