@ceylar/ada 0.0.10 → 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.
@@ -1,21 +1,21 @@
1
- import { get as getConfig } from '@/config';
2
- import { selectConfigSchema } from '@/config/schema';
3
- import { isEmpty } from '@/util';
4
-
5
- import { AppCommand } from '../type';
6
-
7
- const get: AppCommand<typeof selectConfigSchema> = {
8
- name: 'get',
9
- description: 'get variables from config',
10
- options: [['-m, --manager', 'package manager that will be used to install dependencies']],
11
- schema: selectConfigSchema,
12
- action: (options) => {
13
- if (isEmpty(options)) {
14
- console.log(getConfig());
15
- return;
16
- }
17
- console.log(getConfig(options));
18
- }
19
- };
20
-
21
- export { get };
1
+ import type { AppCommand } from '../type'
2
+ import { get as getConfig } from '@/config'
3
+ import { selectConfigSchema } from '@/config/schema'
4
+
5
+ import { isEmpty } from '@/util'
6
+
7
+ const get: AppCommand<typeof selectConfigSchema> = {
8
+ name: 'get',
9
+ description: 'get variables from config',
10
+ options: [['-m, --manager', 'package manager that will be used to install dependencies']],
11
+ schema: selectConfigSchema,
12
+ action: (options) => {
13
+ if (isEmpty(options)) {
14
+ console.log(getConfig())
15
+ return
16
+ }
17
+ console.log(getConfig(options))
18
+ },
19
+ }
20
+
21
+ export { get }
@@ -1,3 +1,3 @@
1
- export { get } from './get';
2
- export { init } from './init';
3
- export { set } from './set';
1
+ export { get } from './get'
2
+ export { init } from './init'
3
+ export { set } from './set'
@@ -1,108 +1,107 @@
1
- import { get } from '@/config';
2
- import { Manager, managerSchema } from '@/entities/manager';
3
- import { logger, resolveCurrentDir } from '@/util';
4
-
5
- import { AppCommand } from '../type';
6
-
7
- import { exec } from 'child_process';
8
- import fsPromises from 'fs/promises';
9
- import { z } from 'zod';
10
-
11
- const initSchema = z.object({
12
- prettier: z.boolean().optional(),
13
- eslint: z.boolean().optional(),
14
- typescript: z.boolean().optional(),
15
- stylelint: z.boolean().optional(),
16
- manager: managerSchema.optional()
17
- });
18
-
19
- const getInstallationString = (manager: Manager, packages: string[]) => {
20
- switch (manager) {
21
- case 'npm':
22
- return `npm install --save-dev ${packages.join(' ')}`;
23
- case 'yarn':
24
- return `yarn add --dev ${packages.join(' ')}`;
25
- case 'pnpm':
26
- return `pnpm add --save-dev ${packages.join(' ')}`;
27
- }
28
- };
29
-
30
- const installDependencies = (manager: Manager, packages: string[]) => {
31
- const childProcess = exec(getInstallationString(manager, packages));
32
- childProcess.stdout?.pipe(process.stdout);
33
- childProcess.stderr?.pipe(process.stderr);
34
- };
35
-
36
- const copyResource = async (resource: string) => {
37
- await fsPromises.copyFile(resolveCurrentDir('resources', resource), resource);
38
- };
39
-
40
- type Init = z.infer<typeof initSchema>;
41
- const setupFunctionsDictionary: Record<Exclude<keyof Init, 'manager'>, (manager: Manager) => void> = {
42
- prettier: async (manager) => {
43
- await copyResource('prettier.config.mjs');
44
- installDependencies(manager, ['prettier']);
45
- },
46
- eslint: async (manager) => {
47
- await copyResource('eslint.config.mjs');
48
- installDependencies(manager, [
49
- 'eslint',
50
- '@eslint/js',
51
- 'eslint-plugin-react',
52
- 'eslint-plugin-react-hooks',
53
- 'eslint-plugin-simple-import-sort',
54
- 'globals',
55
- 'typescript-eslint'
56
- ]);
57
- },
58
- typescript: async (manager) => {
59
- await copyResource('tsconfig.json');
60
- installDependencies(manager, ['typescript']);
61
- },
62
- stylelint: async (manager) => {
63
- await copyResource('stylelint.config.mjs');
64
- installDependencies(manager, ['stylelint', 'stylelint-config-standard-scss']);
65
- }
66
- };
67
-
68
- const init: AppCommand<typeof initSchema> = {
69
- name: 'init',
70
- description: 'initialize configs',
71
- options: [
72
- ['-p, --prettier', 'setup prettier'],
73
- ['-e, --eslint', 'setup eslint'],
74
- ['-t, --typescript', 'setup typescript'],
75
- ['-s, --stylelint', 'setup stylelint'],
76
- ['-m, --manager <npm | yarn | pnpm>', 'package manager that will be used to install dependencies']
77
- ],
78
- schema: initSchema,
79
- isDefault: true,
80
- action: (options) => {
81
- const optionsWithConfig = {
82
- ...get(),
83
- ...options
84
- };
85
-
86
- const { manager, ...rest } = optionsWithConfig;
87
-
88
- if (!manager) {
89
- return logger.error(
90
- "Manager didn't specified. Please, set it up with `set` command or use -m or --manager option."
91
- );
92
- }
93
-
94
- const initOptions = Object.entries(rest);
95
-
96
- if (initOptions.length === 0) {
97
- return logger.error('Specify at least one of the instrument to setup.');
98
- }
99
-
100
- initOptions.forEach(([key, value]) => {
101
- if (value) {
102
- setupFunctionsDictionary[key as keyof typeof rest](manager);
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 }
@@ -1,13 +1,13 @@
1
- import { configSchema, set as setConfig } from '@/config';
2
-
3
- import { AppCommand } from '../type';
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
- const 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
- const 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 };
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 { resolveCurrentDir } from '@/util';
2
-
3
- import { Config, SelectConfig } from './type';
4
-
5
- import fs from 'fs';
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 }
@@ -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'
@@ -1,19 +1,19 @@
1
- import { managerSchema } from '@/entities/manager';
2
-
3
- import { z } from 'zod';
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 };
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 { resolveCurrentDir } from '@/util';
2
-
3
- import { get } from './get';
4
- import { Config } from './type';
5
-
6
- import fs from 'fs';
7
-
8
- const 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 };
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 }
@@ -1,8 +1,8 @@
1
- import { configSchema, selectConfigSchema } from './schema';
2
-
3
- import { z } from 'zod';
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 { managerSchema } from './schema';
2
-
3
- import { z } from 'zod';
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 }