diff --git a/.gitignore b/.gitignore index 86c8bb7..dbab1f4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ /npm-debug.log /test.js package-lock.json + +*.d.ts +*.d.ts.map diff --git a/declaration.tsconfig.json b/declaration.tsconfig.json new file mode 100644 index 0000000..1cde465 --- /dev/null +++ b/declaration.tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "noEmit": false, + "emitDeclarationOnly": true + }, + "exclude": [ + "**/*.test.js", + ] +} diff --git a/lib/copy.js b/lib/copy.js index 1f6d1b2..aab5cb2 100644 --- a/lib/copy.js +++ b/lib/copy.js @@ -19,6 +19,14 @@ const removeFile = require('./utils/remove-file') // Exports // ------------------------------------------------------------------------------ +/** + * @typedef {{ + cleaned: string[], + copied: string[], + options: object + }} CopyReport + */ + /** * Copy files asynchronously. * @param {string} source The glob pattern of target files. @@ -32,9 +40,9 @@ const removeFile = require('./utils/remove-file') * @param {boolean} [options.preserve=false] The flag to copy file attributes such as timestamps, users, and groups. * @param {(function(string):void)[]} [options.transform] The array of the factories of transform streams. * @param {boolean} [options.update=false] The flag to not overwrite newer files. - * @param {string|Array.} [options.ignore] - gitignore string or array of gitignore strings - * @param {function(Error):void} [callback] The callback function which will go fulfilled after done. - * @returns {Promise} The promise which will go fulfilled after done. + * @param {string[]|string|null|undefined} [options.ignore] - gitignore string or array of gitignore strings + * @param {function(Error, CopyReport):void} [callback] The callback function which will go fulfilled after done. + * @returns {Promise} The promise which will go fulfilled after done. */ module.exports = async function copy (source, outputDir, options, callback) { /* eslint-disable no-param-reassign */ @@ -81,6 +89,7 @@ module.exports = async function copy (source, outputDir, options, callback) { return Promise.resolve() }) + /** @type {CopyReport} */ const report = { cleaned, copied: copied.filter(r => r), // clean holes, diff --git a/package.json b/package.json index 7b84dde..0807a53 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "node": ">=16" }, "main": "lib/index.js", + "types": "./lib/index.d.ts", "bin": { "cpx": "bin/index.js" }, @@ -14,14 +15,18 @@ "lib" ], "scripts": { - "prepublishOnly": "git push --follow-tags && gh-release -y", + "prepublishOnly": "npm run build && git push --follow-tags && gh-release -y", + "postpublish": "npm run clean", "version": "auto-changelog -p --template keepachangelog auto-changelog --breaking-pattern 'BREAKING CHANGE:' && git add CHANGELOG.md", "_mocha": "_mocha \"test/*.js\" --timeout 35000", - "clean": "rm -rf .nyc_output coverage test-ws", + "clean": "run-p clean:*", "coverage": "nyc report -r lcov && opener coverage/lcov-report/index.html", "lint": "standard", "test": "nyc --require @babel/register npm run -s _mocha", - "watch": "npm run -s _mocha -- --require @babel/register --watch --growl" + "watch": "npm run -s _mocha -- --require @babel/register --watch --growl", + "build": "npm run clean && run-p build:*", + "build:declaration": "tsc -p declaration.tsconfig.json", + "clean:declarations-lib": "rm -rf $(find {lib,bin} -type f -name '*.d.ts*' ! -name '*-types.d.ts')" }, "dependencies": { "debounce": "^1.2.0", @@ -41,17 +46,21 @@ "devDependencies": { "@babel/core": "^7.5.5", "@babel/register": "^7.5.5", + "@types/node": "^20.8.9", + "@voxpelli/tsconfig": "^9.0.0", "auto-changelog": "^2.2.0", "babel-preset-power-assert": "^3.0.0", "gh-release": "^7.0.2", "mocha": "^10.2.0", + "npm-run-all2": "^6.1.1", "nyc": "15.1.0", "opener": "^1.5.1", "p-event": "^6.0.0", "power-assert": "^1.6.1", "shelljs": "^0.8.3", "standard": "^17.1.0", - "through": "^2.3.8" + "through": "^2.3.8", + "typescript": "~5.2.2" }, "repository": { "type": "git", diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..bf6b7eb --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "@voxpelli/tsconfig/node18.json", + "compilerOptions": { + "skipLibCheck": true + }, + "include": [ + "lib/**/*", + "bin/**/*" + ], + "exclude": [ + "node_modules" + ] +}