Skip to content

Commit 4340154

Browse files
committed
Add missing version script for autocomplete client
1 parent 365c324 commit 4340154

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* This file only purpose is to execute any build related tasks
3+
*/
4+
5+
const { resolve, normalize } = require('path')
6+
const { readFileSync, writeFileSync } = require('fs')
7+
const pkg = require('../package.json')
8+
9+
const ROOT = resolve(__dirname, '..')
10+
const TYPES_ROOT_FILE = resolve(ROOT, normalize(pkg.typings))
11+
12+
main()
13+
14+
function main() {
15+
writeDtsHeader()
16+
}
17+
18+
function writeDtsHeader() {
19+
const dtsHeader = getDtsHeader(
20+
pkg.name,
21+
pkg.version,
22+
pkg.author,
23+
pkg.repository.url,
24+
pkg.devDependencies.typescript
25+
)
26+
27+
prependFileSync(TYPES_ROOT_FILE, dtsHeader)
28+
}
29+
30+
/**
31+
*
32+
* @param {string} pkgName
33+
* @param {string} version
34+
* @param {string} author
35+
* @param {string} repoUrl
36+
* @param {string} tsVersion
37+
*/
38+
function getDtsHeader(pkgName, version, author, repoUrl, tsVersion) {
39+
const extractUserName = repoUrl.match(/\.com\/([\w-]+)\/\w+/i)
40+
const githubUserUrl = extractUserName ? extractUserName[1] : 'Unknown'
41+
42+
return `
43+
// Type definitions for ${pkgName} ${version}
44+
// Project: ${repoUrl}
45+
// Definitions by: ${author} <https://github.com/${githubUserUrl}>
46+
// Definitions: ${repoUrl}
47+
// TypeScript Version: ${tsVersion}
48+
`.replace(/^\s+/gm, '')
49+
}
50+
51+
/**
52+
*
53+
* @param {string} path
54+
* @param {string | Blob} data
55+
*/
56+
function prependFileSync(path, data) {
57+
const existingFileContent = readFileSync(path, {
58+
encoding: 'utf8',
59+
})
60+
const newFileContent = [data, existingFileContent].join('\n')
61+
writeFileSync(path, newFileContent, {
62+
flag: 'w+',
63+
encoding: 'utf8',
64+
})
65+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const pkg = require('../package.json')
2+
const fs = require('fs')
3+
const path = require('path')
4+
5+
const version = pkg.version
6+
const fileContents = `export const PACKAGE_VERSION = '${version}'
7+
`
8+
9+
const filePath = path.resolve(__dirname, '../src/package-version.ts')
10+
11+
fs.writeFileSync(filePath, fileContents)

packages/instant-meilisearch/scripts/update_version.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ const fileContents = `export const PACKAGE_VERSION = '${version}'
88

99
const filePath = path.resolve(__dirname, '../src/package-version.ts')
1010

11-
console.log(filePath)
1211
fs.writeFileSync(filePath, fileContents)

0 commit comments

Comments
 (0)