|
1 | 1 | import fs from 'node:fs'; |
2 | 2 | import os from 'node:os'; |
3 | | -import { dirname, join } from 'node:path'; |
| 3 | +import { dirname, join, basename } from 'node:path'; |
4 | 4 | import { fileURLToPath } from 'node:url'; |
5 | 5 |
|
6 | 6 | const isLinux = os.platform() === 'linux'; |
7 | 7 | const root = dirname(fileURLToPath(import.meta.url)); |
8 | 8 | const configDir = join(os.homedir(), '.css-doodle'); |
9 | 9 | const configFilePath = join(configDir, 'config.json'); |
10 | 10 | const configDownloadDir = join(configDir, 'download'); |
| 11 | +const pkgInfo = JSON.parse(read('../package.json')); |
11 | 12 |
|
12 | 13 | if (!fs.existsSync(configDir)) { |
13 | 14 | fs.mkdirSync(configDir); |
@@ -45,6 +46,12 @@ function getDefaultAppArgs() { |
45 | 46 | return args; |
46 | 47 | } |
47 | 48 |
|
| 49 | +function getPackageInfo() { |
| 50 | + let name = basename(process.argv[1]); |
| 51 | + let programName = pkgInfo.bin?.[name] ? name : 'cssd'; |
| 52 | + return Object.assign(pkgInfo, { programName }); |
| 53 | +} |
| 54 | + |
48 | 55 | export function getCssDoodleLib() { |
49 | 56 | const libPath = config['css-doodle']; |
50 | 57 | if (libPath) { |
@@ -78,7 +85,7 @@ export const config = JSON.parse(fs.readFileSync(configFilePath), 'utf8'); |
78 | 85 | export const configPath = configFilePath; |
79 | 86 | export const configDownloadPath = configDownloadDir; |
80 | 87 |
|
81 | | -export const pkg = JSON.parse(read('../package.json')); |
82 | 88 | export const previewClient = read('./preview/client.html'); |
83 | 89 | export const previewServerPath = join(root, './preview/server.js'); |
84 | 90 | export const defaultAppArgs = getDefaultAppArgs(); |
| 91 | +export const pkg = getPackageInfo(); |
0 commit comments