mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
build: refactor linting setup
This commit is contained in:
@@ -1 +1,18 @@
|
||||
module.exports = require('../../.prettierrc.json');
|
||||
/** @type {import('prettier').Config} */
|
||||
module.exports = {
|
||||
...require('../../.prettierrc.json'),
|
||||
overrides: [
|
||||
{
|
||||
files: 'turbo/generators/templates/{.cliff-jumperrc.json.hbs,api-extractor.json.hbs,package.json.hbs}',
|
||||
options: {
|
||||
parser: 'json',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: 'turbo/generators/templates/{.lintstagedrc.js.hbs,.prettierrc.js.hbs}',
|
||||
options: {
|
||||
parser: 'babel',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
|
||||
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
|
||||
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src turbo",
|
||||
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src turbo",
|
||||
"fmt": "yarn format"
|
||||
},
|
||||
"exports": {
|
||||
@@ -56,23 +56,21 @@
|
||||
"@microsoft/api-extractor-model": "7.27.6",
|
||||
"@microsoft/tsdoc": "0.14.2",
|
||||
"@microsoft/tsdoc-config": "0.16.2",
|
||||
"commander": "^11.0.0",
|
||||
"fs-extra": "^11.1.1",
|
||||
"tslib": "^2.6.2",
|
||||
"undici": "5.23.0",
|
||||
"yaml": "2.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "^11.0.1",
|
||||
"@types/node": "16.18.41",
|
||||
"@turbo/gen": "^1.10.13",
|
||||
"@types/node": "16.18.44",
|
||||
"@vitest/coverage-v8": "^0.34.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.47.0",
|
||||
"eslint-config-neon": "^0.1.54",
|
||||
"eslint-config-neon": "^0.1.56",
|
||||
"eslint-formatter-pretty": "^5.0.0",
|
||||
"prettier": "^3.0.2",
|
||||
"tsup": "^7.2.0",
|
||||
"turbo": "^1.10.12",
|
||||
"turbo": "^1.10.13",
|
||||
"typescript": "^5.1.6",
|
||||
"vitest": "^0.34.2"
|
||||
},
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
import { mkdir, writeFile, readFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { chdir } from 'node:process';
|
||||
import { copy } from 'fs-extra';
|
||||
import { parse as parseYAML, stringify as stringifyYAML } from 'yaml';
|
||||
import cliffJumperJSON from './template/.cliff-jumperrc.json';
|
||||
import apiExtractorJSON from './template/api-extractor.json';
|
||||
import templateJSON from './template/template.package.json';
|
||||
|
||||
interface LabelerData {
|
||||
color: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
function sortYAMLObject(yaml: Record<string, string[]>) {
|
||||
const sortedYAML: typeof yaml = {};
|
||||
for (const key of Object.keys(yaml).sort((a, b) => a.localeCompare(b))) sortedYAML[key] = yaml[key]!;
|
||||
return sortedYAML;
|
||||
}
|
||||
|
||||
export async function createPackage(packageName: string, packageDescription?: string) {
|
||||
const packageDir = join('packages', packageName);
|
||||
|
||||
// Make directory for package
|
||||
await mkdir(packageDir);
|
||||
|
||||
// Change to subdirectory
|
||||
chdir(packageDir);
|
||||
|
||||
// Create folder structure
|
||||
await Promise.all([mkdir('src'), mkdir('__tests__')]);
|
||||
|
||||
const templateDir = join('..', 'scripts', 'src', 'template');
|
||||
|
||||
// Create files
|
||||
await writeFile(join('src', 'index.ts'), `console.log('Hello, from @discordjs/${packageName}');`);
|
||||
await writeFile('.eslintrc.json', await readFile(join(templateDir, 'template.eslintrc.json'), 'utf8'));
|
||||
await writeFile('.gitignore', await readFile(join(templateDir, 'template.gitignore'), 'utf8'));
|
||||
await writeFile('.lintstagedrc.js', await readFile(join(templateDir, 'template.lintstagedrc.js'), 'utf8'));
|
||||
await writeFile('.prettierignore', await readFile(join(templateDir, 'template.prettierignore'), 'utf8'));
|
||||
await writeFile('.prettierrc.js', await readFile(join(templateDir, 'template.prettierrc.js'), 'utf8'));
|
||||
|
||||
const packageJSON = {
|
||||
...templateJSON,
|
||||
name: templateJSON.name.replace('{name}', packageName),
|
||||
description: packageDescription ?? '',
|
||||
};
|
||||
|
||||
// Edit changelog script
|
||||
packageJSON.scripts.changelog = packageJSON.scripts.changelog.replace('{name}', packageName);
|
||||
|
||||
// Edit repository directory
|
||||
packageJSON.repository.directory = packageJSON.repository.directory.replace('{name}', packageName);
|
||||
|
||||
// Create package.json
|
||||
await writeFile(`package.json`, JSON.stringify(packageJSON, null, 2));
|
||||
|
||||
// Update cliff.toml
|
||||
const cliffTOML = (await readFile(join(templateDir, 'cliff.toml'), 'utf8')).replace('{name}', packageName);
|
||||
|
||||
await writeFile('cliff.toml', cliffTOML);
|
||||
|
||||
// Update .cliff-jumperrc.json
|
||||
const newCliffJumperJSON = { ...cliffJumperJSON, name: packageName, packagePath: `packages/${packageName}` };
|
||||
|
||||
await writeFile('.cliff-jumperrc.json', JSON.stringify(newCliffJumperJSON, null, 2));
|
||||
|
||||
// Update api-extractor.json
|
||||
const newApiExtractorJSON = { ...apiExtractorJSON };
|
||||
newApiExtractorJSON.docModel.projectFolderUrl = newApiExtractorJSON.docModel.projectFolderUrl.replace(
|
||||
'{name}',
|
||||
packageName,
|
||||
);
|
||||
|
||||
await writeFile('api-extractor.json', JSON.stringify(newApiExtractorJSON, null, 2));
|
||||
|
||||
// Move to github directory
|
||||
chdir(join('..', '..', '.github'));
|
||||
|
||||
const labelsYAML = parseYAML(await readFile('labels.yml', 'utf8')) as LabelerData[];
|
||||
labelsYAML.push({ name: `packages:${packageName}`, color: 'fbca04' });
|
||||
|
||||
labelsYAML.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
await writeFile('labels.yml', stringifyYAML(labelsYAML));
|
||||
|
||||
const labelerYAML = parseYAML(await readFile('labeler.yml', 'utf8')) as Record<string, string[]>;
|
||||
labelerYAML[`packages:${packageName}`] = [`packages/${packageName}/*`, `packages/${packageName}/**/*`];
|
||||
|
||||
await writeFile('labeler.yml', stringifyYAML(sortYAMLObject(labelerYAML)));
|
||||
|
||||
const issueLabelerYAML = parseYAML(await readFile('issue-labeler.yml', 'utf8')) as Record<string, string[]>;
|
||||
issueLabelerYAML[`packages:${packageName}`] = [
|
||||
`### Which (application|package|application or package) is this (bug report|feature request) for\\?\\n\\n${packageName}\\n`,
|
||||
];
|
||||
|
||||
await writeFile('issue-labeler.yml', stringifyYAML(sortYAMLObject(issueLabelerYAML)));
|
||||
|
||||
// Move back to root
|
||||
chdir('..');
|
||||
|
||||
// Copy default files over
|
||||
await copy(join('packages', 'scripts', 'src', 'template', 'default'), packageDir);
|
||||
}
|
||||
@@ -1,2 +1 @@
|
||||
export * from './generateIndex.js';
|
||||
export * from './createPackage.js';
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { program } from 'commander';
|
||||
import { createPackage } from '../dist/index.mjs';
|
||||
|
||||
program
|
||||
.description('A script for creating discord.js packages.')
|
||||
.argument('<name>', 'The name of the new package.')
|
||||
.argument('[description]', 'The description of the new package.');
|
||||
program.parse();
|
||||
|
||||
const [packageName, description] = program.args;
|
||||
|
||||
console.log(`Creating package @discordjs/${packageName}...`);
|
||||
await createPackage(packageName, description);
|
||||
console.log('Done!');
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name": "",
|
||||
"org": "discordjs",
|
||||
"packagePath": ""
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"extends": "../../api-extractor.json",
|
||||
"docModel": {
|
||||
"projectFolderUrl": "https://github.com/discordjs/discord.js/tree/main/packages/{name}"
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig.json",
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"**/*.js",
|
||||
"**/*.mjs",
|
||||
"**/*.jsx",
|
||||
"**/*.test.ts",
|
||||
"**/*.test.js",
|
||||
"**/*.test.mjs",
|
||||
"**/*.spec.ts",
|
||||
"**/*.spec.js",
|
||||
"**/*.spec.mjs"
|
||||
],
|
||||
"exclude": []
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "../../.eslintrc.json"
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
# Packages
|
||||
node_modules
|
||||
|
||||
# Log files
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Env
|
||||
.env
|
||||
|
||||
# Dist
|
||||
dist
|
||||
dist-docs
|
||||
|
||||
# Docs
|
||||
docs/**/*
|
||||
!docs/README.md
|
||||
|
||||
# Miscellaneous
|
||||
.turbo
|
||||
.tmp
|
||||
coverage
|
||||
@@ -1,6 +0,0 @@
|
||||
.turbo
|
||||
coverage
|
||||
dist
|
||||
dist-docs
|
||||
docs/docs.api.json
|
||||
CHANGELOG.md
|
||||
@@ -4,17 +4,5 @@
|
||||
"compilerOptions": {
|
||||
"allowJs": true
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"**/*.js",
|
||||
"**/*.mjs",
|
||||
"**/*.jsx",
|
||||
"**/*.test.ts",
|
||||
"**/*.test.js",
|
||||
"**/*.test.mjs",
|
||||
"**/*.spec.ts",
|
||||
"**/*.spec.js",
|
||||
"**/*.spec.mjs"
|
||||
]
|
||||
"include": ["*.ts", "*.tsx", "*.js", "*.cjs", "*.mjs", "src", "turbo"]
|
||||
}
|
||||
|
||||
93
packages/scripts/turbo/generators/config.ts
Normal file
93
packages/scripts/turbo/generators/config.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { writeFile } from 'node:fs/promises';
|
||||
import type { PlopTypes } from '@turbo/gen';
|
||||
import { parse as parseYAML, stringify as stringifyYAML } from 'yaml';
|
||||
|
||||
interface LabelerData {
|
||||
color: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
function sortYAMLObject(yaml: Record<string, string[]>) {
|
||||
const sortedYAML: typeof yaml = {};
|
||||
for (const key of Object.keys(yaml).sort((a, b) => a.localeCompare(b))) sortedYAML[key] = yaml[key]!;
|
||||
return sortedYAML;
|
||||
}
|
||||
|
||||
export default function generator(plop: PlopTypes.NodePlopAPI): void {
|
||||
plop.setGenerator('create-package', {
|
||||
description: '',
|
||||
prompts: [
|
||||
{
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
message: 'The name of the new package',
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'description',
|
||||
message: 'The description of the new package.',
|
||||
},
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
type: 'add',
|
||||
path: `${plop.getDestBasePath()}/../{{name}}/src/index.ts`,
|
||||
template: "console.log('Hello, from @discordjs/{{name}}');",
|
||||
},
|
||||
{
|
||||
type: 'add',
|
||||
path: `${plop.getDestBasePath()}/../{{name}}/__tests__/.gitkeep`,
|
||||
},
|
||||
{
|
||||
type: 'addMany',
|
||||
destination: `${plop.getDestBasePath()}/../{{name}}`,
|
||||
templateFiles: ['templates/**'],
|
||||
globOptions: { dot: true },
|
||||
base: 'templates/default/',
|
||||
stripExtensions: ['hbs'],
|
||||
},
|
||||
{
|
||||
type: 'modify',
|
||||
path: `${plop.getDestBasePath()}/turbo/generators/templates/cliff.toml`,
|
||||
async transform(content, answers) {
|
||||
const cliffTOML = content.replace('{{name}}', answers.name);
|
||||
await writeFile(`${plop.getDestBasePath()}/../${answers.name}/cliff.toml`, cliffTOML);
|
||||
return content;
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'modify',
|
||||
path: `${plop.getDestBasePath()}/../../.github/labels.yml`,
|
||||
transform(content, answers) {
|
||||
const labelsYAML = parseYAML(content) as LabelerData[];
|
||||
labelsYAML.push({ name: `packages:${answers.name}`, color: 'fbca04' });
|
||||
labelsYAML.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
return stringifyYAML(labelsYAML);
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'modify',
|
||||
path: `${plop.getDestBasePath()}/../../.github/labeler.yml`,
|
||||
transform(content, answers) {
|
||||
const labelerYAML = parseYAML(content) as Record<string, string[]>;
|
||||
labelerYAML[`packages:${answers.name}`] = [`packages/${answers.name}/*`, `packages/${answers.name}/**/*`];
|
||||
|
||||
return stringifyYAML(sortYAMLObject(labelerYAML));
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'modify',
|
||||
path: `${plop.getDestBasePath()}/../../.github/issue-labeler.yml`,
|
||||
transform(content, answers) {
|
||||
const issueLabelerYAML = parseYAML(content) as Record<string, string[]>;
|
||||
issueLabelerYAML[`packages:${answers.name}`] = [
|
||||
`### Which (application|package|application or package) is this (bug report|feature request) for\\?\\n\\n${answers.name}\\n`,
|
||||
];
|
||||
|
||||
return stringifyYAML(sortYAMLObject(issueLabelerYAML));
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "name": "{{name}}", "org": "discordjs", "packagePath": "packages/{{name}}" }
|
||||
@@ -0,0 +1,2 @@
|
||||
# Packages node_modules # Log files logs *.log npm-debug.log* # Runtime data pids *.pid *.seed # Env .env # Dist dist
|
||||
dist-docs # Docs docs/**/* !docs/README.md # Miscellaneous .turbo .tmp coverage
|
||||
@@ -0,0 +1 @@
|
||||
.turbo coverage dist dist-docs docs/docs.api.json CHANGELOG.md
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../api-extractor.json",
|
||||
"docModel": { "projectFolderUrl": "https://github.com/discordjs/discord.js/tree/main/packages/{{name}}" }
|
||||
}
|
||||
@@ -57,7 +57,7 @@ commit_parsers = [
|
||||
{ body = ".*security", group = "Security"},
|
||||
]
|
||||
filter_commits = true
|
||||
tag_pattern = "@discordjs/{name}@[0-9]*"
|
||||
tag_pattern = "@discordjs/{{name}}@[0-9]*"
|
||||
ignore_tags = ""
|
||||
topo_order = true
|
||||
sort_commits = "newest"
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig.json",
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true
|
||||
},
|
||||
"include": ["*.ts", "*.tsx", "*.js", "*.cjs", "*.mjs", "src", "__tests__"]
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
import { createTsupConfig } from '../../tsup.config.js';
|
||||
|
||||
export default createTsupConfig({});
|
||||
export default createTsupConfig();
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@discordjs/{name}",
|
||||
"name": "@discordjs/{{name}}",
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"description": "{{description}}",
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"build": "tsup",
|
||||
@@ -10,17 +10,24 @@
|
||||
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
|
||||
"docs": "yarn build:docs && api-extractor run --local && api-extractor run --local --config ./api-extractor-docs.json",
|
||||
"prepack": "yarn build && yarn lint",
|
||||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/{name}/*'",
|
||||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/{{name}}/*'",
|
||||
"release": "cliff-jumper"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"require": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/index.d.mts",
|
||||
"default": "./dist/index.mjs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.js"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "src",
|
||||
"test": "__tests__"
|
||||
@@ -37,7 +44,7 @@
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/discordjs/discord.js.git",
|
||||
"directory": "packages/{name}"
|
||||
"directory": "packages/{{name}}"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
@@ -47,11 +54,11 @@
|
||||
"devDependencies": {
|
||||
"@favware/cliff-jumper": "^2.1.1",
|
||||
"@microsoft/api-extractor": "^7.36.4",
|
||||
"@types/node": "16.18.41",
|
||||
"@types/node": "16.18.42",
|
||||
"@vitest/coverage-v8": "^0.34.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.47.0",
|
||||
"eslint-config-neon": "^0.1.47",
|
||||
"eslint-config-neon": "^0.1.54",
|
||||
"eslint-formatter-pretty": "^5.0.0",
|
||||
"prettier": "^3.0.2",
|
||||
"tsup": "^7.2.0",
|
||||
Reference in New Issue
Block a user