@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/.github/workflows/publish.yml +31 -0
- package/babel.config.json +8 -8
- package/bin/index.js +2 -2
- package/bin/resources/eslint.config.mjs +67 -67
- package/bin/resources/prettier.config.mjs +12 -12
- package/bin/resources/stylelint.config.mjs +7 -7
- package/bin/resources/tsconfig.json +36 -36
- package/eslint.config.mjs +63 -63
- package/package.json +51 -51
- package/prettier.config.mjs +12 -12
- package/readme.md +3 -3
- package/resources/eslint.config.mjs +67 -67
- package/resources/prettier.config.mjs +12 -12
- package/resources/stylelint.config.mjs +7 -7
- package/resources/tsconfig.json +36 -36
- package/rollup.config.ts +55 -55
- package/src/cli/commands/get.ts +21 -21
- package/src/cli/commands/index.ts +3 -3
- package/src/cli/commands/init.ts +108 -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 +52 -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 +31 -31
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import js from '@eslint/js';
|
|
2
|
-
import react from 'eslint-plugin-react';
|
|
3
|
-
import reactHooks from 'eslint-plugin-react-hooks';
|
|
4
|
-
import simpleImportSort from 'eslint-plugin-simple-import-sort';
|
|
5
|
-
import globals from 'globals';
|
|
6
|
-
import ts from 'typescript-eslint';
|
|
7
|
-
|
|
8
|
-
/** @type {import('eslint').Linter.Config<Linter.RulesRecord>[]} */
|
|
9
|
-
export default ts.config(
|
|
10
|
-
js.configs.recommended,
|
|
11
|
-
...ts.configs.recommended,
|
|
12
|
-
{
|
|
13
|
-
plugins: {
|
|
14
|
-
react: react,
|
|
15
|
-
'react-hooks': reactHooks,
|
|
16
|
-
'simple-import-sort': simpleImportSort,
|
|
17
|
-
ts: ts.plugin
|
|
18
|
-
},
|
|
19
|
-
rules: {
|
|
20
|
-
'prefer-const': 'error',
|
|
21
|
-
'no-else-return': 'error',
|
|
22
|
-
|
|
23
|
-
'react-hooks/exhaustive-deps': 'off',
|
|
24
|
-
|
|
25
|
-
'no-console': 'warn',
|
|
26
|
-
|
|
27
|
-
'simple-import-sort/exports': 'error',
|
|
28
|
-
'simple-import-sort/imports': [
|
|
29
|
-
'error',
|
|
30
|
-
{
|
|
31
|
-
groups: [
|
|
32
|
-
['^react', '^@?\\w'],
|
|
33
|
-
['^@(([\\/.]?\\w)|assets|test-utils)'],
|
|
34
|
-
['^\\u0000'],
|
|
35
|
-
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
|
|
36
|
-
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
|
|
37
|
-
['^.+\\.s?css$']
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
},
|
|
42
|
-
languageOptions: {
|
|
43
|
-
globals: {
|
|
44
|
-
...globals.node,
|
|
45
|
-
...globals.browser,
|
|
46
|
-
...globals.es2022
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
languageOptions: {
|
|
52
|
-
parserOptions: {
|
|
53
|
-
project: ['tsconfig.json']
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
files: ['/src/**/*.ts', '/src/**/*.tsx']
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
languageOptions: {
|
|
60
|
-
parserOptions: react.configs.recommended.parserOptions
|
|
61
|
-
},
|
|
62
|
-
files: ['/src/**/*.js', '/src/**/*.jsx']
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
ignores: ['node_modules', 'build', 'dist']
|
|
66
|
-
}
|
|
67
|
-
);
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import react from 'eslint-plugin-react';
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
|
4
|
+
import simpleImportSort from 'eslint-plugin-simple-import-sort';
|
|
5
|
+
import globals from 'globals';
|
|
6
|
+
import ts from 'typescript-eslint';
|
|
7
|
+
|
|
8
|
+
/** @type {import('eslint').Linter.Config<Linter.RulesRecord>[]} */
|
|
9
|
+
export default ts.config(
|
|
10
|
+
js.configs.recommended,
|
|
11
|
+
...ts.configs.recommended,
|
|
12
|
+
{
|
|
13
|
+
plugins: {
|
|
14
|
+
react: react,
|
|
15
|
+
'react-hooks': reactHooks,
|
|
16
|
+
'simple-import-sort': simpleImportSort,
|
|
17
|
+
ts: ts.plugin
|
|
18
|
+
},
|
|
19
|
+
rules: {
|
|
20
|
+
'prefer-const': 'error',
|
|
21
|
+
'no-else-return': 'error',
|
|
22
|
+
|
|
23
|
+
'react-hooks/exhaustive-deps': 'off',
|
|
24
|
+
|
|
25
|
+
'no-console': 'warn',
|
|
26
|
+
|
|
27
|
+
'simple-import-sort/exports': 'error',
|
|
28
|
+
'simple-import-sort/imports': [
|
|
29
|
+
'error',
|
|
30
|
+
{
|
|
31
|
+
groups: [
|
|
32
|
+
['^react', '^@?\\w'],
|
|
33
|
+
['^@(([\\/.]?\\w)|assets|test-utils)'],
|
|
34
|
+
['^\\u0000'],
|
|
35
|
+
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
|
|
36
|
+
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
|
|
37
|
+
['^.+\\.s?css$']
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
languageOptions: {
|
|
43
|
+
globals: {
|
|
44
|
+
...globals.node,
|
|
45
|
+
...globals.browser,
|
|
46
|
+
...globals.es2022
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
languageOptions: {
|
|
52
|
+
parserOptions: {
|
|
53
|
+
project: ['tsconfig.json']
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
files: ['/src/**/*.ts', '/src/**/*.tsx']
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
languageOptions: {
|
|
60
|
+
parserOptions: react.configs.recommended.parserOptions
|
|
61
|
+
},
|
|
62
|
+
files: ['/src/**/*.js', '/src/**/*.jsx']
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
ignores: ['node_modules', 'build', 'dist']
|
|
66
|
+
}
|
|
67
|
+
);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/** @type {import('prettier').Config} */
|
|
2
|
-
export default {
|
|
3
|
-
printWidth: 120,
|
|
4
|
-
singleQuote: true,
|
|
5
|
-
jsxSingleQuote: true,
|
|
6
|
-
trailingComma: 'none',
|
|
7
|
-
semi: true,
|
|
8
|
-
tabWidth: 2,
|
|
9
|
-
useTabs: false,
|
|
10
|
-
endOfLine: 'crlf',
|
|
11
|
-
arrowParens: 'always'
|
|
12
|
-
};
|
|
1
|
+
/** @type {import('prettier').Config} */
|
|
2
|
+
export default {
|
|
3
|
+
printWidth: 120,
|
|
4
|
+
singleQuote: true,
|
|
5
|
+
jsxSingleQuote: true,
|
|
6
|
+
trailingComma: 'none',
|
|
7
|
+
semi: true,
|
|
8
|
+
tabWidth: 2,
|
|
9
|
+
useTabs: false,
|
|
10
|
+
endOfLine: 'crlf',
|
|
11
|
+
arrowParens: 'always'
|
|
12
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/** @type {import('stylelint').Config} */
|
|
2
|
-
export default {
|
|
3
|
-
extends: 'stylelint-config-standard-scss',
|
|
4
|
-
rules: {
|
|
5
|
-
'selector-class-pattern': ['^[a-z][a-zA-Z0-9]*$', { message: 'Selector should be in camelCase' }]
|
|
6
|
-
}
|
|
7
|
-
};
|
|
1
|
+
/** @type {import('stylelint').Config} */
|
|
2
|
+
export default {
|
|
3
|
+
extends: 'stylelint-config-standard-scss',
|
|
4
|
+
rules: {
|
|
5
|
+
'selector-class-pattern': ['^[a-z][a-zA-Z0-9]*$', { message: 'Selector should be in camelCase' }]
|
|
6
|
+
}
|
|
7
|
+
};
|
package/resources/tsconfig.json
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "esnext",
|
|
4
|
-
"lib": [
|
|
5
|
-
"dom",
|
|
6
|
-
"dom.iterable",
|
|
7
|
-
"esnext"
|
|
8
|
-
],
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"allowSyntheticDefaultImports": true,
|
|
13
|
-
"strict": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"module": "esnext",
|
|
16
|
-
"newLine": "lf",
|
|
17
|
-
"moduleResolution": "bundler",
|
|
18
|
-
"isolatedModules": true,
|
|
19
|
-
"resolveJsonModule": true,
|
|
20
|
-
"noEmit": true,
|
|
21
|
-
"jsx": "react-jsx",
|
|
22
|
-
"sourceMap": true,
|
|
23
|
-
"noUnusedLocals": true,
|
|
24
|
-
"noUnusedParameters": true,
|
|
25
|
-
"noFallthroughCasesInSwitch": true,
|
|
26
|
-
"baseUrl": ".",
|
|
27
|
-
"paths": {
|
|
28
|
-
"@/*": [
|
|
29
|
-
"./src/*"
|
|
30
|
-
],
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"exclude": [
|
|
34
|
-
"dist",
|
|
35
|
-
"node_modules",
|
|
36
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"module": "esnext",
|
|
16
|
+
"newLine": "lf",
|
|
17
|
+
"moduleResolution": "bundler",
|
|
18
|
+
"isolatedModules": true,
|
|
19
|
+
"resolveJsonModule": true,
|
|
20
|
+
"noEmit": true,
|
|
21
|
+
"jsx": "react-jsx",
|
|
22
|
+
"sourceMap": true,
|
|
23
|
+
"noUnusedLocals": true,
|
|
24
|
+
"noUnusedParameters": true,
|
|
25
|
+
"noFallthroughCasesInSwitch": true,
|
|
26
|
+
"baseUrl": ".",
|
|
27
|
+
"paths": {
|
|
28
|
+
"@/*": [
|
|
29
|
+
"./src/*"
|
|
30
|
+
],
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"exclude": [
|
|
34
|
+
"dist",
|
|
35
|
+
"node_modules",
|
|
36
|
+
]
|
|
37
37
|
}
|
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
|
+
];
|
package/src/cli/commands/get.ts
CHANGED
|
@@ -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';
|
package/src/cli/commands/init.ts
CHANGED
|
@@ -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 };
|
package/src/cli/commands/set.ts
CHANGED
|
@@ -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 };
|