test.js 2.1 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
const fs = require('fs')
fxy060608's avatar
fxy060608 已提交
2
const path = require('path')
fxy060608's avatar
fxy060608 已提交
3
const { parse, bundle, UtsTarget } = require('../packages/uts/dist')
fxy060608's avatar
fxy060608 已提交
4
const projectDir = path.resolve(__dirname, '../packages/playground/uts')
fxy060608's avatar
fxy060608 已提交
5

fxy060608's avatar
fxy060608 已提交
6
const start = Date.now()
fxy060608's avatar
fxy060608 已提交
7 8
parse(
  fs.readFileSync(
fxy060608's avatar
fxy060608 已提交
9 10 11 12
    path.resolve(
      projectDir,
      'uni_modules/test-uniplugin/app-android/index.uts'
    ),
fxy060608's avatar
fxy060608 已提交
13 14 15 16 17 18
    'utf8'
  )
).then((res) => {
  console.log('parse: ' + (Date.now() - start) + 'ms')
  console.log(JSON.stringify(res))
})
fxy060608's avatar
fxy060608 已提交
19 20 21 22 23 24
function testKotlin() {
  const start = Date.now()
  return bundle(UtsTarget.KOTLIN, {
    input: {
      root: projectDir,
      filename: path.resolve(
fxy060608's avatar
fxy060608 已提交
25
        projectDir,
fxy060608's avatar
fxy060608 已提交
26
        'uni_modules/test-uniplugin/app-android/index.uts'
fxy060608's avatar
fxy060608 已提交
27
      ),
fxy060608's avatar
fxy060608 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    },
    output: {
      outDir: path.resolve(projectDir, 'unpackage/dist/app'),
      package: 'uts.modules.testUniPlugin',
      imports: ['kotlinx.coroutines.*', 'io.dcloud.uts.runtime.*'],
      sourceMap: true,
      extname: 'kt',
      logFilename: true,
    },
  }).then((res) => {
    console.log('bundle: ' + (Date.now() - start) + 'ms')
    console.log(JSON.stringify(res))
    console.log(
      fs.readFileSync(
        path.resolve(
          projectDir,
          'unpackage/dist/app/uni_modules/test-uniplugin/app-android/index.kt'
        ),
        'utf8'
      )
fxy060608's avatar
fxy060608 已提交
48
    )
fxy060608's avatar
fxy060608 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  })
}

function testSwift() {
  const start = Date.now()
  return bundle(UtsTarget.SWIFT, {
    input: {
      root: projectDir,
      filename: path.resolve(
        projectDir,
        'uni_modules/test-uniplugin/app-ios/index.uts'
      ),
    },
    output: {
      outDir: path.resolve(projectDir, 'unpackage/dist/app'),
      package: 'uts.modules.testUniPlugin',
      sourceMap: true,
      extname: 'swift',
      logFilename: true,
    },
  }).then((res) => {
    console.log('bundle: ' + (Date.now() - start) + 'ms')
    console.log(JSON.stringify(res))
    console.log(
      fs.readFileSync(
        path.resolve(
          projectDir,
          'unpackage/dist/app/uni_modules/test-uniplugin/app-ios/index.swift'
        ),
        'utf8'
      )
    )
  })
}

async function test() {
  await testKotlin()
  await testSwift()
}

test()