create-airbnb-x-config 2.1.1 → 2.1.2
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/dist/lib/templates/configs.d.ts +13 -0
- package/dist/lib/templates/configs.js +205 -0
- package/dist/lib/templates/constants.d.ts +24 -0
- package/dist/lib/templates/constants.js +11 -0
- package/dist/lib/templates/contentFormatter.d.ts +4 -0
- package/dist/lib/templates/contentFormatter.js +12 -0
- package/dist/lib/templates/createDirectories.d.ts +3 -0
- package/dist/lib/templates/createDirectories.js +31 -0
- package/dist/lib/templates/getAllFolders.d.ts +19 -0
- package/dist/lib/templates/getAllFolders.js +29 -0
- package/dist/lib/templates/getContent.d.ts +17 -0
- package/dist/lib/templates/getContent.js +39 -0
- package/dist/lib/templates/getDefaultSubFolders.d.ts +7 -0
- package/dist/lib/templates/getDefaultSubFolders.js +102 -0
- package/dist/lib/templates/getFolders.d.ts +4 -0
- package/dist/lib/templates/getFolders.js +61 -0
- package/dist/lib/templates/index.d.ts +1 -0
- package/dist/lib/templates/index.js +25 -0
- package/dist/lib/templates/writeFiles.d.ts +3 -0
- package/dist/lib/templates/writeFiles.js +41 -0
- package/dist/package.json +3 -2
- package/package.json +3 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Content } from '../../lib/templates/contentFormatter';
|
|
2
|
+
import type { GetContentParams } from '../../lib/templates/getContent';
|
|
3
|
+
type Config = (params: GetContentParams) => Content;
|
|
4
|
+
export declare const startingComments: string[];
|
|
5
|
+
export declare const imports: Config;
|
|
6
|
+
export declare const gitignoreCode: string[];
|
|
7
|
+
export declare const jsConfig: Config;
|
|
8
|
+
export declare const reactConfig: Config;
|
|
9
|
+
export declare const nodeConfig: (string | string[])[];
|
|
10
|
+
export declare const typescriptConfig: Config;
|
|
11
|
+
export declare const prettierConfig: (string | (string | (string | string[])[])[])[];
|
|
12
|
+
export declare const defaultConfig: Config;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultConfig = exports.prettierConfig = exports.typescriptConfig = exports.nodeConfig = exports.reactConfig = exports.jsConfig = exports.gitignoreCode = exports.imports = exports.startingComments = void 0;
|
|
4
|
+
const constants_1 = require("../../constants");
|
|
5
|
+
const constants_2 = require("../../lib/templates/constants");
|
|
6
|
+
// STARTING COMMENTS
|
|
7
|
+
exports.startingComments = [
|
|
8
|
+
'/**',
|
|
9
|
+
' * THIS FILE WAS AUTO-GENERATED.',
|
|
10
|
+
' * PLEASE DO NOT EDIT IT MANUALLY.',
|
|
11
|
+
' * ===============================',
|
|
12
|
+
" * IF YOU'RE COPYING THIS INTO AN ESLINT CONFIG, REMOVE THIS COMMENT BLOCK.",
|
|
13
|
+
' */',
|
|
14
|
+
];
|
|
15
|
+
// IMPORTS
|
|
16
|
+
const imports = ({ type, configurations, strictConfig }) => {
|
|
17
|
+
const isLegacy = type === constants_1.configTypes.LEGACY;
|
|
18
|
+
const hasStrictConfig = strictConfig.length > 0;
|
|
19
|
+
const importStatement = (() => {
|
|
20
|
+
if (isLegacy)
|
|
21
|
+
return "import { configs } from 'eslint-config-airbnb-extended/legacy';";
|
|
22
|
+
if (hasStrictConfig) {
|
|
23
|
+
return "import { configs, plugins, rules } from 'eslint-config-airbnb-extended';";
|
|
24
|
+
}
|
|
25
|
+
return "import { configs, plugins } from 'eslint-config-airbnb-extended';";
|
|
26
|
+
})();
|
|
27
|
+
return [
|
|
28
|
+
"import path from 'node:path';",
|
|
29
|
+
'',
|
|
30
|
+
"import { includeIgnoreFile } from '@eslint/compat';",
|
|
31
|
+
"import js from '@eslint/js';",
|
|
32
|
+
importStatement,
|
|
33
|
+
...(configurations.prettier
|
|
34
|
+
? [
|
|
35
|
+
"import { rules as prettierConfigRules } from 'eslint-config-prettier';",
|
|
36
|
+
"import prettierPlugin from 'eslint-plugin-prettier';",
|
|
37
|
+
]
|
|
38
|
+
: []),
|
|
39
|
+
];
|
|
40
|
+
};
|
|
41
|
+
exports.imports = imports;
|
|
42
|
+
// GITIGNORE CONFIG
|
|
43
|
+
exports.gitignoreCode = ["const gitignorePath = path.resolve('.', '.gitignore');"];
|
|
44
|
+
// JAVASCRIPT CONFIG
|
|
45
|
+
const jsConfig = ({ type, language, strictConfig }) => {
|
|
46
|
+
const isLegacy = type === constants_1.configTypes.LEGACY;
|
|
47
|
+
const hasStrictImportConfig = strictConfig.includes(constants_1.strictConfigs.IMPORT);
|
|
48
|
+
const jsArray = (() => {
|
|
49
|
+
if (isLegacy) {
|
|
50
|
+
return language === constants_1.legacyLanguages.BASE
|
|
51
|
+
? ['// Airbnb Base Recommended Config', '...configs.base.recommended,']
|
|
52
|
+
: [];
|
|
53
|
+
}
|
|
54
|
+
return [
|
|
55
|
+
'// Stylistic Plugin',
|
|
56
|
+
'plugins.stylistic,',
|
|
57
|
+
'// Import X Plugin',
|
|
58
|
+
'plugins.importX,',
|
|
59
|
+
'// Airbnb Base Recommended Config',
|
|
60
|
+
'...configs.base.recommended,',
|
|
61
|
+
...(hasStrictImportConfig ? ['// Strict Import Config', 'rules.base.importsStrict,'] : []),
|
|
62
|
+
];
|
|
63
|
+
})();
|
|
64
|
+
return [
|
|
65
|
+
'const jsConfig = [',
|
|
66
|
+
[
|
|
67
|
+
'// ESLint Recommended Rules',
|
|
68
|
+
'{',
|
|
69
|
+
["name: 'js/config',", '...js.configs.recommended,'],
|
|
70
|
+
'},',
|
|
71
|
+
...jsArray,
|
|
72
|
+
],
|
|
73
|
+
'];',
|
|
74
|
+
];
|
|
75
|
+
};
|
|
76
|
+
exports.jsConfig = jsConfig;
|
|
77
|
+
// REACT & NEXT CONFIG
|
|
78
|
+
const reactConfig = ({ type, language, strictConfig }) => {
|
|
79
|
+
const isLegacy = type === constants_1.configTypes.LEGACY;
|
|
80
|
+
const isNextJs = language === constants_1.languages.NEXT;
|
|
81
|
+
const hasStrictReactConfig = strictConfig.includes(constants_1.strictConfigs.REACT);
|
|
82
|
+
const reactArray = [
|
|
83
|
+
'// React Plugin',
|
|
84
|
+
'plugins.react,',
|
|
85
|
+
'// React Hooks Plugin',
|
|
86
|
+
'plugins.reactHooks,',
|
|
87
|
+
'// React JSX A11y Plugin',
|
|
88
|
+
'plugins.reactA11y,',
|
|
89
|
+
];
|
|
90
|
+
const nextArray = ['// Next Plugin', 'plugins.next,'];
|
|
91
|
+
const legacyArray = [
|
|
92
|
+
'const reactConfig = [',
|
|
93
|
+
['// Airbnb React Recommended Config', '...configs.react.recommended,'],
|
|
94
|
+
language === constants_1.legacyLanguages.REACT_HOOKS
|
|
95
|
+
? ['// Airbnb React Hooks Config', '...configs.react.hooks,']
|
|
96
|
+
: [],
|
|
97
|
+
'];',
|
|
98
|
+
];
|
|
99
|
+
const extendedArray = [
|
|
100
|
+
`const ${language}Config = [`,
|
|
101
|
+
[
|
|
102
|
+
...reactArray,
|
|
103
|
+
...(isNextJs ? nextArray : []),
|
|
104
|
+
`// Airbnb ${isNextJs ? 'Next' : 'React'} Recommended Config`,
|
|
105
|
+
`...configs.${language}.recommended,`,
|
|
106
|
+
...(hasStrictReactConfig ? ['// Strict React Config', 'rules.react.strict,'] : []),
|
|
107
|
+
],
|
|
108
|
+
'];',
|
|
109
|
+
];
|
|
110
|
+
return isLegacy ? legacyArray : extendedArray;
|
|
111
|
+
};
|
|
112
|
+
exports.reactConfig = reactConfig;
|
|
113
|
+
// NODE CONFIG
|
|
114
|
+
exports.nodeConfig = [
|
|
115
|
+
'const nodeConfig = [',
|
|
116
|
+
[
|
|
117
|
+
'// Node Plugin',
|
|
118
|
+
'plugins.node,',
|
|
119
|
+
'// Airbnb Node Recommended Config',
|
|
120
|
+
'...configs.node.recommended,',
|
|
121
|
+
],
|
|
122
|
+
'];',
|
|
123
|
+
];
|
|
124
|
+
// TYPESCRIPT CONFIG
|
|
125
|
+
const typescriptConfig = ({ type, language, strictConfig }) => {
|
|
126
|
+
const isLegacy = type === constants_1.configTypes.LEGACY;
|
|
127
|
+
const reactArray = ['// Airbnb React TypeScript Config', '...configs.react.typescript,'];
|
|
128
|
+
const nextArray = ['// Airbnb Next TypeScript Config', '...configs.next.typescript,'];
|
|
129
|
+
const hasStrictTypescriptConfig = strictConfig.includes(constants_1.strictConfigs.TYPESCRIPT);
|
|
130
|
+
const legacyArray = [
|
|
131
|
+
'const typescriptConfig = [',
|
|
132
|
+
language === constants_1.legacyLanguages.BASE
|
|
133
|
+
? ['// Airbnb Base TypeScript Config', '...configs.base.typescript,']
|
|
134
|
+
: ['// Airbnb React TypeScript Config', '...configs.react.typescript,'],
|
|
135
|
+
'];',
|
|
136
|
+
];
|
|
137
|
+
const extendedArray = [
|
|
138
|
+
'const typescriptConfig = [',
|
|
139
|
+
[
|
|
140
|
+
'// TypeScript ESLint Plugin',
|
|
141
|
+
'plugins.typescriptEslint,',
|
|
142
|
+
'// Airbnb Base TypeScript Config',
|
|
143
|
+
'...configs.base.typescript,',
|
|
144
|
+
...(hasStrictTypescriptConfig
|
|
145
|
+
? ['// Strict TypeScript Config', 'rules.typescript.typescriptEslintStrict,']
|
|
146
|
+
: []),
|
|
147
|
+
...(language === constants_1.languages.REACT ? reactArray : []),
|
|
148
|
+
...(language === constants_1.languages.NEXT ? nextArray : []),
|
|
149
|
+
],
|
|
150
|
+
'];',
|
|
151
|
+
];
|
|
152
|
+
return isLegacy ? legacyArray : extendedArray;
|
|
153
|
+
};
|
|
154
|
+
exports.typescriptConfig = typescriptConfig;
|
|
155
|
+
// Prettier Config
|
|
156
|
+
exports.prettierConfig = [
|
|
157
|
+
'const prettierConfig = [',
|
|
158
|
+
[
|
|
159
|
+
'// Prettier Plugin',
|
|
160
|
+
'{',
|
|
161
|
+
["name: 'prettier/plugin/config',", 'plugins: {', ['prettier: prettierPlugin,'], '},'],
|
|
162
|
+
'},',
|
|
163
|
+
],
|
|
164
|
+
[
|
|
165
|
+
'// Prettier Config',
|
|
166
|
+
'{',
|
|
167
|
+
[
|
|
168
|
+
"name: 'prettier/config',",
|
|
169
|
+
'rules: {',
|
|
170
|
+
['...prettierConfigRules,', "'prettier/prettier': 'error',"],
|
|
171
|
+
'},',
|
|
172
|
+
],
|
|
173
|
+
'},',
|
|
174
|
+
],
|
|
175
|
+
'];',
|
|
176
|
+
];
|
|
177
|
+
// DEFAULT CONFIG
|
|
178
|
+
const defaultConfig = ({ type, language, languagePreference, configurations }) => {
|
|
179
|
+
const isLegacy = type === constants_1.configTypes.LEGACY;
|
|
180
|
+
const reactArray = ['// React Config', '...reactConfig,'];
|
|
181
|
+
const nextArray = ['// Next Config', '...nextConfig,'];
|
|
182
|
+
const typescriptArray = ['// TypeScript Config', '...typescriptConfig,'];
|
|
183
|
+
const nodeArray = ['// Node Config', '...nodeConfig,'];
|
|
184
|
+
const prettierArray = ['// Prettier Config', '...prettierConfig,'];
|
|
185
|
+
return [
|
|
186
|
+
'export default [',
|
|
187
|
+
[
|
|
188
|
+
'// Ignore .gitignore files/folder in eslint',
|
|
189
|
+
'includeIgnoreFile(gitignorePath),',
|
|
190
|
+
'// Javascript Config',
|
|
191
|
+
'...jsConfig,',
|
|
192
|
+
...((isLegacy &&
|
|
193
|
+
[constants_1.legacyLanguages.REACT, constants_1.legacyLanguages.REACT_HOOKS].includes(language)) ||
|
|
194
|
+
(!isLegacy && language === constants_1.languages.REACT)
|
|
195
|
+
? reactArray
|
|
196
|
+
: []),
|
|
197
|
+
...(!isLegacy && language === constants_1.languages.NEXT ? nextArray : []),
|
|
198
|
+
...(!isLegacy && language === constants_1.languages.NODE ? nodeArray : []),
|
|
199
|
+
...(languagePreference === constants_2.languagePreferences.TYPESCRIPT ? typescriptArray : []),
|
|
200
|
+
...(configurations.prettier ? prettierArray : []),
|
|
201
|
+
],
|
|
202
|
+
'];',
|
|
203
|
+
];
|
|
204
|
+
};
|
|
205
|
+
exports.defaultConfig = defaultConfig;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const templateConstants: {
|
|
2
|
+
readonly FOLDER_NAME: "templates";
|
|
3
|
+
};
|
|
4
|
+
export declare const languagePreferences: {
|
|
5
|
+
readonly JAVASCRIPT: "js";
|
|
6
|
+
readonly TYPESCRIPT: "ts";
|
|
7
|
+
};
|
|
8
|
+
export declare const subFolders: {
|
|
9
|
+
readonly DEFAULT: "default";
|
|
10
|
+
readonly PRETTIER: "prettier";
|
|
11
|
+
readonly BASE: "base";
|
|
12
|
+
readonly REACT: "react";
|
|
13
|
+
readonly REACT_HOOKS: "react-hooks";
|
|
14
|
+
readonly STRICT: "strict";
|
|
15
|
+
readonly STRICT_IMPORT: "import";
|
|
16
|
+
readonly STRICT_IMPORT_REACT: "import-react";
|
|
17
|
+
readonly STRICT_IMPORT_TYPESCRIPT: "import-typescript";
|
|
18
|
+
readonly STRICT_IMPORT_REACT_TYPESCRIPT: "import-react-typescript";
|
|
19
|
+
readonly STRICT_REACT: "react";
|
|
20
|
+
readonly STRICT_REACT_TYPESCRIPT: "react-typescript";
|
|
21
|
+
readonly STRICT_TYPESCRIPT: "typescript";
|
|
22
|
+
readonly JAVASCRIPT: "js";
|
|
23
|
+
readonly TYPESCRIPT: "ts";
|
|
24
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subFolders = exports.languagePreferences = exports.templateConstants = void 0;
|
|
4
|
+
exports.templateConstants = {
|
|
5
|
+
FOLDER_NAME: 'templates',
|
|
6
|
+
};
|
|
7
|
+
exports.languagePreferences = {
|
|
8
|
+
JAVASCRIPT: 'js',
|
|
9
|
+
TYPESCRIPT: 'ts',
|
|
10
|
+
};
|
|
11
|
+
exports.subFolders = Object.assign(Object.assign({}, exports.languagePreferences), { DEFAULT: 'default', PRETTIER: 'prettier', BASE: 'base', REACT: 'react', REACT_HOOKS: 'react-hooks', STRICT: 'strict', STRICT_IMPORT: 'import', STRICT_IMPORT_REACT: 'import-react', STRICT_IMPORT_TYPESCRIPT: 'import-typescript', STRICT_IMPORT_REACT_TYPESCRIPT: 'import-react-typescript', STRICT_REACT: 'react', STRICT_REACT_TYPESCRIPT: 'react-typescript', STRICT_TYPESCRIPT: 'typescript' });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const contentFormatter = (content, level = 0) => content.reduce((acc, val) => {
|
|
4
|
+
if (typeof val === 'string') {
|
|
5
|
+
acc.push(`${' '.repeat(level * 2)}${val}`);
|
|
6
|
+
}
|
|
7
|
+
if (Array.isArray(val)) {
|
|
8
|
+
acc.push(...contentFormatter(val, level + 1));
|
|
9
|
+
}
|
|
10
|
+
return acc;
|
|
11
|
+
}, []);
|
|
12
|
+
exports.default = contentFormatter;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
16
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
17
|
+
const constants_1 = require("../../lib/templates/constants");
|
|
18
|
+
const getFolders_1 = __importDefault(require("../../lib/templates/getFolders"));
|
|
19
|
+
const { FOLDER_NAME } = constants_1.templateConstants;
|
|
20
|
+
const createDirectories = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
if (node_fs_1.default.existsSync(FOLDER_NAME)) {
|
|
22
|
+
yield promises_1.default.rm(FOLDER_NAME, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
const allFolders = (0, getFolders_1.default)();
|
|
25
|
+
yield Promise.all(allFolders.map((folder) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
return promises_1.default.mkdir(folder.path, {
|
|
27
|
+
recursive: true,
|
|
28
|
+
});
|
|
29
|
+
})));
|
|
30
|
+
});
|
|
31
|
+
exports.default = createDirectories;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GetContentParams } from '../../lib/templates/getContent';
|
|
2
|
+
interface FolderMeta extends Partial<Pick<GetContentParams, 'language' | 'languagePreference' | 'strictConfig'>> {
|
|
3
|
+
configType?: GetContentParams['type'];
|
|
4
|
+
hasPrettier?: NonNullable<GetContentParams['configurations']>['prettier'];
|
|
5
|
+
}
|
|
6
|
+
interface Folder {
|
|
7
|
+
meta?: FolderMeta;
|
|
8
|
+
data?: Folders;
|
|
9
|
+
cond?: (folder: Required<Pick<Folder, 'meta'>>) => boolean;
|
|
10
|
+
}
|
|
11
|
+
export type Folders = Record<string, Folder>;
|
|
12
|
+
export interface GetFolder {
|
|
13
|
+
path: string;
|
|
14
|
+
meta: FolderMeta;
|
|
15
|
+
}
|
|
16
|
+
type GetAllFoldersOutput = GetFolder[];
|
|
17
|
+
type GetAllFolders = (folders: Folders, prefix: string[], meta?: FolderMeta) => GetAllFoldersOutput;
|
|
18
|
+
declare const getAllFolders: GetAllFolders;
|
|
19
|
+
export default getAllFolders;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getAllFolders = (folders, prefix, meta = {}) => Object.entries(folders).reduce((acc, val) => {
|
|
4
|
+
const [key, value] = val;
|
|
5
|
+
const prefixes = [...prefix, key];
|
|
6
|
+
const condition = value.cond ? value.cond({ meta }) : true;
|
|
7
|
+
const values = (() => {
|
|
8
|
+
if (value.data && condition) {
|
|
9
|
+
return Object.entries(value.data).reduce((subAcc, subVal) => {
|
|
10
|
+
const [subKey, subValue] = subVal;
|
|
11
|
+
const subFolders = { [subKey]: subValue };
|
|
12
|
+
const subMeta = Object.assign(Object.assign(Object.assign({}, meta), value.meta), subValue.meta);
|
|
13
|
+
const subCondition = subValue.cond ? subValue.cond({ meta: subMeta }) : true;
|
|
14
|
+
if (subCondition)
|
|
15
|
+
subAcc.push(...getAllFolders(subFolders, prefixes, subMeta));
|
|
16
|
+
return subAcc;
|
|
17
|
+
}, []);
|
|
18
|
+
}
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
path: prefixes.join('/'),
|
|
22
|
+
meta,
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
})();
|
|
26
|
+
acc.push(...values);
|
|
27
|
+
return acc;
|
|
28
|
+
}, []);
|
|
29
|
+
exports.default = getAllFolders;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { configTypes, languages, legacyLanguages } from '../../constants';
|
|
2
|
+
import { languagePreferences } from '../../lib/templates/constants';
|
|
3
|
+
import type { strictConfigs } from '../../constants';
|
|
4
|
+
import type { ValueOf } from '../../utils/types';
|
|
5
|
+
interface GetContentConfigurations {
|
|
6
|
+
prettier: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface GetContentParams {
|
|
9
|
+
type: ValueOf<typeof configTypes>;
|
|
10
|
+
language: Exclude<ValueOf<typeof languages>, typeof languages.OTHER> | ValueOf<typeof legacyLanguages>;
|
|
11
|
+
languagePreference: ValueOf<typeof languagePreferences>;
|
|
12
|
+
configurations: GetContentConfigurations;
|
|
13
|
+
strictConfig: ValueOf<typeof strictConfigs>[];
|
|
14
|
+
}
|
|
15
|
+
type GetContent = (params: GetContentParams) => string;
|
|
16
|
+
declare const getContent: GetContent;
|
|
17
|
+
export default getContent;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const constants_1 = require("../../constants");
|
|
7
|
+
const configs_1 = require("../../lib/templates/configs");
|
|
8
|
+
const constants_2 = require("../../lib/templates/constants");
|
|
9
|
+
const contentFormatter_1 = __importDefault(require("../../lib/templates/contentFormatter"));
|
|
10
|
+
const getContent = (params) => {
|
|
11
|
+
const { type, language, languagePreference, configurations } = params;
|
|
12
|
+
const isLegacy = type === constants_1.configTypes.LEGACY;
|
|
13
|
+
const reactArray = (isLegacy &&
|
|
14
|
+
[constants_1.legacyLanguages.REACT, constants_1.legacyLanguages.REACT_HOOKS].includes(language)) ||
|
|
15
|
+
(!isLegacy && [constants_1.languages.REACT, constants_1.languages.NEXT].includes(language))
|
|
16
|
+
? [...(0, configs_1.reactConfig)(params), '']
|
|
17
|
+
: [];
|
|
18
|
+
const typescriptArray = languagePreference === constants_2.languagePreferences.TYPESCRIPT ? [...(0, configs_1.typescriptConfig)(params), ''] : [];
|
|
19
|
+
const nodeArray = !isLegacy && language === constants_1.languages.NODE ? [...configs_1.nodeConfig, ''] : [];
|
|
20
|
+
const prettierArray = configurations.prettier ? [...configs_1.prettierConfig, ''] : [];
|
|
21
|
+
const defaultConfigArray = [...(0, configs_1.defaultConfig)(params), ''];
|
|
22
|
+
const content = (0, contentFormatter_1.default)([
|
|
23
|
+
...configs_1.startingComments,
|
|
24
|
+
'',
|
|
25
|
+
...(0, configs_1.imports)(params),
|
|
26
|
+
'',
|
|
27
|
+
...configs_1.gitignoreCode,
|
|
28
|
+
'',
|
|
29
|
+
...(0, configs_1.jsConfig)(params),
|
|
30
|
+
'',
|
|
31
|
+
...reactArray,
|
|
32
|
+
...nodeArray,
|
|
33
|
+
...typescriptArray,
|
|
34
|
+
...prettierArray,
|
|
35
|
+
...defaultConfigArray,
|
|
36
|
+
]);
|
|
37
|
+
return content.join('\n');
|
|
38
|
+
};
|
|
39
|
+
exports.default = getContent;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Folders } from '../../lib/templates/getAllFolders';
|
|
2
|
+
interface GetDefaultSubFoldersParams {
|
|
3
|
+
strict: boolean;
|
|
4
|
+
}
|
|
5
|
+
type GetDefaultSubFolders = (params: GetDefaultSubFoldersParams) => Folders;
|
|
6
|
+
declare const getDefaultSubFolders: GetDefaultSubFolders;
|
|
7
|
+
export default getDefaultSubFolders;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../../constants");
|
|
4
|
+
const constants_2 = require("../../lib/templates/constants");
|
|
5
|
+
const strictDefaultSubFolders = {
|
|
6
|
+
[constants_2.subFolders.STRICT]: {
|
|
7
|
+
data: {
|
|
8
|
+
[constants_2.subFolders.STRICT_IMPORT]: {
|
|
9
|
+
meta: {
|
|
10
|
+
strictConfig: [constants_1.strictConfigs.IMPORT],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
[constants_2.subFolders.STRICT_IMPORT_REACT]: {
|
|
14
|
+
meta: {
|
|
15
|
+
strictConfig: [constants_1.strictConfigs.IMPORT, constants_1.strictConfigs.REACT],
|
|
16
|
+
},
|
|
17
|
+
cond: ({ meta }) => {
|
|
18
|
+
if (meta.language) {
|
|
19
|
+
return [constants_1.languages.REACT, constants_1.languages.NEXT].includes(meta.language);
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
[constants_2.subFolders.STRICT_IMPORT_TYPESCRIPT]: {
|
|
25
|
+
meta: {
|
|
26
|
+
strictConfig: [constants_1.strictConfigs.IMPORT, constants_1.strictConfigs.TYPESCRIPT],
|
|
27
|
+
},
|
|
28
|
+
cond: ({ meta }) => meta.languagePreference === constants_2.languagePreferences.TYPESCRIPT,
|
|
29
|
+
},
|
|
30
|
+
[constants_2.subFolders.STRICT_IMPORT_REACT_TYPESCRIPT]: {
|
|
31
|
+
meta: {
|
|
32
|
+
strictConfig: [constants_1.strictConfigs.IMPORT, constants_1.strictConfigs.REACT, constants_1.strictConfigs.TYPESCRIPT],
|
|
33
|
+
},
|
|
34
|
+
cond: ({ meta }) => {
|
|
35
|
+
if (meta.language) {
|
|
36
|
+
const tsCond = meta.languagePreference === constants_2.languagePreferences.TYPESCRIPT;
|
|
37
|
+
const reactCond = [constants_1.languages.REACT, constants_1.languages.NEXT].includes(meta.language);
|
|
38
|
+
return tsCond && reactCond;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
[constants_2.subFolders.STRICT_REACT]: {
|
|
44
|
+
meta: {
|
|
45
|
+
strictConfig: [constants_1.strictConfigs.REACT],
|
|
46
|
+
},
|
|
47
|
+
cond: ({ meta }) => {
|
|
48
|
+
if (meta.language) {
|
|
49
|
+
return [constants_1.languages.REACT, constants_1.languages.NEXT].includes(meta.language);
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
[constants_2.subFolders.STRICT_REACT_TYPESCRIPT]: {
|
|
55
|
+
meta: {
|
|
56
|
+
strictConfig: [constants_1.strictConfigs.REACT, constants_1.strictConfigs.TYPESCRIPT],
|
|
57
|
+
},
|
|
58
|
+
cond: ({ meta }) => {
|
|
59
|
+
if (meta.language) {
|
|
60
|
+
const tsCond = meta.languagePreference === constants_2.languagePreferences.TYPESCRIPT;
|
|
61
|
+
const reactCond = [constants_1.languages.REACT, constants_1.languages.NEXT].includes(meta.language);
|
|
62
|
+
return tsCond && reactCond;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
[constants_2.subFolders.STRICT_TYPESCRIPT]: {
|
|
68
|
+
meta: {
|
|
69
|
+
strictConfig: [constants_1.strictConfigs.TYPESCRIPT],
|
|
70
|
+
},
|
|
71
|
+
cond: ({ meta }) => meta.languagePreference === constants_2.languagePreferences.TYPESCRIPT,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
meta: {},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const getDefaultSubFolders = ({ strict }) => {
|
|
78
|
+
const defaultFolders = Object.assign(Object.assign({}, (strict ? strictDefaultSubFolders : null)), { [constants_2.subFolders.DEFAULT]: {
|
|
79
|
+
meta: {},
|
|
80
|
+
} });
|
|
81
|
+
const defaultLanguagePreferencesSubFolders = {
|
|
82
|
+
[constants_2.subFolders.JAVASCRIPT]: {
|
|
83
|
+
data: defaultFolders,
|
|
84
|
+
meta: {
|
|
85
|
+
languagePreference: constants_2.languagePreferences.JAVASCRIPT,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
[constants_2.subFolders.TYPESCRIPT]: {
|
|
89
|
+
data: defaultFolders,
|
|
90
|
+
meta: {
|
|
91
|
+
languagePreference: constants_2.languagePreferences.TYPESCRIPT,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
return Object.assign(Object.assign({}, defaultLanguagePreferencesSubFolders), { [constants_2.subFolders.PRETTIER]: {
|
|
96
|
+
data: defaultLanguagePreferencesSubFolders,
|
|
97
|
+
meta: {
|
|
98
|
+
hasPrettier: true,
|
|
99
|
+
},
|
|
100
|
+
} });
|
|
101
|
+
};
|
|
102
|
+
exports.default = getDefaultSubFolders;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const constants_1 = require("../../constants");
|
|
7
|
+
const constants_2 = require("../../lib/templates/constants");
|
|
8
|
+
const getAllFolders_1 = __importDefault(require("../../lib/templates/getAllFolders"));
|
|
9
|
+
const getDefaultSubFolders_1 = __importDefault(require("../../lib/templates/getDefaultSubFolders"));
|
|
10
|
+
const getFolders = () => {
|
|
11
|
+
const folders = {
|
|
12
|
+
[constants_1.configTypes.LEGACY]: {
|
|
13
|
+
data: {
|
|
14
|
+
[constants_2.subFolders.BASE]: {
|
|
15
|
+
data: (0, getDefaultSubFolders_1.default)({ strict: false }),
|
|
16
|
+
meta: {
|
|
17
|
+
language: constants_1.legacyLanguages.BASE,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
[constants_2.subFolders.REACT]: {
|
|
21
|
+
data: (0, getDefaultSubFolders_1.default)({ strict: false }),
|
|
22
|
+
meta: {
|
|
23
|
+
language: constants_1.legacyLanguages.REACT,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
[constants_2.subFolders.REACT_HOOKS]: {
|
|
27
|
+
data: (0, getDefaultSubFolders_1.default)({ strict: false }),
|
|
28
|
+
meta: {
|
|
29
|
+
language: constants_1.legacyLanguages.REACT_HOOKS,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
meta: {
|
|
34
|
+
configType: constants_1.configTypes.LEGACY,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
[constants_1.languages.REACT]: {
|
|
38
|
+
data: (0, getDefaultSubFolders_1.default)({ strict: true }),
|
|
39
|
+
meta: {
|
|
40
|
+
configType: constants_1.configTypes.EXTENDED,
|
|
41
|
+
language: constants_1.languages.REACT,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
[constants_1.languages.NEXT]: {
|
|
45
|
+
data: (0, getDefaultSubFolders_1.default)({ strict: true }),
|
|
46
|
+
meta: {
|
|
47
|
+
configType: constants_1.configTypes.EXTENDED,
|
|
48
|
+
language: constants_1.languages.NEXT,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
[constants_1.languages.NODE]: {
|
|
52
|
+
data: (0, getDefaultSubFolders_1.default)({ strict: true }),
|
|
53
|
+
meta: {
|
|
54
|
+
configType: constants_1.configTypes.EXTENDED,
|
|
55
|
+
language: constants_1.languages.NODE,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
return (0, getAllFolders_1.default)(folders, [constants_2.templateConstants.FOLDER_NAME]);
|
|
60
|
+
};
|
|
61
|
+
exports.default = getFolders;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const createDirectories_1 = __importDefault(require("../../lib/templates/createDirectories"));
|
|
16
|
+
const writeFiles_1 = __importDefault(require("../../lib/templates/writeFiles"));
|
|
17
|
+
const utils_1 = require("../../utils");
|
|
18
|
+
const run = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
yield (0, createDirectories_1.default)();
|
|
20
|
+
yield (0, writeFiles_1.default)();
|
|
21
|
+
});
|
|
22
|
+
run()
|
|
23
|
+
.then(utils_1.success)
|
|
24
|
+
// eslint-disable-next-line unicorn/prefer-top-level-await
|
|
25
|
+
.catch((error) => console.error(error));
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
16
|
+
const getConfigUrl_1 = require("../../helpers/getConfigUrl");
|
|
17
|
+
const getContent_1 = __importDefault(require("../../lib/templates/getContent"));
|
|
18
|
+
const getFolders_1 = __importDefault(require("../../lib/templates/getFolders"));
|
|
19
|
+
const writeFiles = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const allFolders = (0, getFolders_1.default)();
|
|
21
|
+
yield Promise.all(allFolders.map((folder) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const { path, meta } = folder;
|
|
23
|
+
const { configType, language, languagePreference, hasPrettier, strictConfig } = meta;
|
|
24
|
+
if (!configType)
|
|
25
|
+
return;
|
|
26
|
+
const writePath = [path, getConfigUrl_1.eslintConfigName].join('/');
|
|
27
|
+
const data = (0, getContent_1.default)({
|
|
28
|
+
type: configType,
|
|
29
|
+
language: language,
|
|
30
|
+
languagePreference: languagePreference,
|
|
31
|
+
configurations: {
|
|
32
|
+
prettier: !!hasPrettier,
|
|
33
|
+
},
|
|
34
|
+
strictConfig: strictConfig !== null && strictConfig !== void 0 ? strictConfig : [],
|
|
35
|
+
});
|
|
36
|
+
return promises_1.default.writeFile(writePath, data, {
|
|
37
|
+
encoding: 'utf8',
|
|
38
|
+
});
|
|
39
|
+
})));
|
|
40
|
+
});
|
|
41
|
+
exports.default = writeFiles;
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-airbnb-x-config",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Airbnb Extended Config CLI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"build": "tsc -b",
|
|
37
37
|
"postbuild": "tsc-alias",
|
|
38
38
|
"build:templates": "tsx lib/templates/index.ts",
|
|
39
|
-
"
|
|
39
|
+
"dev": "tsx index.ts",
|
|
40
|
+
"start": "node ./dist/index.js",
|
|
40
41
|
"typecheck": "tsc --noEmit"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-airbnb-x-config",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Airbnb Extended Config CLI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
"build": "tsc -b",
|
|
52
52
|
"postbuild": "tsc-alias",
|
|
53
53
|
"build:templates": "tsx lib/templates/index.ts",
|
|
54
|
-
"
|
|
54
|
+
"dev": "tsx index.ts",
|
|
55
|
+
"start": "node ./dist/index.js",
|
|
55
56
|
"typecheck": "tsc --noEmit"
|
|
56
57
|
}
|
|
57
58
|
}
|