-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move some utils to @revili/helpers
- Loading branch information
Showing
30 changed files
with
185 additions
and
180 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,3 @@ interface KitOptions { | |
|
||
export default demoKit | ||
``` | ||
|
||
## Kit Data Management | ||
|
||
### |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./composables/index.js"; | ||
export * from './paths.js' | ||
export * from "./utils/index.js"; | ||
export * from "./composables/index.js"; |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os from 'node:os' | ||
import process from 'node:process' | ||
import { resolve } from 'node:path' | ||
|
||
// Environment variable for data directory | ||
const USER_DATA_DIR_ENV = 'REVILI_DATA_DIR' | ||
|
||
// Get the current working directory | ||
export const CWD = process.cwd() | ||
|
||
// Base user data directory structure | ||
const homeDir = os.homedir() | ||
const defaultDataDir = resolve(homeDir, '.revili') | ||
|
||
// Allow custom data directory through environment variable | ||
export const USER_DATA_PATH = process.env[USER_DATA_DIR_ENV] | ||
? resolve(process.env[USER_DATA_DIR_ENV]) | ||
: defaultDataDir | ||
|
||
// Organized data subdirectories | ||
export const DATA_DIRS = { | ||
// Directory for storing revili kits | ||
kits: resolve(USER_DATA_PATH, 'kits'), | ||
// Directory for storing kit-specific data | ||
kitsData: resolve(USER_DATA_PATH, 'kitsData') | ||
} as const | ||
|
||
// Specific data file paths | ||
export const DATA_FILES = { | ||
package: resolve(DATA_DIRS.kits, 'package.json'), | ||
config: resolve(USER_DATA_PATH, 'revili.config.json') | ||
} as const |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { CAC } from "cac"; |
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,3 +1,3 @@ | ||
import chalk from 'chalk'; | ||
|
||
export default chalk; | ||
export { chalk } |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { default as gitlyAlias } from 'gitly' | ||
|
||
export const gitly = gitlyAlias.default | ||
|
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,7 +1,9 @@ | ||
import { ora, spinner } from './ora.js'; | ||
import chalk from './chalk.js'; | ||
import inquirer from './inquirer.js'; | ||
|
||
export { ora, spinner, chalk, inquirer } | ||
|
||
export * from "./defineKit.js"; | ||
export * from './cac.js' | ||
export * from './ora.js' | ||
export * from './gitly.js' | ||
export * from './chalk.js' | ||
export * from './kitData.js' | ||
export * from './inquirer.js' | ||
export * from './defineKit.js' | ||
export * from './reviliData.js' | ||
export * from './childProcess.js' |
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,3 +1,3 @@ | ||
import inquirer from 'inquirer'; | ||
|
||
export default inquirer | ||
export { inquirer } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import { pathToFileURL } from 'node:url' | ||
import { CWD, DATA_FILES, DATA_DIRS, USER_DATA_PATH } from '../paths.js' | ||
|
||
import { Kit } from './defineKit.js' | ||
|
||
export interface ReviliConfig { | ||
activeKit: string | ||
kitList: string[] | ||
} | ||
|
||
export async function initConfigFolder() { | ||
if (!fs.existsSync(DATA_DIRS.kits)) { | ||
fs.mkdirSync(DATA_DIRS.kits, { recursive: true }) | ||
} | ||
|
||
if (!fs.existsSync(DATA_FILES.package)) { | ||
// add package.json into config folder | ||
setPackageConfig() | ||
} | ||
} | ||
|
||
export async function getReviliConfig(): Promise<ReviliConfig> { | ||
const isExistConfigFile = fs.existsSync(DATA_FILES.config) | ||
if (!isExistConfigFile) { | ||
// create config folder | ||
fs.mkdirSync(USER_DATA_PATH, { recursive: true }) | ||
setReviliConfig() | ||
} | ||
|
||
try { | ||
const content = await fs.promises.readFile(DATA_FILES.config, 'utf-8') | ||
return JSON.parse(content) | ||
} catch (error) { | ||
// Return default config if file doesn't exist or is invalid | ||
return { | ||
activeKit: '', | ||
kitList: [] | ||
} | ||
} | ||
} | ||
|
||
export async function setReviliConfig(config: ReviliConfig = { | ||
activeKit: '', | ||
kitList: [] | ||
}): Promise<void> { | ||
try { | ||
// Ensure parent directory exists | ||
fs.mkdirSync(USER_DATA_PATH, { recursive: true }) | ||
fs.writeFileSync(DATA_FILES.config, JSON.stringify(config, null, 2)) | ||
} catch (error) { | ||
console.error('[revili] Failed to write config') | ||
} | ||
} | ||
|
||
export function setPackageConfig() { | ||
try { | ||
// Ensure the directory exists | ||
fs.mkdirSync(DATA_DIRS.kits, { recursive: true }) | ||
fs.writeFileSync(DATA_FILES.package, JSON.stringify({ | ||
name: 'revili_kits', | ||
type: 'module' | ||
}, null, 2)) | ||
} catch (error) { | ||
console.error('[revili] Failed to write package.json') | ||
} | ||
} | ||
|
||
export async function getActiveKit(customKitDir: string) { | ||
try { | ||
const { activeKit: activeKitName } = await getReviliConfig(); | ||
|
||
const ACTIVE_KIT_DIR = path.join(USER_DATA_PATH, `./node_modules/${activeKitName}`); | ||
|
||
const CLIENT_DIR = customKitDir | ||
? path.join(CWD, `${customKitDir}/client`) | ||
: path.join(ACTIVE_KIT_DIR, `./dist/client`); | ||
|
||
const ACTIVE_KIT_ENTRY = customKitDir | ||
? path.join(CWD, `${customKitDir}/node/index.js`) | ||
: path.join(ACTIVE_KIT_DIR, `./dist/node/index.js`); | ||
const activeKit = (await import(pathToFileURL(ACTIVE_KIT_ENTRY) as unknown as string)).default as Kit; | ||
|
||
return { activeKit, CLIENT_DIR } | ||
} catch(error) { | ||
return { activeKit: null, CLIENT_DIR: '' } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,28 @@ | ||
import os from 'node:os' | ||
import process from 'node:process' | ||
import { resolve } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
// Environment variable for data directory | ||
const USER_DATA_DIR_ENV = 'REVILI_DATA_DIR' | ||
|
||
// Get the current working directory | ||
export const CWD = process.cwd() | ||
import { resolve } from 'node:path' | ||
import { | ||
CWD, | ||
DATA_DIRS, | ||
DATA_FILES, | ||
USER_DATA_PATH | ||
} from '@revili/helpers/node' | ||
|
||
// Get the root directory of the package | ||
export const PKG_ROOT = resolve(fileURLToPath(import.meta.url), '../..') | ||
const PKG_ROOT = resolve(fileURLToPath(import.meta.url), '../..') | ||
|
||
// Path to the client distribution directory | ||
export const DIST_CLIENT_PATH = resolve(PKG_ROOT, 'client') | ||
const DIST_CLIENT_PATH = resolve(PKG_ROOT, 'client') | ||
|
||
// Directory containing CLI-related files | ||
export const CLI_FILE_DIR = resolve(fileURLToPath(import.meta.url), '..') | ||
|
||
// Base user data directory structure | ||
const homeDir = os.homedir() | ||
const defaultDataDir = resolve(homeDir, '.revili') | ||
|
||
// Allow custom data directory through environment variable | ||
// This is useful for: | ||
// 1. Different user profiles or workspaces | ||
// 2. Custom deployment environments | ||
// 3. Systems with specific data storage requirements | ||
export const USER_DATA_PATH = process.env[USER_DATA_DIR_ENV] | ||
? resolve(process.env[USER_DATA_DIR_ENV]) | ||
: defaultDataDir | ||
|
||
// Organized data subdirectories | ||
export const DATA_DIRS = { | ||
// Directory for storing revili kits | ||
kits: resolve(USER_DATA_PATH, 'kits'), | ||
// Directory for storing kit-specific data | ||
kitsData: resolve(USER_DATA_PATH, 'kitsData') | ||
} as const | ||
|
||
// Specific data file paths | ||
export const DATA_FILES = { | ||
package: resolve(DATA_DIRS.kits, 'package.json'), | ||
config: resolve(USER_DATA_PATH, 'revili.config.json') | ||
} as const | ||
const CLI_FILE_DIR = resolve(fileURLToPath(import.meta.url), '..') | ||
|
||
// Export all path constants | ||
export const PATHS = { | ||
CWD, | ||
PKG_ROOT, | ||
DIST_CLIENT_PATH, | ||
DATA_DIRS, | ||
DATA_FILES, | ||
CLI_FILE_DIR, | ||
USER_DATA_PATH, | ||
DATA_DIRS, | ||
DATA_FILES | ||
DIST_CLIENT_PATH, | ||
} as const |
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
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
Oops, something went wrong.