diff --git a/packages/autocomplete-client/scripts/build.js b/packages/autocomplete-client/scripts/build.js new file mode 100644 index 00000000..ae50a4b8 --- /dev/null +++ b/packages/autocomplete-client/scripts/build.js @@ -0,0 +1,65 @@ +/** + * This file only purpose is to execute any build related tasks + */ + +const { resolve, normalize } = require('path') +const { readFileSync, writeFileSync } = require('fs') +const pkg = require('../package.json') + +const ROOT = resolve(__dirname, '..') +const TYPES_ROOT_FILE = resolve(ROOT, normalize(pkg.typings)) + +main() + +function main() { + writeDtsHeader() +} + +function writeDtsHeader() { + const dtsHeader = getDtsHeader( + pkg.name, + pkg.version, + pkg.author, + pkg.repository.url, + pkg.devDependencies.typescript + ) + + prependFileSync(TYPES_ROOT_FILE, dtsHeader) +} + +/** + * + * @param {string} pkgName + * @param {string} version + * @param {string} author + * @param {string} repoUrl + * @param {string} tsVersion + */ +function getDtsHeader(pkgName, version, author, repoUrl, tsVersion) { + const extractUserName = repoUrl.match(/\.com\/([\w-]+)\/\w+/i) + const githubUserUrl = extractUserName ? extractUserName[1] : 'Unknown' + + return ` +// Type definitions for ${pkgName} ${version} +// Project: ${repoUrl} +// Definitions by: ${author} +// Definitions: ${repoUrl} +// TypeScript Version: ${tsVersion} +`.replace(/^\s+/gm, '') +} + +/** + * + * @param {string} path + * @param {string | Blob} data + */ +function prependFileSync(path, data) { + const existingFileContent = readFileSync(path, { + encoding: 'utf8', + }) + const newFileContent = [data, existingFileContent].join('\n') + writeFileSync(path, newFileContent, { + flag: 'w+', + encoding: 'utf8', + }) +} diff --git a/packages/autocomplete-client/scripts/update_version.js b/packages/autocomplete-client/scripts/update_version.js new file mode 100644 index 00000000..c3387635 --- /dev/null +++ b/packages/autocomplete-client/scripts/update_version.js @@ -0,0 +1,11 @@ +const pkg = require('../package.json') +const fs = require('fs') +const path = require('path') + +const version = pkg.version +const fileContents = `export const PACKAGE_VERSION = '${version}' +` + +const filePath = path.resolve(__dirname, '../src/package-version.ts') + +fs.writeFileSync(filePath, fileContents) diff --git a/packages/instant-meilisearch/scripts/update_version.js b/packages/instant-meilisearch/scripts/update_version.js index 6064643d..c3387635 100644 --- a/packages/instant-meilisearch/scripts/update_version.js +++ b/packages/instant-meilisearch/scripts/update_version.js @@ -8,5 +8,4 @@ const fileContents = `export const PACKAGE_VERSION = '${version}' const filePath = path.resolve(__dirname, '../src/package-version.ts') -console.log(filePath) fs.writeFileSync(filePath, fileContents)