All files / lib/dev-server-asset dev-server.js

88% Statements 22/25
62.5% Branches 5/8
100% Functions 4/4
100% Lines 22/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 402x 2x 2x 2x 2x 2x   2x 4x   4x 4x   4x 4x   4x 2x     4x         4x 4x   4x 4x   4x 4x       2x      
const fs = require('fs');
const path = require('path');
const {buildComponentsListFile, buildComponentMapJsFile} = require('../build/build');
const CONSTANTS = require('../constant');
const child_process = require("child_process");
const helper = require('../helper');
 
const devServerStart = async(libraryName, libraryVersion, port) => {
  const { buildFolderFullPath, buildFolderName, packageVersion } = helper.getBuildFolderName(libraryName, libraryVersion);
   
  buildComponentsListFile(buildFolderName, packageVersion, true);
  buildComponentMapJsFile(buildFolderFullPath);
  
  const webpackPath = path.join(CONSTANTS.BUILD_TOOL_ROOT_PATH).replace(/\\/g, '/');
  const projectPath = path.join(CONSTANTS.CURRENT_WORKING_DIR, CONSTANTS.PROJECT_ROOT).replace(/\\/g, '/');
    
  if(!port){
    port = 3030;
  }
  
  child_process.execSync(`npx webpack serve --mode=development --env mode=development buildFolderFullPath=${buildFolderFullPath} v3=false port=${port} --config ${webpackPath}/webpack.config.js`, {
    stdio: [0, 1, 2],
    cwd: path.join(CONSTANTS.CURRENT_WORKING_DIR).replace(/\\/g, '/'),
  });
 
  fs.unlink(path.join(projectPath, CONSTANTS.COMPONENT_LIST_FILE_NAME_OUTPUT).replace(/\\/g, '/'), (err) => {
    Iif (err) throw err;
  });
  fs.unlink(path.join(projectPath, CONSTANTS.COMPONENT_LIST_FILE_NAME).replace(/\\/g, '/'), (err) => {
    Iif (err) throw err;
  });
  fs.unlink(path.join(projectPath, CONSTANTS.ENTRY_POINT_FILE).replace(/\\/g, '/'), (err) => {
    Iif (err) throw err;
  });
}
 
module.exports = {
  devServerStart
}