diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 1b1a3596f..fd96ed502 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -16,3 +16,14 @@ To get ready to work on the codebase, please do the following: 4. Code your heart out! 5. Run `yarn test` to run ESLint and ensure any JSDoc changes are valid 6. [Submit a pull request](https://github.com/discordjs/discord.js/compare) (Make sure you follow the [conventional commit format](https://github.com/discordjs/discord.js/blob/main/.github/COMMIT_CONVENTION.md)) + +## Adding new packages + +If you'd like to create another package under the `@discordjs` organization run the following command: + +```bash +yarn create-package [package-description] +``` + +This will create new package directory under `packages/` with the required configuration files. You can +begin to make changes within the `src/` directory. diff --git a/package.json b/package.json index 8fd0d129b..b5d3dd50b 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "fmt": "turbo run format --parallel", "postinstall": "is-ci || husky install", "docs": "turbo run docs --parallel", - "update": "yarn upgrade-interactive" + "update": "yarn upgrade-interactive", + "create-package": "node packages/scripts/src/packageScript.mjs" }, "contributors": [ "Crawl ", diff --git a/packages/scripts/.eslintrc.json b/packages/scripts/.eslintrc.json index 99ef7cec8..6e2ebbf37 100644 --- a/packages/scripts/.eslintrc.json +++ b/packages/scripts/.eslintrc.json @@ -1,3 +1,4 @@ { - "extends": "../../.eslintrc.json" + "extends": "../../.eslintrc.json", + "ignorePatterns": "src/template/**/*" } diff --git a/packages/scripts/.prettierignore b/packages/scripts/.prettierignore index 8b94c7d45..98eb791db 100644 --- a/packages/scripts/.prettierignore +++ b/packages/scripts/.prettierignore @@ -5,4 +5,5 @@ dist/ docs/**/* !docs/index.yml !docs/README.md -coverage/ \ No newline at end of file +coverage/ +src/template/ diff --git a/packages/scripts/package.json b/packages/scripts/package.json index c1afd0b05..4f1301ab9 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -44,14 +44,18 @@ "homepage": "https://discord.js.org", "dependencies": { "@discordjs/api-extractor-utils": "workspace:^", + "@iarna/toml": "^2.2.5", "@microsoft/api-extractor-model": "7.24.0", "@microsoft/tsdoc": "0.14.1", "@microsoft/tsdoc-config": "0.16.1", "commander": "^9.4.1", + "fs-extra": "^10.1.0", "tslib": "^2.4.0", - "undici": "^5.11.0" + "undici": "^5.11.0", + "yaml": "^2.1.3" }, "devDependencies": { + "@types/fs-extra": "^9.0.13", "@types/node": "^16.11.64", "@vitest/coverage-c8": "^0.23.4", "cross-env": "^7.0.3", diff --git a/packages/scripts/src/createPackage.ts b/packages/scripts/src/createPackage.ts new file mode 100644 index 000000000..e6bf98ecf --- /dev/null +++ b/packages/scripts/src/createPackage.ts @@ -0,0 +1,94 @@ +import { mkdir, writeFile, readFile } from 'node:fs/promises'; +import { join } from 'node:path'; +import { chdir } from 'node:process'; +import type { JsonMap } from '@iarna/toml'; +import { parse as parseTOML, stringify as stringifyTOML } from '@iarna/toml'; +import { copy } from 'fs-extra'; +import { parse as parseYAML, stringify as stringifyYAML } from 'yaml'; +import cliffJumperJSON from './template/.cliff-jumperrc.json'; +import templateJSON from './template/template.package.json'; + +interface CliffTOML { + changelog: { + body: string; + header: string; + trim: boolean; + }; + git: { + commit_parsers: { group?: string; message: string; skip?: boolean }[]; + conventional_commits: boolean; + date_order: boolean; + filter_commits: boolean; + filter_unconventional: boolean; + ignore_tags: string; + sort_commits: string; + tag_pattern: string; + }; +} + +interface LabelerData { + color: string; + name: string; +} + +export async function createPackage(packageName: string, packageDescription?: string) { + // Make directory for package + await mkdir(`packages/${packageName}`); + + // Change to subdirectory + chdir(`packages/${packageName}`); + + // Create folder structure + await Promise.all([mkdir('src'), mkdir('__tests__')]); + + // Create files + await writeFile('src/index.ts', `console.log('Hello, from @discord.js/${packageName}');`); + + await writeFile('.eslintrc.json', await readFile('../scripts/src/template/template.eslintrc.json', 'utf8')); + + await writeFile('.lintstagedrc.js', await readFile('../scripts/src/template/template.lintstagedrc.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); + + // Create package.json + await writeFile(`package.json`, JSON.stringify(packageJSON, null, 2)); + + // Update cliff.toml + const cliffTOML = parseTOML( + await readFile(join('..', 'scripts/src/template/cliff.toml'), 'utf8'), + ) as unknown as CliffTOML; + cliffTOML.git.tag_pattern = `@discordjs/${packageName}@[0-9]*`; + + await writeFile('cliff.toml', stringifyTOML(cliffTOML as unknown as JsonMap)); + + // Update .cliff-jumperrc.json + const newCliffJumperJSON = { ...cliffJumperJSON, name: packageName, packagePath: `packages/${packageName}` }; + + await writeFile('.cliff-jumperrc.json', JSON.stringify(newCliffJumperJSON, null, 2)); + + // Move to github directory + chdir('../../.github'); + + const labelsYAML = parseYAML(await readFile('labels.yml', 'utf8')) as LabelerData[]; + labelsYAML.push({ name: `packages:${packageName}`, color: 'fbca04' }); + + await writeFile('labels.yml', stringifyYAML(labelsYAML)); + + const labelerYAML = parseYAML(await readFile('labeler.yml', 'utf8')) as Record; + labelerYAML[`packages/${packageName}`] = [`packages:${packageName}/*`, `packages:${packageName}/**/*`]; + + await writeFile('labeler.yml', stringifyYAML(labelerYAML)); + + // Move back to root + chdir('..'); + + // Copy default files over + await copy('packages/scripts/src/template/default', `packages/${packageName}`); +} diff --git a/packages/scripts/src/index.ts b/packages/scripts/src/index.ts index 353651a35..62b9d039b 100644 --- a/packages/scripts/src/index.ts +++ b/packages/scripts/src/index.ts @@ -1 +1,2 @@ export * from './generateIndex.js'; +export * from './createPackage.js'; diff --git a/packages/scripts/src/packageScript.mjs b/packages/scripts/src/packageScript.mjs new file mode 100644 index 000000000..a5e70233f --- /dev/null +++ b/packages/scripts/src/packageScript.mjs @@ -0,0 +1,14 @@ +import { program } from 'commander'; +import { createPackage } from '../dist/index.mjs'; + +program + .description('A script for creating discord.js packages.') + .argument('', '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!'); diff --git a/packages/scripts/src/template/.cliff-jumperrc.json b/packages/scripts/src/template/.cliff-jumperrc.json new file mode 100644 index 000000000..a96e9ab7a --- /dev/null +++ b/packages/scripts/src/template/.cliff-jumperrc.json @@ -0,0 +1,5 @@ +{ + "name": "", + "org": "discordjs", + "packagePath": "" +} diff --git a/packages/scripts/src/template/cliff.toml b/packages/scripts/src/template/cliff.toml new file mode 100644 index 000000000..1e382a3b1 --- /dev/null +++ b/packages/scripts/src/template/cliff.toml @@ -0,0 +1,63 @@ +[changelog] +header = """ +# Changelog + +All notable changes to this project will be documented in this file.\n +""" +body = """ +{% if version %}\ + # [{{ version | trim_start_matches(pat="v") }}]\ + {% if previous %}\ + {% if previous.version %}\ + (https://github.com/discordjs/discord.js/compare/{{ previous.version }}...{{ version }})\ + {% else %}\ + (https://github.com/discordjs/discord.js/tree/{{ version }})\ + {% endif %}\ + {% endif %} \ + - ({{ timestamp | date(format="%Y-%m-%d") }}) +{% else %}\ + # [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ## {{ group | upper_first }} + {% for commit in commits %} + - {% if commit.scope %}\ + **{{commit.scope}}:** \ + {% endif %}\ + {{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}](https://github.com/discordjs/discord.js/commit/{{ commit.id }}))\ + {% if commit.breaking %}\ + {% for breakingChange in commit.footers %}\ + \n{% raw %} {% endraw %}- **{{ breakingChange.token }}{{ breakingChange.separator }}** {{ breakingChange.value }}\ + {% endfor %}\ + {% endif %}\ + {% endfor %} +{% endfor %}\n +""" +trim = true +footer = "" + +[git] +conventional_commits = true +filter_unconventional = true +commit_parsers = [ + { message = "^feat", group = "Features"}, + { message = "^fix", group = "Bug Fixes"}, + { message = "^docs", group = "Documentation"}, + { message = "^perf", group = "Performance"}, + { message = "^refactor", group = "Refactor"}, + { message = "^typings", group = "Typings"}, + { message = "^types", group = "Typings"}, + { message = ".*deprecated", body = ".*deprecated", group = "Deprecation"}, + { message = "^revert", skip = true}, + { message = "^style", group = "Styling"}, + { message = "^test", group = "Testing"}, + { message = "^chore", skip = true}, + { message = "^ci", skip = true}, + { message = "^build", skip = true}, + { body = ".*security", group = "Security"}, +] +filter_commits = true +tag_pattern = "@discordjs/{name}@[0-9]*" +ignore_tags = "" +date_order = true +sort_commits = "newest" diff --git a/packages/scripts/src/template/default/.gitignore b/packages/scripts/src/template/default/.gitignore new file mode 100644 index 000000000..86b93e929 --- /dev/null +++ b/packages/scripts/src/template/default/.gitignore @@ -0,0 +1,27 @@ +# Packages +node_modules/ + +# Log files +logs/ +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Env +.env + +# Dist +dist/ +typings/ +docs/**/* +!docs/index.json +!docs/README.md + +# Miscellaneous +.tmp/ +coverage/ +tsconfig.tsbuildinfo diff --git a/packages/scripts/src/template/default/.prettierignore b/packages/scripts/src/template/default/.prettierignore new file mode 100644 index 000000000..553e0ea6c --- /dev/null +++ b/packages/scripts/src/template/default/.prettierignore @@ -0,0 +1,8 @@ +# Autogenerated +CHANGELOG.md +.turbo +dist/ +docs/**/* +!docs/index.yml +!docs/README.md +coverage/ diff --git a/packages/scripts/src/template/default/.prettierrc.js b/packages/scripts/src/template/default/.prettierrc.js new file mode 100644 index 000000000..f004026c7 --- /dev/null +++ b/packages/scripts/src/template/default/.prettierrc.js @@ -0,0 +1 @@ +module.exports = require('../../.prettierrc.json'); diff --git a/packages/scripts/src/template/default/LICENSE b/packages/scripts/src/template/default/LICENSE new file mode 100644 index 000000000..e633a147b --- /dev/null +++ b/packages/scripts/src/template/default/LICENSE @@ -0,0 +1,188 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/scripts/src/template/default/api-extractor.json b/packages/scripts/src/template/default/api-extractor.json new file mode 100644 index 000000000..3845fd481 --- /dev/null +++ b/packages/scripts/src/template/default/api-extractor.json @@ -0,0 +1,376 @@ +/** + * Config file for API Extractor. For more info, please visit: https://api-extractor.com + */ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + + /** + * Optionally specifies another JSON config file that this file extends from. This provides a way for + * standard settings to be shared across multiple projects. + * + * If the path starts with "./" or "../", the path is resolved relative to the folder of the file that contains + * the "extends" field. Otherwise, the first path segment is interpreted as an NPM package name, and will be + * resolved using NodeJS require(). + * + * SUPPORTED TOKENS: none + * DEFAULT VALUE: "" + */ + // "extends": "./shared/api-extractor-base.json" + // "extends": "my-package/include/api-extractor-base.json" + + /** + * Determines the "" token that can be used with other config file settings. The project folder + * typically contains the tsconfig.json and package.json config files, but the path is user-defined. + * + * The path is resolved relative to the folder of the config file that contains the setting. + * + * The default value for "projectFolder" is the token "", which means the folder is determined by traversing + * parent folders, starting from the folder containing api-extractor.json, and stopping at the first folder + * that contains a tsconfig.json file. If a tsconfig.json file cannot be found in this way, then an error + * will be reported. + * + * SUPPORTED TOKENS: + * DEFAULT VALUE: "" + */ + // "projectFolder": "..", + + /** + * (REQUIRED) Specifies the .d.ts file to be used as the starting point for analysis. API Extractor + * analyzes the symbols exported by this module. + * + * The file extension must be ".d.ts" and not ".ts". + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * SUPPORTED TOKENS: , , + */ + "mainEntryPointFilePath": "/dist/index.d.ts", + + /** + * A list of NPM package names whose exports should be treated as part of this package. + * + * For example, suppose that Webpack is used to generate a distributed bundle for the project "library1", + * and another NPM package "library2" is embedded in this bundle. Some types from library2 may become part + * of the exported API for library1, but by default API Extractor would generate a .d.ts rollup that explicitly + * imports library2. To avoid this, we can specify: + * + * "bundledPackages": [ "library2" ], + * + * This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been + * local files for library1. + */ + "bundledPackages": [], + + /** + * Determines how the TypeScript compiler engine will be invoked by API Extractor. + */ + "compiler": { + /** + * Specifies the path to the tsconfig.json file to be used by API Extractor when analyzing the project. + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * Note: This setting will be ignored if "overrideTsconfig" is used. + * + * SUPPORTED TOKENS: , , + * DEFAULT VALUE: "/tsconfig.json" + */ + // "tsconfigFilePath": "/tsconfig.json", + /** + * Provides a compiler configuration that will be used instead of reading the tsconfig.json file from disk. + * The object must conform to the TypeScript tsconfig schema: + * + * http://json.schemastore.org/tsconfig + * + * If omitted, then the tsconfig.json file will be read from the "projectFolder". + * + * DEFAULT VALUE: no overrideTsconfig section + */ + // "overrideTsconfig": { + // . . . + // } + /** + * This option causes the compiler to be invoked with the --skipLibCheck option. This option is not recommended + * and may cause API Extractor to produce incomplete or incorrect declarations, but it may be required when + * dependencies contain declarations that are incompatible with the TypeScript engine that API Extractor uses + * for its analysis. Where possible, the underlying issue should be fixed rather than relying on skipLibCheck. + * + * DEFAULT VALUE: false + */ + // "skipLibCheck": true, + }, + + /** + * Configures how the API report file (*.api.md) will be generated. + */ + "apiReport": { + /** + * (REQUIRED) Whether to generate an API report. + */ + "enabled": false + + /** + * The filename for the API report files. It will be combined with "reportFolder" or "reportTempFolder" to produce + * a full file path. + * + * The file extension should be ".api.md", and the string should not contain a path separator such as "\" or "/". + * + * SUPPORTED TOKENS: , + * DEFAULT VALUE: ".api.md" + */ + // "reportFileName": ".api.md", + + /** + * Specifies the folder where the API report file is written. The file name portion is determined by + * the "reportFileName" setting. + * + * The API report file is normally tracked by Git. Changes to it can be used to trigger a branch policy, + * e.g. for an API review. + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * SUPPORTED TOKENS: , , + * DEFAULT VALUE: "/temp/" + */ + // "reportFolder": "/temp/", + + /** + * Specifies the folder where the temporary report file is written. The file name portion is determined by + * the "reportFileName" setting. + * + * After the temporary file is written to disk, it is compared with the file in the "reportFolder". + * If they are different, a production build will fail. + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * SUPPORTED TOKENS: , , + * DEFAULT VALUE: "/temp/" + */ + // "reportTempFolder": "/temp/" + }, + + /** + * Configures how the doc model file (*.api.json) will be generated. + */ + "docModel": { + /** + * (REQUIRED) Whether to generate a doc model file. + */ + "enabled": true, + + /** + * The output path for the doc model file. The file extension should be ".api.json". + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * SUPPORTED TOKENS: , , + * DEFAULT VALUE: "/temp/.api.json" + */ + "apiJsonFilePath": "/docs/docs.api.json" + }, + + /** + * Configures how the .d.ts rollup file will be generated. + */ + "dtsRollup": { + /** + * (REQUIRED) Whether to generate the .d.ts rollup file. + */ + "enabled": false + + /** + * Specifies the output path for a .d.ts rollup file to be generated without any trimming. + * This file will include all declarations that are exported by the main entry point. + * + * If the path is an empty string, then this file will not be written. + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * SUPPORTED TOKENS: , , + * DEFAULT VALUE: "/dist/.d.ts" + */ + // "untrimmedFilePath": "/dist/.d.ts", + + /** + * Specifies the output path for a .d.ts rollup file to be generated with trimming for an "alpha" release. + * This file will include only declarations that are marked as "@public", "@beta", or "@alpha". + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * SUPPORTED TOKENS: , , + * DEFAULT VALUE: "" + */ + // "alphaTrimmedFilePath": "/dist/-alpha.d.ts", + + /** + * Specifies the output path for a .d.ts rollup file to be generated with trimming for a "beta" release. + * This file will include only declarations that are marked as "@public" or "@beta". + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * SUPPORTED TOKENS: , , + * DEFAULT VALUE: "" + */ + // "betaTrimmedFilePath": "/dist/-beta.d.ts", + + /** + * Specifies the output path for a .d.ts rollup file to be generated with trimming for a "public" release. + * This file will include only declarations that are marked as "@public". + * + * If the path is an empty string, then this file will not be written. + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * SUPPORTED TOKENS: , , + * DEFAULT VALUE: "" + */ + // "publicTrimmedFilePath": "/dist/-public.d.ts", + + /** + * When a declaration is trimmed, by default it will be replaced by a code comment such as + * "Excluded from this release type: exampleMember". Set "omitTrimmingComments" to true to remove the + * declaration completely. + * + * DEFAULT VALUE: false + */ + // "omitTrimmingComments": true + }, + + /** + * Configures how the tsdoc-metadata.json file will be generated. + */ + "tsdocMetadata": { + /** + * Whether to generate the tsdoc-metadata.json file. + * + * DEFAULT VALUE: true + */ + // "enabled": true, + /** + * Specifies where the TSDoc metadata file should be written. + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * The default value is "", which causes the path to be automatically inferred from the "tsdocMetadata", + * "typings" or "main" fields of the project's package.json. If none of these fields are set, the lookup + * falls back to "tsdoc-metadata.json" in the package folder. + * + * SUPPORTED TOKENS: , , + * DEFAULT VALUE: "" + */ + // "tsdocMetadataFilePath": "/dist/tsdoc-metadata.json" + }, + + /** + * Specifies what type of newlines API Extractor should use when writing output files. By default, the output files + * will be written with Windows-style newlines. To use POSIX-style newlines, specify "lf" instead. + * To use the OS's default newline kind, specify "os". + * + * DEFAULT VALUE: "crlf" + */ + "newlineKind": "lf", + + /** + * Configures how API Extractor reports error and warning messages produced during analysis. + * + * There are three sources of messages: compiler messages, API Extractor messages, and TSDoc messages. + */ + "messages": { + /** + * Configures handling of diagnostic messages reported by the TypeScript compiler engine while analyzing + * the input .d.ts files. + * + * TypeScript message identifiers start with "TS" followed by an integer. For example: "TS2551" + * + * DEFAULT VALUE: A single "default" entry with logLevel=warning. + */ + "compilerMessageReporting": { + /** + * Configures the default routing for messages that don't match an explicit rule in this table. + */ + "default": { + /** + * Specifies whether the message should be written to the the tool's output log. Note that + * the "addToApiReportFile" property may supersede this option. + * + * Possible values: "error", "warning", "none" + * + * Errors cause the build to fail and return a nonzero exit code. Warnings cause a production build fail + * and return a nonzero exit code. For a non-production build (e.g. when "api-extractor run" includes + * the "--local" option), the warning is displayed but the build will not fail. + * + * DEFAULT VALUE: "warning" + */ + "logLevel": "warning" + + /** + * When addToApiReportFile is true: If API Extractor is configured to write an API report file (.api.md), + * then the message will be written inside that file; otherwise, the message is instead logged according to + * the "logLevel" option. + * + * DEFAULT VALUE: false + */ + // "addToApiReportFile": false + } + + // "TS2551": { + // "logLevel": "warning", + // "addToApiReportFile": true + // }, + // + // . . . + }, + + /** + * Configures handling of messages reported by API Extractor during its analysis. + * + * API Extractor message identifiers start with "ae-". For example: "ae-extra-release-tag" + * + * DEFAULT VALUE: See api-extractor-defaults.json for the complete table of extractorMessageReporting mappings + */ + "extractorMessageReporting": { + "default": { + "logLevel": "warning" + // "addToApiReportFile": false + } + + // "ae-extra-release-tag": { + // "logLevel": "warning", + // "addToApiReportFile": true + // }, + // + // . . . + }, + + /** + * Configures handling of messages reported by the TSDoc parser when analyzing code comments. + * + * TSDoc message identifiers start with "tsdoc-". For example: "tsdoc-link-tag-unescaped-text" + * + * DEFAULT VALUE: A single "default" entry with logLevel=warning. + */ + "tsdocMessageReporting": { + "default": { + "logLevel": "warning" + // "addToApiReportFile": false + } + + // "tsdoc-link-tag-unescaped-text": { + // "logLevel": "warning", + // "addToApiReportFile": true + // }, + // + // . . . + } + } +} diff --git a/packages/scripts/src/template/default/tsconfig.eslint.json b/packages/scripts/src/template/default/tsconfig.eslint.json new file mode 100644 index 000000000..d04d4be3a --- /dev/null +++ b/packages/scripts/src/template/default/tsconfig.eslint.json @@ -0,0 +1,20 @@ +{ + "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": [] +} diff --git a/packages/scripts/src/template/default/tsconfig.json b/packages/scripts/src/template/default/tsconfig.json new file mode 100644 index 000000000..fd8b5e417 --- /dev/null +++ b/packages/scripts/src/template/default/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*.ts"] +} diff --git a/packages/scripts/src/template/default/tsup.config.js b/packages/scripts/src/template/default/tsup.config.js new file mode 100644 index 000000000..3d4480d6d --- /dev/null +++ b/packages/scripts/src/template/default/tsup.config.js @@ -0,0 +1,3 @@ +import { createTsupConfig } from '../../tsup.config.js'; + +export default createTsupConfig({}); diff --git a/packages/scripts/src/template/template.eslintrc.json b/packages/scripts/src/template/template.eslintrc.json new file mode 100644 index 000000000..99ef7cec8 --- /dev/null +++ b/packages/scripts/src/template/template.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "../../.eslintrc.json" +} diff --git a/packages/scripts/src/template/template.lintstagedrc.js b/packages/scripts/src/template/template.lintstagedrc.js new file mode 100644 index 000000000..dc17706a5 --- /dev/null +++ b/packages/scripts/src/template/template.lintstagedrc.js @@ -0,0 +1 @@ +module.exports = require('../../.lintstagedrc.json'); diff --git a/packages/scripts/src/template/template.package.json b/packages/scripts/src/template/template.package.json new file mode 100644 index 000000000..db01827f4 --- /dev/null +++ b/packages/scripts/src/template/template.package.json @@ -0,0 +1,65 @@ +{ + "name": "@discordjs/{name}", + "version": "0.1.0", + "description": "", + "scripts": { + "test": "vitest run", + "build": "tsup", + "lint": "prettier --check . && cross-env TIMING=1 eslint src __tests__ --ext mjs,js,ts", + "format": "prettier --write . && cross-env TIMING=1 eslint src __tests__ --ext mjs,js,ts --fix", + "docs": "downlevel-dts dist docs/dist --to=3.7 && api-extractor run --local", + "prepack": "yarn build && yarn lint", + "changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/{name}/*'", + "release": "cliff-jumper" + }, + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "typings": "./dist/index.d.ts", + "exports": { + "import": "./dist/index.mjs", + "require": "./dist/index.js", + "types": "./dist/index.d.ts" + }, + "directories": { + "lib": "src", + "test": "__tests__" + }, + "files": ["dist"], + "contributors": [ + "Crawl ", + "SpaceEEC ", + "Vlad Frangu ", + "Aura Román " + ], + "license": "Apache-2.0", + "keywords": [], + "repository": { + "type": "git", + "url": "git+https://github.com/discordjs/discord.js.git" + }, + "bugs": { + "url": "https://github.com/discordjs/discord.js/issues" + }, + "homepage": "https://discord.js.org", + "dependencies": {}, + "devDependencies": { + "cross-env": "^7.0.3", + "@favware/cliff-jumper": "^1.8.7", + "@microsoft/api-extractor": "^7.31.2", + "@types/node": "^16.11.60", + "@vitest/coverage-c8": "^0.23.4", + "downlevel-dts": "^0.10.1", + "eslint": "^8.24.0", + "eslint-config-neon": "^0.1.33", + "prettier": "^2.7.1", + "tsup": "^6.2.3", + "typescript": "^4.8.3", + "vitest": "^0.23.4" + }, + "engines": { + "node": ">=16.9.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/yarn.lock b/yarn.lock index b396b3430..2568ace33 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2271,21 +2271,25 @@ __metadata: resolution: "@discordjs/scripts@workspace:packages/scripts" dependencies: "@discordjs/api-extractor-utils": "workspace:^" + "@iarna/toml": ^2.2.5 "@microsoft/api-extractor-model": 7.24.0 "@microsoft/tsdoc": 0.14.1 "@microsoft/tsdoc-config": 0.16.1 + "@types/fs-extra": ^9.0.13 "@types/node": ^16.11.64 "@vitest/coverage-c8": ^0.23.4 commander: ^9.4.1 cross-env: ^7.0.3 eslint: ^8.24.0 eslint-config-neon: ^0.1.34 + fs-extra: ^10.1.0 prettier: ^2.7.1 tslib: ^2.4.0 tsup: ^6.2.3 typescript: ^4.8.4 undici: ^5.11.0 vitest: ^0.23.4 + yaml: ^2.1.3 languageName: unknown linkType: soft @@ -2630,6 +2634,13 @@ __metadata: languageName: node linkType: hard +"@iarna/toml@npm:^2.2.5": + version: 2.2.5 + resolution: "@iarna/toml@npm:2.2.5" + checksum: b63b2b2c4fd67969a6291543ada0303d45593801ee744b60f5390f183c03d9192bc67a217abb24be945158f1935f02840d9ffff40c0142aa171b5d3b6b6a3ea5 + languageName: node + linkType: hard + "@iconify/types@npm:^2.0.0": version: 2.0.0 resolution: "@iconify/types@npm:2.0.0" @@ -4008,6 +4019,15 @@ __metadata: languageName: node linkType: hard +"@types/fs-extra@npm:^9.0.13": + version: 9.0.13 + resolution: "@types/fs-extra@npm:9.0.13" + dependencies: + "@types/node": "*" + checksum: add79e212acd5ac76b97b9045834e03a7996aef60a814185e0459088fd290519a3c1620865d588fa36c4498bf614210d2a703af5cf80aa1dbc125db78f6edac3 + languageName: node + linkType: hard + "@types/graceful-fs@npm:^4.1.3": version: 4.1.5 resolution: "@types/graceful-fs@npm:4.1.5" @@ -9888,7 +9908,7 @@ __metadata: languageName: node linkType: hard -"fs-extra@npm:^10.0.0": +"fs-extra@npm:^10.0.0, fs-extra@npm:^10.1.0": version: 10.1.0 resolution: "fs-extra@npm:10.1.0" dependencies: @@ -20105,6 +20125,13 @@ __metadata: languageName: node linkType: hard +"yaml@npm:^2.1.3": + version: 2.1.3 + resolution: "yaml@npm:2.1.3" + checksum: 91316062324a93f9cb547469092392e7d004ff8f70c40fecb420f042a4870b2181557350da56c92f07bd44b8f7a252b0be26e6ade1f548e1f4351bdd01c9d3c7 + languageName: node + linkType: hard + "yargs-parser@npm:^18.1.2": version: 18.1.3 resolution: "yargs-parser@npm:18.1.3"