Files
cypress/cli/scripts/build.ts
Cacie Prins 48c2ba28e7 chore: upgrade cli eslint to 9 (#32446)
* chore: replace dtslint with eslint-plugin-expect-type

* update guide

* add lint-staged

* rm stale script

* modify cli eslint and tsconfigs to support ts migration

* separate expect-type files

* modifications to tsconfigs to make eslint a little easier

* revert workflow.yml

* further revision

* put tslint config for dtslint back in

* ensure false negative case is tested

* correct tsconfigs

* align dtslint tsconfig with eslint 9 config

* consolidate / DRY tsconfigs
2025-09-26 11:16:42 -04:00

83 lines
2.1 KiB
TypeScript

import _ from 'lodash'
import path from 'path'
import shell from 'shelljs'
import fs from 'fs-extra'
// grab the current version and a few other properties
// from the root package.json
import rootPkg from '@packages/root'
const {
version,
description,
homepage,
license,
bugs,
repository,
keywords,
} = rootPkg as any
// the rest of properties should come from the package.json in CLI folder
const packageJsonSrc = path.join('package.json')
const packageJsonDest = path.join('build', 'package.json')
function getStdout (cmd: string): string {
return shell.exec(cmd).trim()
}
function preparePackageForNpmRelease (json: any, branchName?: string): any {
// modify the existing package.json
// to prepare it for releasing to npm
delete json.devDependencies
delete json['private']
// no need to include "nyc" code coverage settings
delete json.nyc
delete json.workspaces
_.extend(json, {
version,
buildInfo: {
commitBranch: branchName || process.env.CIRCLE_BRANCH || getStdout('git branch --show-current'),
commitSha: getStdout('git rev-parse HEAD'),
commitDate: new Date(getStdout('git show -s --format=%ci')).toISOString(),
stable: false,
},
description,
homepage,
license,
bugs,
repository,
keywords,
types: 'types', // typescript types
scripts: {
postinstall: 'node dist/index.js --exec install',
size: 't="$(npm pack .)"; wc -c "${t}"; tar tvf "${t}"; rm "${t}";',
},
})
return json
}
async function makeUserPackageFile (branchName?: string): Promise<any> {
const json = await fs.readJson(packageJsonSrc)
const jsonPrepared = preparePackageForNpmRelease(json, branchName)
await fs.outputJson(packageJsonDest, jsonPrepared, {
spaces: 2,
}) // returning package json object makes it easy to test
return jsonPrepared
}
export default makeUserPackageFile
if (require.main === module) {
makeUserPackageFile(process.env.BRANCH)
.catch((err: any) => {
console.error('Could not write user package file')
console.error(err)
process.exit(-1)
})
}