Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli-logger): enhance login, storing file in XDG file path
Create the user if it doesn't exist Update logs Use spinner for authentication
- Loading branch information
1 parent
cbf0d32
commit b544834
Showing
7 changed files
with
164 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 49 additions & 5 deletions
54
packages/core/strapi/src/commands/actions/cloud/config/local.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,59 @@ | ||
import path from 'path'; | ||
import os from 'os'; | ||
import fs from 'fs'; | ||
import XDGAppPaths from 'xdg-app-paths'; | ||
|
||
export const TMP_DIR = path.join(os.tmpdir(), 'strapi-cli'); | ||
export const TMP_TOKEN_FILE = 'strapi.cloud'; | ||
const APP_FOLDER_NAME = 'com.strapi.cli'; | ||
|
||
export const CONFIG_FILENAME = 'config.json'; | ||
|
||
export type LocalConfig = { | ||
token?: string; | ||
}; | ||
|
||
function checkDirectoryExists(directoryPath: string) { | ||
try { | ||
return fs.lstatSync(directoryPath).isDirectory(); | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
// Determine storage path based on the operating system | ||
export function getStoragePath() { | ||
const storagePath = TMP_DIR; | ||
if (!fs.existsSync(storagePath)) { | ||
export function getTmpStoragePath() { | ||
const storagePath = path.join(os.tmpdir(), APP_FOLDER_NAME); | ||
if (!checkDirectoryExists(storagePath)) { | ||
fs.mkdirSync(storagePath, { recursive: true }); | ||
} | ||
return storagePath; | ||
} | ||
|
||
function getConfigPath() { | ||
const configDirs = XDGAppPaths(APP_FOLDER_NAME).configDirs(); | ||
const configPath = configDirs.find(checkDirectoryExists); | ||
|
||
if (!configPath) { | ||
fs.mkdirSync(configDirs[0], { recursive: true }); | ||
return configDirs[0]; | ||
} | ||
return configPath; | ||
} | ||
|
||
export function getLocalConfig(): LocalConfig { | ||
const configPath = getConfigPath(); | ||
const configFilePath = path.join(configPath, CONFIG_FILENAME); | ||
if (!fs.existsSync(configFilePath)) { | ||
return {}; | ||
} | ||
try { | ||
return JSON.parse(fs.readFileSync(configFilePath, 'utf8')); | ||
} catch (e) { | ||
return {}; | ||
} | ||
} | ||
|
||
export function saveLocalConfig(data: LocalConfig) { | ||
const configPath = getConfigPath(); | ||
const configFilePath = path.join(configPath, CONFIG_FILENAME); | ||
fs.writeFileSync(configFilePath, JSON.stringify(data), { encoding: 'utf8', mode: 0o600 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters