Skip to content

Commit

Permalink
Merge pull request #18 from Phala-Network/imp-build
Browse files Browse the repository at this point in the history
Imp build command
  • Loading branch information
Leechael authored Nov 14, 2023
2 parents 5d88d1b + 7b11aea commit 0f34a0a
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 249 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CLI action
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16, 18, 20]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: npm run build
- name: Run Commands
run: |
./bin/run init --help
./bin/run build --help
./bin/run run --help
./bin/run watch --help
./bin/run upload --help
./bin/run update --help
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
},
"files": [
"/bin",
"/dist"
"/dist",
"/tsconfig.build.json"
],
"dependencies": {
"@oclif/core": "^2",
"@phala/sdk": "^0.5.3-nightly-20231013",
"@phala/sdk": "0.5.5-nightly-20231111",
"@types/node-fetch": "2",
"chalk": "4",
"dotenv": "^16.3.1",
Expand Down
29 changes: 19 additions & 10 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lstatSync, readFileSync } from 'node:fs'
import { lstatSync, readFileSync, existsSync } from 'node:fs'
import upath from 'upath'
import { Args, Command, Flags, ux } from '@oclif/core'
import chalk from 'chalk'
Expand Down Expand Up @@ -48,15 +48,24 @@ export default class Build extends Command {
let buildEntries: Record<string, string> = {
[upath.parse(script).name]: script,
}
const pjson = JSON.parse(readFileSync(upath.join(directory, 'package.json')).toString())
if (pjson.exports && typeof pjson.exports !== 'string') {
buildEntries = Object.entries(pjson.exports as Record<string, string>).reduce(
(acc, [key, value]) => {
acc[key] = value
return acc
},
{ ...buildEntries },
)


const pjson_file_path = upath.join(directory, 'package.json')
if (existsSync(pjson_file_path)) {
try {
const pjson = JSON.parse(readFileSync(pjson_file_path).toString())
if (pjson.exports && typeof pjson.exports !== 'string') {
buildEntries = Object.entries(pjson.exports as Record<string, string>).reduce(
(acc, [key, value]) => {
acc[key] = value
return acc
},
{ ...buildEntries },
)
}
} catch (error) {
this.error(`Error parsing package.json: ${error}`)
}
}

for (const i in buildEntries) {
Expand Down
22 changes: 12 additions & 10 deletions src/lib/PhatCommandBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import chalk from 'chalk'
import { filesize } from 'filesize'
import { Command, Args, Flags, ux } from '@oclif/core'
import {
options,
getClient,
OnChainRegistry,
signCertificate,
unsafeGetAbiFromGitHubRepoByCodeHash,
PinkContractPromise,
type CertificateData,
} from '@phala/sdk'
import { ApiPromise, WsProvider } from '@polkadot/api'
import { ApiPromise } from '@polkadot/api'
import { Abi } from '@polkadot/api-contract'
import { waitReady } from '@polkadot/wasm-crypto'
import { Keyring } from '@polkadot/keyring'
Expand All @@ -39,6 +39,7 @@ export interface ParsedFlags {
readonly accountFilePath: string
readonly accountPassword: string
readonly coreSettings: string
readonly pruntimeUrl: string
}

interface ParsedArgs {
Expand Down Expand Up @@ -98,6 +99,10 @@ export default abstract class PhatCommandBase extends Command {
description: 'Core settings',
required: false,
}),
pruntimeUrl: Flags.string({
description: 'Pruntime URL',
required: false,
}),
mode: Flags.custom({
options: ['production', 'prod', 'development', 'dev'],
default: 'development',
Expand Down Expand Up @@ -205,15 +210,12 @@ export default abstract class PhatCommandBase extends Command {
endpoint: string
pair: KeyringPair
}): Promise<[ApiPromise, OnChainRegistry, CertificateData]> {
const apiPromise = await ApiPromise.create(
options({
provider: new WsProvider(endpoint),
noInitWarn: true,
})
)
const registry = await OnChainRegistry.create(apiPromise)
const registry = await getClient({
transport: endpoint,
pruntimeURL: this.parsedFlags.pruntimeUrl,
})
const cert = await signCertificate({ pair })
return [apiPromise, registry, cert]
return [registry.api, registry, cert]
}

async getRollupAbi() {
Expand Down
10 changes: 3 additions & 7 deletions src/lib/runWebpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@ const getBaseConfig = (
exclude: /node_modules/,
loader: require.resolve('ts-loader'),
options: {
compilerOptions: {
declaration: false,
moduleResolution: 'node',
module: 'es6',
},
configFile: require.resolve('../../tsconfig.build.json'),
onlyCompileBundledFiles: true,
},
}
},
],
},
Expand All @@ -70,7 +66,7 @@ const getBaseConfig = (


function modifyFilePath(filePath: string) {
let newFilePath = filePath.replace(/\/([^/]+)$/, '/_$1')
let newFilePath = filePath.replace(/([^/]+)$/, '_$1')
if (!newFilePath.endsWith('.ts')) {
newFilePath += '.ts'
}
Expand Down
12 changes: 12 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"module": "es6",
"target": "es2020",
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"declaration": false,
"moduleResolution": "node",
"allowJs": true
}
}
Loading

0 comments on commit 0f34a0a

Please sign in to comment.