Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions packages/autocomplete-client/scripts/build.js
Original file line number Diff line number Diff line change
@@ -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} <https://github.com/${githubUserUrl}>
// 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',
})
}
11 changes: 11 additions & 0 deletions packages/autocomplete-client/scripts/update_version.js
Original file line number Diff line number Diff line change
@@ -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)
1 change: 0 additions & 1 deletion packages/instant-meilisearch/scripts/update_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)