Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦️ chore: Add release package #1027

Merged
merged 1 commit into from
Dec 3, 2023
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
58 changes: 58 additions & 0 deletions packages/core/src/cli/cliEntrypoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import path from 'node:path'
import chalk from 'chalk'
import { Command } from 'commander'
import { rimraf } from 'rimraf'
import { WALLET_SETUP_DIR_NAME } from '../constants'
import { createCache } from '../createCache'
import { prepareExtension } from '../prepareExtension'
import { compileWalletSetupFunctions } from './compileWalletSetupFunctions'
import { footer } from './footer'

interface CliFlags {
headless: boolean
force: boolean
debug: boolean
}

// TODO: Add unit tests for the CLI!
export const cliEntrypoint = async () => {
console.log(`⚠️ ${chalk.yellowBright`The CLI is in alpha so expect breaking changes!`} ⚠️\n`)

const program = new Command()
.name(chalk.magenta('core'))
.description('A CLI for building the cache of wallet setup functions')
.argument('[dir]', 'Directory containing the wallet setup functions', path.join('test', WALLET_SETUP_DIR_NAME))
.option(
'--headless',
'Build cache in the headless browser mode. Alternatively, set the `HEADLESS` env variable to `true`',
false
)
.option('-f, --force', 'Force the creation of cache even if it already exists', false)
.option('-d, --debug', 'If this flag is present, the compilation files are not going to be deleted', false)
.helpOption(undefined, 'Display help for command')
.addHelpText('afterAll', `\n${footer}\n`)
.parse(process.argv)

let walletSetupDir = program.args[0]
if (!walletSetupDir) {
walletSetupDir = path.join(process.cwd(), 'test', WALLET_SETUP_DIR_NAME)
}

const flags: CliFlags = program.opts()

if (flags.headless) {
process.env.HEADLESS = true
}

console.log('[DEBUG] Running with the following options:')
console.log({ cacheDir: walletSetupDir, ...flags, headless: Boolean(process.env.HEADLESS) ?? false }, '\n')

const compiledWalletSetupDirPath = await compileWalletSetupFunctions(walletSetupDir, flags.debug)

// TODO: We should be using `prepareExtension` function from the wallet itself!
await createCache(compiledWalletSetupDirPath, prepareExtension, flags.force)

if (!flags.debug) {
await rimraf(compiledWalletSetupDirPath)
}
}
61 changes: 2 additions & 59 deletions packages/core/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,8 @@
#!/usr/bin/env node

import path from 'node:path'
import chalk from 'chalk'
import { Command } from 'commander'
import { rimraf } from 'rimraf'
import { WALLET_SETUP_DIR_NAME } from '../constants'
import { createCache } from '../createCache'
import { prepareExtension } from '../prepareExtension'
import { compileWalletSetupFunctions } from './compileWalletSetupFunctions'
import { footer } from './footer'
import { cliEntrypoint } from './cliEntrypoint'

interface CliFlags {
headless: boolean
force: boolean
debug: boolean
}

// TODO: Add unit tests for the CLI!
export const main = async () => {
console.log(`⚠️ ${chalk.yellowBright`The CLI is in alpha so expect breaking changes!`} ⚠️\n`)

const program = new Command()
.name(chalk.magenta('core'))
.description('A CLI for building the cache of wallet setup functions')
.argument('[dir]', 'Directory containing the wallet setup functions', path.join('test', WALLET_SETUP_DIR_NAME))
.option(
'--headless',
'Build cache in the headless browser mode. Alternatively, set the `HEADLESS` env variable to `true`',
false
)
.option('-f, --force', 'Force the creation of cache even if it already exists', false)
.option('-d, --debug', 'If this flag is present, the compilation files are not going to be deleted', false)
.helpOption(undefined, 'Display help for command')
.addHelpText('afterAll', `\n${footer}\n`)
.parse(process.argv)

let walletSetupDir = program.args[0]
if (!walletSetupDir) {
walletSetupDir = path.join(process.cwd(), 'test', WALLET_SETUP_DIR_NAME)
}

const flags: CliFlags = program.opts()

if (flags.headless) {
process.env.HEADLESS = true
}

console.log('[DEBUG] Running with the following options:')
console.log({ cacheDir: walletSetupDir, ...flags, headless: Boolean(process.env.HEADLESS) ?? false }, '\n')

const compiledWalletSetupDirPath = await compileWalletSetupFunctions(walletSetupDir, flags.debug)

// TODO: We should be using `prepareExtension` function from the wallet itself!
await createCache(compiledWalletSetupDirPath, prepareExtension, flags.force)

if (!flags.debug) {
await rimraf(compiledWalletSetupDirPath)
}
}

main().catch((err) => {
cliEntrypoint().catch((err) => {
console.log('Aborting...')

if (err instanceof Error) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './defineWalletSetup'
export * from './utils/createTempContextDir'
export * from './utils/removeTempContextDir'
export * from './prepareExtension'
export * from './cli/cliEntrypoint'
31 changes: 31 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ packages:
- "packages/*"
- "wallets/*"
- "examples/*"
- "release"
46 changes: 46 additions & 0 deletions release/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@synthetixio/synpress",
"version": "4.0.0",
"type": "module",
"exports": {
".": {
"import": {
"types": "./types/index.d.ts",
"default": "./dist/index.js"
}
}
},
"main": "./dist/index.js",
"bin": "./dist/cli.js",
"files": [
"dist",
"src",
"types"
],
"scripts": {
"build": "pnpm run clean && pnpm run build:dist && pnpm run build:types",
"build:dist": "tsup",
"build:types": "tsc --emitDeclarationOnly",
"clean": "rimraf dist types",
"lint": "biome check . --apply",
"lint:check": "biome check . --verbose",
"lint:unsafe": "biome check . --apply-unsafe",
"prepublishOnly": "pnpm run build",
"types:check": "tsc --noEmit"
},
"dependencies": {
"@synthetixio/synpress-core": "workspace:*",
"@synthetixio/synpress-fixtures": "workspace:*",
"@synthetixio/synpress-metamask": "workspace:*"
},
"devDependencies": {
"@types/node": "^20.8.0",
"rimraf": "^5.0.1",
"tsconfig": "workspace:*",
"tsup": "^7.2.0",
"typescript": "^5.2.2"
},
"peerDependencies": {
"@playwright/test": "1.40.0"
}
}
15 changes: 15 additions & 0 deletions release/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node

import { cliEntrypoint } from '@synthetixio/synpress-core'

cliEntrypoint().catch((err) => {
console.log('Aborting...')

if (err instanceof Error) {
console.error(err)
} else {
console.error('Unknown error occurred!', err)
}

process.exit(1)
})
5 changes: 5 additions & 0 deletions release/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineWalletSetup } from '@synthetixio/synpress-core'
import { getExtensionId, testWithSynpress } from '@synthetixio/synpress-fixtures'
import { MetaMask, unlockForFixture } from '@synthetixio/synpress-metamask'

export { defineWalletSetup, testWithSynpress, getExtensionId, MetaMask, unlockForFixture }
11 changes: 11 additions & 0 deletions release/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "tsconfig/base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "types",
"declaration": true,
"sourceMap": false,
"declarationMap": true
},
"include": ["src/index.ts"]
}
10 changes: 10 additions & 0 deletions release/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'tsup'

export default defineConfig({
name: 'synpress',
entry: ['src/index.ts', 'src/cli.ts'],
outDir: 'dist',
format: 'esm',
splitting: false,
sourcemap: false
})