@create-mastery/cli 0.1.2 → 0.1.3
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/cli.ts +5 -2
- package/commands/add/language.ts +11 -17
- package/package.json +1 -1
package/cli.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { execSync } from 'node:child_process'
|
|
4
4
|
import { readFileSync } from 'node:fs'
|
|
5
5
|
import path from 'node:path'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
6
7
|
import chalk from 'chalk'
|
|
7
8
|
import { program } from 'commander'
|
|
8
9
|
import gradient from 'gradient-string'
|
|
@@ -14,7 +15,6 @@ import printScripts from './commands/scripts'
|
|
|
14
15
|
import printVersion from './commands/version'
|
|
15
16
|
import { createMasteryASCIIArtBig } from './utils/arts'
|
|
16
17
|
import { requireProjectRoot } from './utils/require-project-root'
|
|
17
|
-
import { fileURLToPath } from 'node:url'
|
|
18
18
|
|
|
19
19
|
const __filename = fileURLToPath(import.meta.url)
|
|
20
20
|
const __dirname = path.dirname(__filename)
|
|
@@ -106,6 +106,9 @@ add
|
|
|
106
106
|
.command('language')
|
|
107
107
|
.description('creates a new language for i18n')
|
|
108
108
|
.argument('<language>', 'language to add')
|
|
109
|
-
.action((language) =>
|
|
109
|
+
.action((language) => {
|
|
110
|
+
const projectRoot = requireProjectRoot()
|
|
111
|
+
addLanguage(language, projectRoot)
|
|
112
|
+
})
|
|
110
113
|
|
|
111
114
|
program.parse()
|
package/commands/add/language.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
|
-
import { findProjectRoot } from '../../utils/find-project-root'
|
|
5
|
-
|
|
6
|
-
const projectRoot = findProjectRoot()
|
|
7
4
|
|
|
8
5
|
type Json =
|
|
9
6
|
| string
|
|
@@ -30,17 +27,17 @@ function stripValues(obj: Json): Json {
|
|
|
30
27
|
return obj
|
|
31
28
|
}
|
|
32
29
|
|
|
33
|
-
function genLocales(files: string[]) {
|
|
30
|
+
function genLocales(files: string[], projectRoot: string) {
|
|
34
31
|
const locales = files.map((f) => `'${f.replace('.json', '')}'`).join(' | ')
|
|
35
32
|
const content = `export type locales = ${locales}\n`
|
|
36
33
|
|
|
37
34
|
fs.writeFileSync(
|
|
38
|
-
path.resolve(projectRoot ?? '', '
|
|
35
|
+
path.resolve(projectRoot ?? '', 'src/i18n/types/locales.ts'),
|
|
39
36
|
content
|
|
40
37
|
)
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
function genI18n(files: string[]) {
|
|
40
|
+
function genI18n(files: string[], projectRoot: string) {
|
|
44
41
|
const locales = files
|
|
45
42
|
.map((f) => `'${f.replace('.json', '')}'`)
|
|
46
43
|
.join(',\n\t\t')
|
|
@@ -51,13 +48,10 @@ function genI18n(files: string[]) {
|
|
|
51
48
|
],
|
|
52
49
|
}`
|
|
53
50
|
|
|
54
|
-
fs.writeFileSync(
|
|
55
|
-
path.resolve(projectRoot ?? '', '../../../src/i18n/i18n.ts'),
|
|
56
|
-
content
|
|
57
|
-
)
|
|
51
|
+
fs.writeFileSync(path.resolve(projectRoot ?? '', 'src/i18n/i18n.ts'), content)
|
|
58
52
|
}
|
|
59
53
|
|
|
60
|
-
function genDictionaryLoaders(files: string[]) {
|
|
54
|
+
function genDictionaryLoaders(files: string[], projectRoot: string) {
|
|
61
55
|
const dictionaries = files.map((f) => f.replace('.json', ''))
|
|
62
56
|
|
|
63
57
|
let dictionariesLoaders: string = `import { type Locale } from '../config'\n\nexport const dictionariesLoaders: Locale = {\n`
|
|
@@ -71,16 +65,16 @@ function genDictionaryLoaders(files: string[]) {
|
|
|
71
65
|
fs.writeFileSync(
|
|
72
66
|
path.resolve(
|
|
73
67
|
projectRoot ?? '',
|
|
74
|
-
'
|
|
68
|
+
'src/i18n/dictionaries/dictionaries-loaders.ts'
|
|
75
69
|
),
|
|
76
70
|
dictionariesLoaders
|
|
77
71
|
)
|
|
78
72
|
}
|
|
79
73
|
|
|
80
|
-
export default function addLanguage(language: string) {
|
|
74
|
+
export default function addLanguage(language: string, projectRoot: string) {
|
|
81
75
|
const dictionarieDir = path.resolve(
|
|
82
76
|
projectRoot ?? '',
|
|
83
|
-
'
|
|
77
|
+
'src/i18n/dictionaries'
|
|
84
78
|
)
|
|
85
79
|
|
|
86
80
|
const input = JSON.parse(fs.readFileSync(`${dictionarieDir}/en.json`, 'utf8'))
|
|
@@ -111,9 +105,9 @@ export default function addLanguage(language: string) {
|
|
|
111
105
|
.readdirSync(dictionarieDir)
|
|
112
106
|
.filter((f) => f.endsWith('.json') && f !== 'schema.schema.json')
|
|
113
107
|
|
|
114
|
-
genDictionaryLoaders(files)
|
|
115
|
-
genLocales(files)
|
|
116
|
-
genI18n(files)
|
|
108
|
+
genDictionaryLoaders(files, projectRoot)
|
|
109
|
+
genLocales(files, projectRoot)
|
|
110
|
+
genI18n(files, projectRoot)
|
|
117
111
|
|
|
118
112
|
console.log(chalk.blue('Language - '), chalk.reset(language))
|
|
119
113
|
console.log(
|
package/package.json
CHANGED