@create-mastery/cli 0.1.1 → 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 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)
@@ -86,7 +86,10 @@ program
86
86
  gen
87
87
  .command('schema')
88
88
  .description('generates the schema for the dictionaries')
89
- .action(() => genSchema())
89
+ .action(() => {
90
+ const projectRoot = requireProjectRoot()
91
+ genSchema(projectRoot)
92
+ })
90
93
 
91
94
  add
92
95
  .command('component')
@@ -103,6 +106,9 @@ add
103
106
  .command('language')
104
107
  .description('creates a new language for i18n')
105
108
  .argument('<language>', 'language to add')
106
- .action((language) => addLanguage(language))
109
+ .action((language) => {
110
+ const projectRoot = requireProjectRoot()
111
+ addLanguage(language, projectRoot)
112
+ })
107
113
 
108
114
  program.parse()
@@ -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 ?? '', '../../../src/i18n/types/locales.ts'),
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
- '../../../src/i18n/dictionaries/dictionaries-loaders.ts'
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
- '../../../src/i18n/dictionaries'
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(
@@ -2,18 +2,6 @@ import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import chalk from 'chalk'
4
4
  import * as GenerateSchema from 'generate-schema'
5
- import { findProjectRoot } from '../utils/find-project-root'
6
-
7
- const projectRoot = findProjectRoot()
8
-
9
- const dictionarieDir = path.resolve(projectRoot ?? '', 'src/i18n/dictionaries/')
10
- const dictionary = JSON.parse(
11
- fs.readFileSync(`${dictionarieDir}/en.json`, 'utf8')
12
- )
13
- const schemaPath = path.resolve(
14
- projectRoot ?? '',
15
- `${dictionarieDir}/schema.schema.json`
16
- )
17
5
 
18
6
  interface JsonSchema {
19
7
  type: string
@@ -44,7 +32,21 @@ function addRequiredRecursively(
44
32
  }
45
33
  }
46
34
 
47
- export function genSchema() {
35
+ export function genSchema(projectRoot: string) {
36
+ const dictionarieDir = path.resolve(
37
+ projectRoot ?? '',
38
+ 'src/i18n/dictionaries/'
39
+ )
40
+
41
+ const dictionary = JSON.parse(
42
+ fs.readFileSync(`${dictionarieDir}/en.json`, 'utf8')
43
+ )
44
+
45
+ const schemaPath = path.resolve(
46
+ projectRoot ?? '',
47
+ `${dictionarieDir}/schema.schema.json`
48
+ )
49
+
48
50
  const schema = GenerateSchema.json('dictionary schema', dictionary)
49
51
 
50
52
  addRequiredRecursively(schema, dictionary)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@create-mastery/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "The official Create Website CLI, created to enhance the DX",
5
5
  "homepage": "https://github.com/Create-Mastery/website/tree/main/cli#readme",
6
6
  "repository": {