@ceylar/ada 0.0.6 → 0.0.7

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/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 { 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 { 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 };
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 { 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,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 { 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 };
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 { 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,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 { 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,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 { managerSchema } from './schema';
2
+
3
+ import { z } from 'zod';
4
+
5
+ type Manager = z.infer<typeof managerSchema>;
6
+
7
+ export type { Manager };
package/src/index.ts CHANGED
@@ -1,52 +1,52 @@
1
- #!/usr/bin/env node
2
- import * as commands from '@/cli/commands';
3
- import { parseCliError } from '@/cli/util';
4
- import { logger } from '@/util';
5
-
6
- import packageJSON from '../package.json';
7
-
8
- import { program } from 'commander';
9
-
10
- program.name('ada');
11
- program.version(packageJSON.version);
12
-
13
- Object.values(commands).map((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
- } else {
30
- logger.error(`${parseCliError(error, process.argv, command.options || [])}`);
31
- }
32
- });
33
- });
34
-
35
- // program
36
- // .command('init', { isDefault: true })
37
- // .description('initialize configs')
38
- // .option('-p, --prettier', 'setup prettier')
39
- // .option('-e, --eslint', 'setup eslint')
40
- // .action((options) => {
41
- // console.log('init', options);
42
- // });
43
-
44
- // program
45
- // .command('set')
46
- // .description('sets variable to config')
47
- // .option('-m, --manager <npm | yarn | pnpm>', 'package manager that will be used to install dependencies')
48
- // .action((options) => {
49
- // console.log('set', options);
50
- // });
51
-
52
- program.parse(process.argv);
1
+ #!/usr/bin/env node
2
+ import * as commands from '@/cli/commands';
3
+ import { parseCliError } from '@/cli/util';
4
+ import { logger } from '@/util';
5
+
6
+ import packageJSON from '../package.json';
7
+
8
+ import { program } from 'commander';
9
+
10
+ program.name('ada');
11
+ program.version(packageJSON.version);
12
+
13
+ Object.values(commands).map((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
+ } else {
30
+ logger.error(`${parseCliError(error, process.argv, command.options || [])}`);
31
+ }
32
+ });
33
+ });
34
+
35
+ // program
36
+ // .command('init', { isDefault: true })
37
+ // .description('initialize configs')
38
+ // .option('-p, --prettier', 'setup prettier')
39
+ // .option('-e, --eslint', 'setup eslint')
40
+ // .action((options) => {
41
+ // console.log('init', options);
42
+ // });
43
+
44
+ // program
45
+ // .command('set')
46
+ // .description('sets variable to config')
47
+ // .option('-m, --manager <npm | yarn | pnpm>', 'package manager that will be used to install dependencies')
48
+ // .action((options) => {
49
+ // console.log('set', options);
50
+ // });
51
+
52
+ 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';
@@ -1,11 +1,11 @@
1
- const isEmpty = (obj: object) => {
2
- for (const prop in obj) {
3
- if (Object.hasOwn(obj, prop)) {
4
- return false;
5
- }
6
- }
7
-
8
- return true;
9
- };
10
-
11
- export { isEmpty };
1
+ const isEmpty = (obj: object) => {
2
+ for (const prop in obj) {
3
+ if (Object.hasOwn(obj, prop)) {
4
+ return false;
5
+ }
6
+ }
7
+
8
+ return true;
9
+ };
10
+
11
+ export { isEmpty };
@@ -1,15 +1,15 @@
1
- const logger = {
2
- info(message: string) {
3
- console.log(`\x1b[32m${message}\x1b[0m`);
4
- },
5
-
6
- warn(message: string) {
7
- console.log(`\x1b[33m${message}\x1b[0m`);
8
- },
9
-
10
- error(message: string) {
11
- console.log(`\x1b[31m${message}\x1b[0m`);
12
- }
13
- };
14
-
15
- export { logger };
1
+ const logger = {
2
+ info(message: string) {
3
+ console.log(`\x1b[32m${message}\x1b[0m`);
4
+ },
5
+
6
+ warn(message: string) {
7
+ console.log(`\x1b[33m${message}\x1b[0m`);
8
+ },
9
+
10
+ error(message: string) {
11
+ console.log(`\x1b[31m${message}\x1b[0m`);
12
+ }
13
+ };
14
+
15
+ export { logger };
@@ -1,7 +1,7 @@
1
- import { resolve } from 'path';
2
-
3
- const resolveCurrentDir = (...paths: string[]) => {
4
- return resolve(import.meta.dirname, ...paths);
5
- };
6
-
7
- export { resolveCurrentDir };
1
+ import { resolve } from 'path';
2
+
3
+ const resolveCurrentDir = (...paths: string[]) => {
4
+ return resolve(import.meta.dirname, ...paths);
5
+ };
6
+
7
+ export { resolveCurrentDir };
package/tsconfig.json CHANGED
@@ -1,32 +1,32 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "lib": [
5
- "ES2023",
6
- "dom"
7
- ],
8
- "module": "ESNext",
9
- "skipLibCheck": true,
10
- /* Bundler mode */
11
- "moduleResolution": "bundler",
12
- "allowImportingTsExtensions": true,
13
- "isolatedModules": true,
14
- "moduleDetection": "force",
15
- "noEmit": true,
16
- /* Linting */
17
- "strict": true,
18
- "noUnusedLocals": true,
19
- "noUnusedParameters": true,
20
- "noFallthroughCasesInSwitch": true,
21
- "noUncheckedSideEffectImports": true,
22
- "baseUrl": ".",
23
- "paths": {
24
- "@/*": [
25
- "./src/*"
26
- ]
27
- }
28
- },
29
- "include": [
30
- "src/**/*.ts"
31
- ]
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": [
5
+ "ES2023",
6
+ "dom"
7
+ ],
8
+ "module": "ESNext",
9
+ "skipLibCheck": true,
10
+ /* Bundler mode */
11
+ "moduleResolution": "bundler",
12
+ "allowImportingTsExtensions": true,
13
+ "isolatedModules": true,
14
+ "moduleDetection": "force",
15
+ "noEmit": true,
16
+ /* Linting */
17
+ "strict": true,
18
+ "noUnusedLocals": true,
19
+ "noUnusedParameters": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedSideEffectImports": true,
22
+ "baseUrl": ".",
23
+ "paths": {
24
+ "@/*": [
25
+ "./src/*"
26
+ ]
27
+ }
28
+ },
29
+ "include": [
30
+ "src/**/*.ts"
31
+ ]
32
32
  }