diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index ba13770..a0df919 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -49,8 +49,9 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 20.x - - run: npm i + - run: npm ci - run: npm run build + - run: npm run test # Deploys the final package to NPM deploy: @@ -86,7 +87,7 @@ jobs: echo "::set-output name=BODY::$BODY" - name: Install Dependencies - run: npm install -f + run: npm ci - name: Create a clean build run: npm run build diff --git a/README.md b/README.md index 64c341d..927be26 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,158 @@ And use in `package.json` `scripts`: } ``` +## Tools + +### deleteFoldersRecursive + +Delete all files and folders in the given directory. +The path could be relative or absolute. +This function operates synchronously. +The target folder itself will not be deleted. + +Usage: `deleteFoldersRecursive(__dirname + '/src');` + +### copyFolderRecursiveSync + +The `copyFolderRecursiveSync` function is used to copy all files and subdirectories from a source directory to a destination directory. +This function operates synchronously, meaning it will block the execution of the program until the copying process is complete. +It is useful for tasks that require a complete and immediate copy of a directory structure, such as backup operations or preparing files for deployment. + +The target directory will be created if not exists. +The path could be relative or absolute. + +Usage: `copyFolderRecursiveSync(__dirname + '/src/build', __dirname + '/dist');` + +### readDirRecursive + +The readDirRecursive function is used to read all files and subdirectories within a given directory recursively. +This function is useful for tasks that require processing or listing all files within a directory tree, +such as file indexing, searching, or batch processing operations. + +The function operates synchronously. + +Usage: + +```js +const files = readDirRecursive(__dirname + '/src'); +console.log(files); +``` + +Parameters: + +- `dir`: The directory path to read. The path can be relative or absolute. + Returns: +- An array of file paths representing all files found within the specified directory and its subdirectories. + +### copyFiles + +The copyFiles function is used to copy specific files from a source directory to a destination directory. This function is useful for tasks that require selective copying of files based on certain patterns or criteria, such as preparing files for deployment or creating backups of specific files. + +Usage: + +```js +const files = copyFiles(['src/build/**/*.js', '!src/build/**/*node_modules*.js'], __dirname + '/dist'); +console.log(files); +``` + +Parameters: + +- `src`: Array of the patterns. Negative pattern starts with '!'. You can use the [glob](https://code.visualstudio.com/docs/editor/glob-patterns) patterns. +- `dest`: The destination directory path where files will be copied to. The path can be relative or absolute. + +### npmInstall +The `npmInstall` function is used to install npm packages for a given project. This function is useful for automating the setup process of a project by programmatically running `npm install` to ensure all dependencies are installed. + +The function returns promise and it is not synchron. + +Usage: +```js +npmInstall(__dirname + '/src') + .catch(e => console.error('Cannot install packages: ' + e.toString())); +``` + +### buildReact +The buildReact function is used to build a React application. +This function is useful for automating the build process of a React project, +ensuring that all necessary steps are taken to compile and bundle the application for production. + +Usage for craco: +```js +buildReact(__dirname + '/src', { craco: true, rootDir: __dirname, ramSize: 7000 }) + .catch(e => console.error('Cannot install packages: ' + e.toString())); +``` + +Usage for vite: +```js +buildReact(__dirname + '/src', { vite: true, rootDir: __dirname }) + .catch(e => console.error('Cannot install packages: ' + e.toString())); +``` + +Usage for application with React scripts: +```js +buildReact(__dirname + '/src', { rootDir: __dirname }) + .catch(e => console.error('Cannot install packages: ' + e.toString())); +``` + +Possible options: +- `rootDir` - sometimes the craco, vite, react-scripts are installed in the main directory and not in the src directory. This parameter says to function to look in the root directory for the executable script too. +- `ramSize` - adds the parameter `--max-old-space-size=X` (in MB) to the node parameter to increase the memory for build. `vis-2` or `admin` require it. +- `tsc` - Executes `tsc` command in the target directory before build. +- `craco` - Used `craco` for build +- `vite` - Used `vite` for build + +### ignoreWidgetFiles +Create a list of glob patterns for files that must be ignored by coping of the widget files. Used together with `copyWidgetFiles`. + +### copyWidgetsFiles +Create a list of glob patterns for files, that must be copied for widgets. + +Usage: +```js +copyFiles([ + __dirname + '/src/build/**/*.*', + copyWidgetsFiles(__dirname + '/src/build'), + ignoreWidgetFiles(__dirname + '/src/build') +], __dirname + '/widgets/vis-2-widgets-adapter-name'); +``` + +### patchHtmlFile +Replace in the given HTML file the debug script with production one: +```html + +``` + +will be replaced with +```html + +``` + +Usage: +`patchHtmlFile('admin/index_m.html')` + ## Converting i18n structure You can convert the old i18n structure i18n/lang/translations.json to the new structure i18n/lang.json with the following command: @@ -44,6 +196,7 @@ node node_modules/@iobroker/build-tools/convertI18n.js path/to/i18n --> ## Changelog + ### 1.1.1 (2024-10-03) - (@GermanBluefox) Trying to fix a build script for craco diff --git a/index.ts b/index.ts index b46af2f..df7d32a 100644 --- a/index.ts +++ b/index.ts @@ -9,6 +9,7 @@ import fs, { unlinkSync, mkdirSync, } from 'node:fs'; +import { globSync } from 'glob'; import { type ChildProcess, exec, fork, type IOType, type CommonSpawnOptions, execFile } from 'node:child_process'; import { dirname, join } from 'node:path'; @@ -24,7 +25,7 @@ export function deleteFoldersRecursive( if (existsSync(path)) { const files = readdirSync(path); for (const file of files) { - const curPath = `${path}/${file}`; + const curPath = join(path, file); if (exceptions?.find(e => curPath.endsWith(e))) { continue; } @@ -60,7 +61,7 @@ export function copyFolderRecursiveSync( exclude?: string[], ): void { const stats = existsSync(src) ? statSync(src) : null; - if (stats && stats.isDirectory()) { + if (stats?.isDirectory()) { !fs.existsSync(dest) && fs.mkdirSync(dest); fs.readdirSync(src).forEach(childItemName => { copyFolderRecursiveSync(join(src, childItemName), join(dest, childItemName)); @@ -76,7 +77,7 @@ export function readDirRecursive(path: string, _list?: string[]): string[] { if (existsSync(path)) { const files = readdirSync(path); files.forEach((file: string) => { - const fullPath = `${path}/${file}`; + const fullPath = join(path, file).replace(/\\/g, '/'); if (statSync(fullPath).isDirectory()) { readDirRecursive(fullPath, _list); } else { @@ -99,6 +100,7 @@ export function collectFiles(patterns: string[] | string): { name: string; base: add = false; } _patterns[i] = _patterns[i].replace(/\\/g, '/'); + let folder = _patterns[i].split('*')[0]; if (folder[folder.length - 1] === '/') { folder = folder.substring(0, folder.length - 1); @@ -107,34 +109,21 @@ export function collectFiles(patterns: string[] | string): { name: string; base: folderParts.pop(); folder = folderParts.join('/'); } - let files; - if (!folder) { - files = readdirSync('.'); - } else { - files = readDirRecursive(folder); - } - // convert pattern "src-admin/build/static/js/*.js" to regex "src-admin/build/static/js/[^\.]+\.js" - if (_patterns[i].endsWith('*')) { - _patterns[i] = _patterns[i].replace(/\./g, '\\.').replace(/\*/g, '[^/]+'); - } else { - _patterns[i] = `${_patterns[i].replace(/\./g, '\\.').replace(/\*/g, '[^/]+')}$`; - } - _patterns[i] = `^${_patterns[i]}`; - const regex = new RegExp(_patterns[i]); + const files: string[] = globSync(_patterns[i]); + for (let f = 0; f < files.length; f++) { - if (regex.test(files[f])) { - if (add) { - result.push({ name: files[f], base: folder }); - } else { - const pos = result.findIndex(it => it.name === files[f]); - if (pos !== -1) { - result.splice(pos, 1); - } + if (add) { + result.push({ name: files[f], base: folder }); + } else { + const pos = result.findIndex(it => it.name === files[f]); + if (pos !== -1) { + result.splice(pos, 1); } } } } + return result.map(it => ({ name: it.base ? it.name.substring(it.base.length + 1) : it.name, base: it.base })); } diff --git a/package-lock.json b/package-lock.json index 5469f12..b403121 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,18 @@ { "name": "@iobroker/build-tools", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@iobroker/build-tools", - "version": "1.1.0", + "version": "1.1.1", "devDependencies": { "@alcalzone/release-script": "^3.8.0", "@alcalzone/release-script-plugin-license": "^3.7.0", "@iobroker/eslint-config": "^0.1.6", "@types/node": "^22.7.4", + "glob": "^11.0.0", "typescript": "^5.6.2" }, "engines": { @@ -553,6 +554,109 @@ "typescript-eslint": "^8.5.0" } }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, + "license": "ISC", + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-regex": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@isaacs/cliui/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@isaacs/cliui/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -1115,8 +1219,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true, - "peer": true + "dev": true }, "node_modules/brace-expansion": { "version": "2.0.1", @@ -1124,7 +1227,6 @@ "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "balanced-match": "^1.0.0" } @@ -1520,6 +1622,13 @@ "node": ">=0.4.0" } }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true, + "license": "MIT" + }, "node_modules/electron-to-chromium": { "version": "1.5.28", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.28.tgz", @@ -2385,6 +2494,36 @@ "is-callable": "^1.1.3" } }, + "node_modules/foreground-child": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", + "integrity": "sha512-Ld2g8rrAyMYFXBhEqMz8ZAHBi4J4uS1i/CxGMDnjyFWddMXLVcDp051DZfu+t7+ab7Wv6SMqpWmyFIj5UbfFvg==", + "dev": true, + "license": "ISC", + "dependencies": { + "cross-spawn": "^7.0.0", + "signal-exit": "^4.0.1" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/foreground-child/node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/form-data": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", @@ -2511,6 +2650,30 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/glob": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-11.0.0.tgz", + "integrity": "sha512-9UiX/Bl6J2yaBbxKoEBRm4Cipxgok8kQYcOPEhScPwebu2I0HoQOuYdIO6S3hLuWoZgpDpwQZMzTFxgpkyT76g==", + "dev": true, + "license": "ISC", + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^4.0.1", + "minimatch": "^10.0.0", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^2.0.0" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", @@ -2524,6 +2687,22 @@ "node": ">=10.13.0" } }, + "node_modules/glob/node_modules/minimatch": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.1.tgz", + "integrity": "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/globals": { "version": "15.9.0", "resolved": "https://registry.npmjs.org/globals/-/globals-15.9.0.tgz", @@ -3216,6 +3395,22 @@ "set-function-name": "^2.0.1" } }, + "node_modules/jackspeak": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.2.tgz", + "integrity": "sha512-bZsjR/iRjl1Nk1UkjGpAzLNfQtzuijhn2g+pbZb98HQ1Gk8vM9hfbxeMBP+M2/UUdwj0RqGG3mlvk2MsAqwvEw==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -3391,6 +3586,16 @@ "loose-envify": "cli.js" } }, + "node_modules/lru-cache": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.0.1.tgz", + "integrity": "sha512-CgeuL5uom6j/ZVrg7G/+1IXqRY8JXX4Hghfy5YE0EhoYQWvndP1kufu58cmZLNIDKnRhZrXfdS9urVWx98AipQ==", + "dev": true, + "license": "ISC", + "engines": { + "node": "20 || >=22" + } + }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -3479,6 +3684,16 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/minipass": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", + "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=16 || 14 >=14.17" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -3719,6 +3934,13 @@ "node": ">=6" } }, + "node_modules/package-json-from-dist": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", + "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==", + "dev": true, + "license": "BlueOak-1.0.0" + }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -3793,6 +4015,23 @@ "dev": true, "peer": true }, + "node_modules/path-scurry": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-2.0.0.tgz", + "integrity": "sha512-ypGJsmGtdXUOeM5u93TyeIEfEhM6s+ljAhrk5vAvSx8uyY/02OvrZnA0YNGUrPXfpJMgI1ODd3nwz8Npx4O4cg==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "lru-cache": "^11.0.0", + "minipass": "^7.1.2" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -4410,6 +4649,22 @@ "node": ">=8" } }, + "node_modules/string-width-cjs": { + "name": "string-width", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/string.prototype.matchall": { "version": "4.0.11", "resolved": "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.11.tgz", @@ -4514,6 +4769,20 @@ "node": ">=8" } }, + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-final-newline": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", @@ -5017,6 +5286,25 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index 4577627..8fe58c3 100644 --- a/package.json +++ b/package.json @@ -1,41 +1,43 @@ { - "name": "@iobroker/build-tools", - "version": "1.1.1", - "description": "Replacement for gulp", - "author": { - "name": "Denis Haev", - "email": "dogafox@gmail.com" - }, - "publishConfig": { - "access": "public" - }, - "engines": { - "node": ">=16" - }, - "repository": { - "type": "git", - "url": "https://github.com/ioBroker/build-tools" - }, - "devDependencies": { - "@alcalzone/release-script": "^3.8.0", - "@alcalzone/release-script-plugin-license": "^3.7.0", - "@iobroker/eslint-config": "^0.1.6", - "@types/node": "^22.7.4", - "typescript": "^5.6.2" - }, - "main": "build/index.js", - "files": [ - "build/", - "LICENSE" - ], - "scripts": { - "build": "tsc -p tsconfig.build.json", - "release": "release-script", - "release-patch": "release-script patch --yes --no-update-lockfile", - "release-minor": "release-script minor --yes --no-update-lockfile", - "release-major": "release-script major --yes --no-update-lockfile", - "update-packages": "ncu --upgrade && cd src-admin && ncu --upgrade", - "lint": "eslint -c eslint.config.mjs", - "npm": "npm i -f" - } + "name": "@iobroker/build-tools", + "version": "1.1.1", + "description": "Replacement for gulp", + "author": { + "name": "Denis Haev", + "email": "dogafox@gmail.com" + }, + "publishConfig": { + "access": "public" + }, + "engines": { + "node": ">=16" + }, + "repository": { + "type": "git", + "url": "https://github.com/ioBroker/build-tools" + }, + "devDependencies": { + "@alcalzone/release-script": "^3.8.0", + "@alcalzone/release-script-plugin-license": "^3.7.0", + "@iobroker/eslint-config": "^0.1.6", + "@types/node": "^22.7.4", + "glob": "^11.0.0", + "typescript": "^5.6.2" + }, + "main": "build/index.js", + "files": [ + "build/", + "LICENSE" + ], + "scripts": { + "build": "tsc -p tsconfig.build.json", + "release": "release-script", + "release-patch": "release-script patch --yes --no-update-lockfile", + "release-minor": "release-script minor --yes --no-update-lockfile", + "release-major": "release-script major --yes --no-update-lockfile", + "update-packages": "ncu --upgrade && cd src-admin && ncu --upgrade", + "lint": "eslint -c eslint.config.mjs", + "test": "cd test && node collectFiles", + "npm": "npm i -f" + } } diff --git a/test/collectFiles.js b/test/collectFiles.js new file mode 100644 index 0000000..c31619b --- /dev/null +++ b/test/collectFiles.js @@ -0,0 +1,14 @@ +const { collectFiles } = require('../build/index.js'); + +const files = collectFiles('../build/*.ts'); +if (files.length !== 2) { + throw new Error(`Invalid number of files. Expected 2, got ${files.length}`); +} +files.forEach(item => { + if (item.base !== '../build') { + throw new Error(`Invalid base. Expected "../build", got ${item.base}`); + } + if (!item.name.endsWith('.ts')) { + throw new Error(`Invalid file. Expected "*.ts", got ${item.name}`); + } +});