@ceylar/ada 0.0.9 → 0.0.11
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/.github/workflows/publish.yml +32 -29
- package/.github/workflows/test-version-on-pr.yml +38 -38
- package/babel.config.json +9 -9
- package/bin/index.js +8784 -0
- package/bin/resources/eslint.config.mjs +8 -0
- package/{prettier.config.mjs → bin/resources/prettier.config.mjs} +12 -12
- package/bin/resources/stylelint.config.mjs +7 -0
- package/bin/resources/tsconfig.json +37 -0
- package/eslint.config.ts +14 -0
- package/package.json +45 -51
- package/readme.md +3 -3
- package/resources/eslint.config.mjs +8 -67
- package/resources/prettier.config.mjs +12 -12
- package/resources/stylelint.config.mjs +7 -7
- package/resources/tsconfig.json +37 -37
- package/rollup.config.ts +56 -55
- package/src/cli/commands/get.ts +21 -21
- package/src/cli/commands/index.ts +3 -3
- package/src/cli/commands/init.ts +107 -108
- package/src/cli/commands/set.ts +13 -13
- package/src/cli/type.ts +12 -12
- package/src/cli/util.ts +23 -23
- package/src/config/get.ts +38 -38
- package/src/config/index.ts +4 -4
- package/src/config/schema.ts +19 -19
- package/src/config/set.ts +14 -14
- package/src/config/type.ts +8 -8
- package/src/entities/manager/index.ts +2 -2
- package/src/entities/manager/schema.ts +5 -5
- package/src/entities/manager/type.ts +7 -7
- package/src/index.ts +53 -52
- package/src/util/index.ts +3 -3
- package/src/util/isEmpty.ts +11 -11
- package/src/util/logger.ts +15 -15
- package/src/util/resolveCurrentDir.ts +7 -7
- package/tsconfig.json +34 -32
- package/eslint.config.mjs +0 -63
package/src/cli/commands/init.ts
CHANGED
|
@@ -1,108 +1,107 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Manager
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
case '
|
|
24
|
-
return `
|
|
25
|
-
case '
|
|
26
|
-
return `
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
childProcess
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
'eslint
|
|
52
|
-
'eslint-
|
|
53
|
-
'eslint-plugin-
|
|
54
|
-
'
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
['-
|
|
73
|
-
['-
|
|
74
|
-
['-
|
|
75
|
-
['-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
...
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
export { init };
|
|
1
|
+
import type { AppCommand } from '../type'
|
|
2
|
+
import type { Manager } from '@/entities/manager'
|
|
3
|
+
import { exec } from 'node:child_process'
|
|
4
|
+
|
|
5
|
+
import fsPromises from 'node:fs/promises'
|
|
6
|
+
import process from 'node:process'
|
|
7
|
+
import { z } from 'zod'
|
|
8
|
+
import { get } from '@/config'
|
|
9
|
+
import { managerSchema } from '@/entities/manager'
|
|
10
|
+
|
|
11
|
+
import { logger, resolveCurrentDir } from '@/util'
|
|
12
|
+
|
|
13
|
+
const initSchema = z.object({
|
|
14
|
+
prettier: z.boolean().optional(),
|
|
15
|
+
eslint: z.boolean().optional(),
|
|
16
|
+
typescript: z.boolean().optional(),
|
|
17
|
+
stylelint: z.boolean().optional(),
|
|
18
|
+
manager: managerSchema.optional(),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
function getInstallationString(manager: Manager, packages: string[]) {
|
|
22
|
+
switch (manager) {
|
|
23
|
+
case 'npm':
|
|
24
|
+
return `npm install --save-dev ${packages.join(' ')}`
|
|
25
|
+
case 'yarn':
|
|
26
|
+
return `yarn add --dev ${packages.join(' ')}`
|
|
27
|
+
case 'pnpm':
|
|
28
|
+
return `pnpm add --save-dev ${packages.join(' ')}`
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function installDependencies(manager: Manager, packages: string[]) {
|
|
33
|
+
const childProcess = exec(getInstallationString(manager, packages))
|
|
34
|
+
childProcess.stdout?.pipe(process.stdout)
|
|
35
|
+
childProcess.stderr?.pipe(process.stderr)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function copyResource(resource: string) {
|
|
39
|
+
await fsPromises.copyFile(resolveCurrentDir('resources', resource), resource)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type Init = z.infer<typeof initSchema>
|
|
43
|
+
const setupFunctionsDictionary: Record<Exclude<keyof Init, 'manager'>, (manager: Manager) => void> = {
|
|
44
|
+
prettier: async (manager) => {
|
|
45
|
+
await copyResource('prettier.config.mjs')
|
|
46
|
+
installDependencies(manager, ['prettier'])
|
|
47
|
+
},
|
|
48
|
+
eslint: async (manager) => {
|
|
49
|
+
await copyResource('eslint.config.mjs')
|
|
50
|
+
installDependencies(manager, [
|
|
51
|
+
'eslint',
|
|
52
|
+
'@eslint-react/eslint-plugin',
|
|
53
|
+
'eslint-plugin-react-refresh',
|
|
54
|
+
'@antfu/eslint-config',
|
|
55
|
+
])
|
|
56
|
+
},
|
|
57
|
+
typescript: async (manager) => {
|
|
58
|
+
await copyResource('tsconfig.json')
|
|
59
|
+
installDependencies(manager, ['typescript'])
|
|
60
|
+
},
|
|
61
|
+
stylelint: async (manager) => {
|
|
62
|
+
await copyResource('stylelint.config.mjs')
|
|
63
|
+
installDependencies(manager, ['stylelint', 'stylelint-config-standard-scss'])
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const init: AppCommand<typeof initSchema> = {
|
|
68
|
+
name: 'init',
|
|
69
|
+
description: 'initialize configs',
|
|
70
|
+
options: [
|
|
71
|
+
['-p, --prettier', 'setup prettier'],
|
|
72
|
+
['-e, --eslint', 'setup eslint'],
|
|
73
|
+
['-t, --typescript', 'setup typescript'],
|
|
74
|
+
['-s, --stylelint', 'setup stylelint'],
|
|
75
|
+
['-m, --manager <npm | yarn | pnpm>', 'package manager that will be used to install dependencies'],
|
|
76
|
+
],
|
|
77
|
+
schema: initSchema,
|
|
78
|
+
isDefault: true,
|
|
79
|
+
action: (options) => {
|
|
80
|
+
const optionsWithConfig = {
|
|
81
|
+
...get(),
|
|
82
|
+
...options,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const { manager, ...rest } = optionsWithConfig
|
|
86
|
+
|
|
87
|
+
if (!manager) {
|
|
88
|
+
return logger.error(
|
|
89
|
+
'Manager didn\'t specified. Please, set it up with `set` command or use -m or --manager option.',
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const initOptions = Object.entries(rest)
|
|
94
|
+
|
|
95
|
+
if (initOptions.length === 0) {
|
|
96
|
+
return logger.error('Specify at least one of the instrument to setup.')
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
initOptions.forEach(([key, value]) => {
|
|
100
|
+
if (value) {
|
|
101
|
+
setupFunctionsDictionary[key as keyof typeof rest](manager)
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { init }
|
package/src/cli/commands/set.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const set: AppCommand<typeof configSchema> = {
|
|
6
|
-
name: 'set',
|
|
7
|
-
description: 'sets variable to config',
|
|
8
|
-
options: [['-m, --manager <npm | yarn | pnpm>', 'package manager that will be used to install dependencies']],
|
|
9
|
-
schema: configSchema,
|
|
10
|
-
action: setConfig
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { set }
|
|
1
|
+
import type { AppCommand } from '../type'
|
|
2
|
+
|
|
3
|
+
import { configSchema, set as setConfig } from '@/config'
|
|
4
|
+
|
|
5
|
+
const set: AppCommand<typeof configSchema> = {
|
|
6
|
+
name: 'set',
|
|
7
|
+
description: 'sets variable to config',
|
|
8
|
+
options: [['-m, --manager <npm | yarn | pnpm>', 'package manager that will be used to install dependencies']],
|
|
9
|
+
schema: configSchema,
|
|
10
|
+
action: setConfig,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { set }
|
package/src/cli/type.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
|
|
3
|
-
interface AppCommand<Schema extends z.ZodType> {
|
|
4
|
-
name: string
|
|
5
|
-
description: string
|
|
6
|
-
options?: [string, string?][]
|
|
7
|
-
action: (options: z.infer<Schema>) => void
|
|
8
|
-
schema: Schema
|
|
9
|
-
isDefault?: true
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type { AppCommand }
|
|
1
|
+
import type { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
interface AppCommand<Schema extends z.ZodType> {
|
|
4
|
+
name: string
|
|
5
|
+
description: string
|
|
6
|
+
options?: [string, string?][]
|
|
7
|
+
action: (options: z.infer<Schema>) => void
|
|
8
|
+
schema: Schema
|
|
9
|
+
isDefault?: true
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type { AppCommand }
|
package/src/cli/util.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { ZodError } from 'zod'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const short = option[0].match(/(?<!-)-(\w)/)?.[1]
|
|
5
|
-
const long = option[0].match(/--(\w+)/)?.[1]
|
|
6
|
-
|
|
7
|
-
return { short, long }
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const option = declaredOptions.map(getOptionKeys).find(({ long, short }) => {
|
|
12
|
-
return long ? error.errors[0].path[0] === long : error.errors[0].path[0] === short
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
if (option) {
|
|
16
|
-
const { short, long } = option
|
|
17
|
-
const errorOption = argv.findLast(
|
|
18
|
-
|
|
19
|
-
return `Error in option "${errorOption}". ${error.errors[0].message}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { parseCliError }
|
|
1
|
+
import type { ZodError } from 'zod'
|
|
2
|
+
|
|
3
|
+
function getOptionKeys(option: [string, string?]) {
|
|
4
|
+
const short = option[0].match(/(?<!-)-(\w)/)?.[1]
|
|
5
|
+
const long = option[0].match(/--(\w+)/)?.[1]
|
|
6
|
+
|
|
7
|
+
return { short, long }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function parseCliError(error: ZodError, argv: string[], declaredOptions: [string, string?][]) {
|
|
11
|
+
const option = declaredOptions.map(getOptionKeys).find(({ long, short }) => {
|
|
12
|
+
return long ? error.errors[0].path[0] === long : error.errors[0].path[0] === short
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
if (option) {
|
|
16
|
+
const { short, long } = option
|
|
17
|
+
const errorOption = argv.findLast(arg => arg === `-${short}` || arg === `--${long}`)
|
|
18
|
+
|
|
19
|
+
return `Error in option "${errorOption}". ${error.errors[0].message}`
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { parseCliError }
|
package/src/config/get.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
interface Get {
|
|
8
|
-
(): Config
|
|
9
|
-
<T extends SelectConfig>(configSelect: SelectConfig): Pick<Config, T extends SelectConfig ? keyof T : never
|
|
10
|
-
<T extends keyof Config>(key: T): Config[T]
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const get = ((key: keyof Config | SelectConfig | undefined) => {
|
|
14
|
-
const configPath = resolveCurrentDir('config.json')
|
|
15
|
-
const exists = fs.existsSync(configPath)
|
|
16
|
-
|
|
17
|
-
if (!exists) {
|
|
18
|
-
return {} as Config
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8')) as Config
|
|
22
|
-
|
|
23
|
-
if (key && typeof key === 'object') {
|
|
24
|
-
return Object.fromEntries(
|
|
25
|
-
Object.entries(key)
|
|
26
|
-
.filter(([key]) => config[key as keyof SelectConfig] !== undefined)
|
|
27
|
-
.map(([key]) => [key, config[key as keyof SelectConfig]] as const)
|
|
28
|
-
) as Pick<Config, keyof SelectConfig
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (key) {
|
|
32
|
-
return config[key]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return config
|
|
36
|
-
}) as Get
|
|
37
|
-
|
|
38
|
-
export { get }
|
|
1
|
+
import type { Config, SelectConfig } from './type'
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
|
|
5
|
+
import { resolveCurrentDir } from '@/util'
|
|
6
|
+
|
|
7
|
+
interface Get {
|
|
8
|
+
(): Config
|
|
9
|
+
<T extends SelectConfig>(configSelect: SelectConfig): Pick<Config, T extends SelectConfig ? keyof T : never>
|
|
10
|
+
<T extends keyof Config>(key: T): Config[T]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const get = ((key: keyof Config | SelectConfig | undefined) => {
|
|
14
|
+
const configPath = resolveCurrentDir('config.json')
|
|
15
|
+
const exists = fs.existsSync(configPath)
|
|
16
|
+
|
|
17
|
+
if (!exists) {
|
|
18
|
+
return {} as Config
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8')) as Config
|
|
22
|
+
|
|
23
|
+
if (key && typeof key === 'object') {
|
|
24
|
+
return Object.fromEntries(
|
|
25
|
+
Object.entries(key)
|
|
26
|
+
.filter(([key]) => config[key as keyof SelectConfig] !== undefined)
|
|
27
|
+
.map(([key]) => [key, config[key as keyof SelectConfig]] as const),
|
|
28
|
+
) as Pick<Config, keyof SelectConfig>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (key) {
|
|
32
|
+
return config[key]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return config
|
|
36
|
+
}) as Get
|
|
37
|
+
|
|
38
|
+
export { get }
|
package/src/config/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { get } from './get'
|
|
2
|
-
export { configSchema, selectConfigSchema as keysConfigSchema } from './schema'
|
|
3
|
-
export { set } from './set'
|
|
4
|
-
export { type Config } from './type'
|
|
1
|
+
export { get } from './get'
|
|
2
|
+
export { configSchema, selectConfigSchema as keysConfigSchema } from './schema'
|
|
3
|
+
export { set } from './set'
|
|
4
|
+
export { type Config } from './type'
|
package/src/config/schema.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const configShape = {
|
|
6
|
-
manager: managerSchema.optional()
|
|
7
|
-
}
|
|
8
|
-
const configSchema = z.object(configShape)
|
|
9
|
-
|
|
10
|
-
type ToSelectConfigType<T> = {
|
|
11
|
-
[K in keyof T]: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
-
}
|
|
13
|
-
const selectConfigSchema = z.object(
|
|
14
|
-
Object.fromEntries(configSchema.keyof().options.map(
|
|
15
|
-
typeof configShape
|
|
16
|
-
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
export { configSchema, selectConfigSchema }
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import { managerSchema } from '@/entities/manager'
|
|
4
|
+
|
|
5
|
+
const configShape = {
|
|
6
|
+
manager: managerSchema.optional(),
|
|
7
|
+
}
|
|
8
|
+
const configSchema = z.object(configShape)
|
|
9
|
+
|
|
10
|
+
type ToSelectConfigType<T> = {
|
|
11
|
+
[K in keyof T]: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
}
|
|
13
|
+
const selectConfigSchema = z.object(
|
|
14
|
+
Object.fromEntries(configSchema.keyof().options.map(key => [key, z.boolean().optional()])) as ToSelectConfigType<
|
|
15
|
+
typeof configShape
|
|
16
|
+
>,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
export { configSchema, selectConfigSchema }
|
package/src/config/set.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const configPath = resolveCurrentDir('config.json')
|
|
10
|
-
const config = get()
|
|
11
|
-
fs.writeFileSync(configPath, JSON.stringify({ ...config, ...newConfigData }))
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { set }
|
|
1
|
+
import type { Config } from './type'
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
|
|
5
|
+
import { resolveCurrentDir } from '@/util'
|
|
6
|
+
import { get } from './get'
|
|
7
|
+
|
|
8
|
+
function set(newConfigData: Config) {
|
|
9
|
+
const configPath = resolveCurrentDir('config.json')
|
|
10
|
+
const config = get()
|
|
11
|
+
fs.writeFileSync(configPath, JSON.stringify({ ...config, ...newConfigData }))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { set }
|
package/src/config/type.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
type Config = z.infer<typeof configSchema
|
|
6
|
-
type SelectConfig = z.infer<typeof selectConfigSchema
|
|
7
|
-
|
|
8
|
-
export type { Config, SelectConfig }
|
|
1
|
+
import type { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import type { configSchema, selectConfigSchema } from './schema'
|
|
4
|
+
|
|
5
|
+
type Config = z.infer<typeof configSchema>
|
|
6
|
+
type SelectConfig = z.infer<typeof selectConfigSchema>
|
|
7
|
+
|
|
8
|
+
export type { Config, SelectConfig }
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { managerSchema } from './schema'
|
|
2
|
-
export type { Manager } from './type'
|
|
1
|
+
export { managerSchema } from './schema'
|
|
2
|
+
export type { Manager } from './type'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
|
|
3
|
-
const managerSchema = z.enum(['npm', 'yarn', 'pnpm'])
|
|
4
|
-
|
|
5
|
-
export { managerSchema }
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
const managerSchema = z.enum(['npm', 'yarn', 'pnpm'])
|
|
4
|
+
|
|
5
|
+
export { managerSchema }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
type Manager = z.infer<typeof managerSchema
|
|
6
|
-
|
|
7
|
-
export type { Manager }
|
|
1
|
+
import type { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import type { managerSchema } from './schema'
|
|
4
|
+
|
|
5
|
+
type Manager = z.infer<typeof managerSchema>
|
|
6
|
+
|
|
7
|
+
export type { Manager }
|
package/src/index.ts
CHANGED
|
@@ -1,52 +1,53 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
program.name('ada')
|
|
11
|
-
program.version(packageJSON.version)
|
|
12
|
-
|
|
13
|
-
Object.values(commands).
|
|
14
|
-
const currentCommand = program.command(command.name, {
|
|
15
|
-
isDefault: command.isDefault
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
currentCommand.description(command.description)
|
|
19
|
-
|
|
20
|
-
command.options?.forEach((option) => {
|
|
21
|
-
currentCommand.option(option[0], option[1])
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
currentCommand.action((options) => {
|
|
25
|
-
const { success, data, error } = command.schema.safeParse(options)
|
|
26
|
-
if (success) {
|
|
27
|
-
// @ts-expect-error: type inference
|
|
28
|
-
command.action(data)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
// .
|
|
38
|
-
// .
|
|
39
|
-
// .option('-
|
|
40
|
-
// .
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
//
|
|
46
|
-
// .
|
|
47
|
-
// .
|
|
48
|
-
// .
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from 'node:process'
|
|
3
|
+
|
|
4
|
+
import { program } from 'commander'
|
|
5
|
+
import * as commands from '@/cli/commands'
|
|
6
|
+
import { parseCliError } from '@/cli/util'
|
|
7
|
+
import { logger } from '@/util'
|
|
8
|
+
import packageJSON from '../package.json'
|
|
9
|
+
|
|
10
|
+
program.name('ada')
|
|
11
|
+
program.version(packageJSON.version)
|
|
12
|
+
|
|
13
|
+
Object.values(commands).forEach((command) => {
|
|
14
|
+
const currentCommand = program.command(command.name, {
|
|
15
|
+
isDefault: command.isDefault,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
currentCommand.description(command.description)
|
|
19
|
+
|
|
20
|
+
command.options?.forEach((option) => {
|
|
21
|
+
currentCommand.option(option[0], option[1])
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
currentCommand.action((options) => {
|
|
25
|
+
const { success, data, error } = command.schema.safeParse(options)
|
|
26
|
+
if (success) {
|
|
27
|
+
// @ts-expect-error: type inference
|
|
28
|
+
command.action(data)
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
logger.error(`${parseCliError(error, process.argv, command.options || [])}`)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// program
|
|
37
|
+
// .command('init', { isDefault: true })
|
|
38
|
+
// .description('initialize configs')
|
|
39
|
+
// .option('-p, --prettier', 'setup prettier')
|
|
40
|
+
// .option('-e, --eslint', 'setup eslint')
|
|
41
|
+
// .action((options) => {
|
|
42
|
+
// console.log('init', options);
|
|
43
|
+
// });
|
|
44
|
+
|
|
45
|
+
// program
|
|
46
|
+
// .command('set')
|
|
47
|
+
// .description('sets variable to config')
|
|
48
|
+
// .option('-m, --manager <npm | yarn | pnpm>', 'package manager that will be used to install dependencies')
|
|
49
|
+
// .action((options) => {
|
|
50
|
+
// console.log('set', options);
|
|
51
|
+
// });
|
|
52
|
+
|
|
53
|
+
program.parse(process.argv)
|
package/src/util/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { isEmpty } from './isEmpty'
|
|
2
|
-
export { logger } from './logger'
|
|
3
|
-
export { resolveCurrentDir } from './resolveCurrentDir'
|
|
1
|
+
export { isEmpty } from './isEmpty'
|
|
2
|
+
export { logger } from './logger'
|
|
3
|
+
export { resolveCurrentDir } from './resolveCurrentDir'
|