-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use import type and add esm dist
- Loading branch information
Showing
147 changed files
with
461 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
import { execSync } from 'child_process'; | ||
import parseArgs from 'minimist'; | ||
import { SemVer } from 'semver'; | ||
|
||
function getCurrentGitBranch(): string { | ||
return execSync('git branch --show-current').toString().trim(); | ||
} | ||
|
||
/** | ||
* @var {string} p - path to directory where package.json is located | ||
*/ | ||
const { p: packageJsonDir = '.' } = parseArgs(process.argv.slice(2)); | ||
|
||
void (async (): Promise<void> => { | ||
const packageJsonPath = `${packageJsonDir}/package.json`; | ||
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString()); | ||
const { version } = packageJson; | ||
const branchName: string = getCurrentGitBranch(); | ||
|
||
const ticketNumber: string | undefined = /^(feature|feat|hotifx|fix)\/(\d+)/gim.exec(branchName)?.[0]?.split('/').pop(); | ||
const semVer: SemVer = new SemVer(version); | ||
|
||
if (!semVer) { | ||
throw new Error(`Can't find package.json version`); | ||
} | ||
|
||
console.log('Input data', { packageJsonPath, branchName, ticketNumber, version: semVer.format() }); | ||
|
||
if (!semVer.prerelease.length && !ticketNumber) { | ||
throw new Error(`Your branch should contain the ticket number or the package.json version should be with the prerelease version`); | ||
} | ||
if (semVer.prerelease.length && Number.isSafeInteger(semVer.prerelease[semVer.prerelease.length - 1])) { | ||
// @ts-ignore | ||
semVer.prerelease[semVer.prerelease.length - 1]++; | ||
} else if (ticketNumber) { | ||
semVer.prerelease = [`dev`, ticketNumber, 0]; | ||
} | ||
|
||
console.log('Output data', { packageJsonPath, branchName, ticketNumber, version: semVer.format() }); | ||
|
||
packageJson.version = semVer.format(); | ||
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 4)); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
import { writeFileSync, copyFileSync } from 'fs'; | ||
import originPackage from '../package.json'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const distPackage: Record<string, any> = originPackage; | ||
distPackage.module = './index.js'; | ||
distPackage.main = './index.js'; | ||
distPackage.types = './index.d.ts'; | ||
delete distPackage.scripts; | ||
delete distPackage.devDependencies; | ||
delete distPackage.config; | ||
delete distPackage.husky; | ||
delete distPackage.files; | ||
delete distPackage.directories; | ||
delete distPackage['lint-staged']; | ||
async function run(): Promise<void> { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const { scripts, devDependencies, husky, files, 'lint-staged': lintStaged, directories, config, ...packageJson } = JSON.parse( | ||
fs.readFileSync(path.join(process.cwd(), 'package.json')).toString(), | ||
); | ||
|
||
writeFileSync('./dist/package.json', JSON.stringify(distPackage, null, ' ')); | ||
packageJson.main = './cjs/index.js'; | ||
packageJson.module = './esm/index.js'; | ||
packageJson.typings = './types/index.d.ts'; | ||
packageJson.sideEffects = false; | ||
|
||
const copyFiles = ['README.md']; | ||
for (const file of copyFiles) { | ||
copyFileSync(`./${file}`, `./dist/${file}`); | ||
fs.writeFileSync('./dist/package.json', JSON.stringify(packageJson, null, 4)); | ||
|
||
const copyFiles = ['README.md']; | ||
for (const file of copyFiles) { | ||
fs.copyFileSync(`./${file}`, `./dist/${file}`); | ||
} | ||
} | ||
|
||
void run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.