@ceylar/ada 0.0.5 → 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/rollup.config.ts CHANGED
@@ -1,55 +1,55 @@
1
- import alias from '@rollup/plugin-alias';
2
- import babel from '@rollup/plugin-babel';
3
- import commonjs from '@rollup/plugin-commonjs';
4
- import json from '@rollup/plugin-json';
5
- import resolve from '@rollup/plugin-node-resolve';
6
- import typescript from '@rollup/plugin-typescript';
7
-
8
- import packageJSON from './package.json';
9
-
10
- import { resolve as resolvePath } from 'path';
11
- import copy from 'rollup-plugin-copy';
12
-
13
- const sourcemap = false;
14
- const input = 'src/index.ts';
15
- const banner = `/* @license ${packageJSON.name} v${packageJSON.version} */`;
16
-
17
- const isDev = process.env.NODE_ENV === 'development';
18
-
19
- /** @type {import('rollup').RollupOptions[]} */
20
- export default [
21
- {
22
- input,
23
- output: Object.values(packageJSON.bin).map((bin) => ({
24
- format: 'esm',
25
- file: bin,
26
- sourcemap,
27
- banner
28
- })),
29
- plugins: [
30
- alias({
31
- entries: [{ find: '@', replacement: resolvePath(__dirname, './src') }]
32
- }),
33
- resolve({
34
- extensions: ['.js', '.ts']
35
- }),
36
- commonjs({
37
- include: /node_modules/,
38
- ignoreDynamicRequires: true
39
- }),
40
- typescript({
41
- tsconfig: './tsconfig.json',
42
- compilerOptions: { noCheck: isDev },
43
- noForceEmit: true
44
- }),
45
- babel({
46
- exclude: /node_modules/,
47
- extensions: ['.js', '.ts']
48
- }),
49
- json(),
50
- copy({
51
- targets: [{ src: 'resources/*', dest: 'bin/resources' }]
52
- })
53
- ]
54
- }
55
- ];
1
+ import alias from '@rollup/plugin-alias';
2
+ import babel from '@rollup/plugin-babel';
3
+ import commonjs from '@rollup/plugin-commonjs';
4
+ import json from '@rollup/plugin-json';
5
+ import resolve from '@rollup/plugin-node-resolve';
6
+ import typescript from '@rollup/plugin-typescript';
7
+
8
+ import packageJSON from './package.json';
9
+
10
+ import { resolve as resolvePath } from 'path';
11
+ import copy from 'rollup-plugin-copy';
12
+
13
+ const sourcemap = false;
14
+ const input = 'src/index.ts';
15
+ const banner = `/* @license ${packageJSON.name} v${packageJSON.version} */`;
16
+
17
+ const isDev = process.env.NODE_ENV === 'development';
18
+
19
+ /** @type {import('rollup').RollupOptions[]} */
20
+ export default [
21
+ {
22
+ input,
23
+ output: Object.values(packageJSON.bin).map((bin) => ({
24
+ format: 'esm',
25
+ file: bin,
26
+ sourcemap,
27
+ banner
28
+ })),
29
+ plugins: [
30
+ alias({
31
+ entries: [{ find: '@', replacement: resolvePath(__dirname, './src') }]
32
+ }),
33
+ resolve({
34
+ extensions: ['.js', '.ts']
35
+ }),
36
+ commonjs({
37
+ include: /node_modules/,
38
+ ignoreDynamicRequires: true
39
+ }),
40
+ typescript({
41
+ tsconfig: './tsconfig.json',
42
+ compilerOptions: { noCheck: isDev },
43
+ noForceEmit: true
44
+ }),
45
+ babel({
46
+ exclude: /node_modules/,
47
+ extensions: ['.js', '.ts']
48
+ }),
49
+ json(),
50
+ copy({
51
+ targets: [{ src: 'resources/*', dest: 'bin/resources' }]
52
+ })
53
+ ]
54
+ }
55
+ ];
@@ -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 { 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,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,108 @@
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 { 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,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 { 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 };
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';