You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.8 KiB
68 lines
1.8 KiB
// const esbuild = require('esbuild');
|
|
// import esbuild from 'esbuild';
|
|
// import fs from 'fs';
|
|
// import path from 'path';
|
|
const esbuild = require('esbuild');
|
|
const fs = require('fs');
|
|
const path = require('path')
|
|
const targetDir = 'dist';
|
|
|
|
async function build()
|
|
{
|
|
const result = await esbuild.build({
|
|
entryPoints: ['src/app.ts'],
|
|
bundle: true,
|
|
platform: 'node',
|
|
sourcemap: 'external',
|
|
outfile: `${targetDir}/app.js`,
|
|
external: ['punycode']
|
|
}).catch(() => process.exit(1))
|
|
|
|
copyFiles();
|
|
}
|
|
|
|
function copyFiles()
|
|
{
|
|
const sdk = JSON.parse(fs.readFileSync(path.join(process.cwd(), './src/com/7zcloud/', './config/sdk.json'), {encoding: 'utf-8'}))
|
|
copyConfigs(sdk);
|
|
copySdks(sdk);
|
|
}
|
|
|
|
function copyConfigs(sdk)
|
|
{
|
|
const len = sdk.sdkpath.length;
|
|
const targetPaths = [];
|
|
for(let i = 0;i < len;i ++){
|
|
let sdkPath = sdk.sdkpath[i];
|
|
sdkPath = sdkPath.substring(sdkPath.lastIndexOf('/'));
|
|
targetPaths.push(`./sdk${sdkPath}`)
|
|
}
|
|
const targetSdk = {
|
|
sdkpath: targetPaths,
|
|
isDev: false
|
|
}
|
|
const dirPath = mkdirSync('config')
|
|
fs.writeFileSync(path.join(dirPath, `/sdk.json`), JSON.stringify(targetSdk, null, 4));
|
|
}
|
|
|
|
function copySdks(sdk)
|
|
{
|
|
const targetDir = mkdirSync('sdk')
|
|
for(let i = 0;i < sdk.sdkpath.length;i ++)
|
|
{
|
|
let sdkPath = sdk.sdkpath[i];
|
|
sdkPath = sdkPath.substring(sdkPath.lastIndexOf('/'));
|
|
fs.copyFileSync(path.join(process.cwd(), sdk.sdkpath[i]), `${targetDir}${sdkPath}`)
|
|
}
|
|
}
|
|
|
|
function mkdirSync(dir)
|
|
{
|
|
const dirPath = path.join(process.cwd(), `${targetDir}/${dir}`);
|
|
if(fs.existsSync(dirPath) === false){
|
|
fs.mkdirSync(dirPath);
|
|
}
|
|
return dirPath;
|
|
}
|
|
|
|
build();
|