API

API

Methods

(static) bundleJScriptSrcs(scriptPaths, options) → {string}

Source:

Bundles JScripts

Parameters:
Name Type Description
scriptPaths Array.<string>

JScript src paths

options object

Optional parameters

Properties
Name Type Attributes Default Description
baseDir string <optional>
'.'
minifies boolean <optional>
true
ignoreSrc string | RegExp <optional>
Returns:
  • A bundled JScript code
Type
string

(static) bundleVBScriptSrcs(scriptPaths, options) → {string}

Source:

Bundles VBScripts

Parameters:
Name Type Description
scriptPaths Array.<string>

VBScript src paths

options object

Optional parameters

Properties
Name Type Attributes Default Description
baseDir string <optional>
'.'
minifies boolean <optional>
true
ignoreSrc string | RegExp <optional>
Returns:
  • A bundled JScript code
Type
string

(static) bundleWsfJob(wshObjs, options) → {string}

Source:

Bundles the job of .wsf into a .wsf file

Parameters:
Name Type Description
wshObjs Array.<object>
options object

Optional parameters

Properties
Name Type Attributes Default Description
baseDir string <optional>
'.'
minifies boolean <optional>
true
ignoreSrc string | RegExp <optional>
Returns:
  • A code bundled
Type
string

(static) bundleWshFiles(dirPath, optionsopt) → {void}

Source:

Bundles .wsf jobs defined in Package.wsf

Example
const { bundleWshFiles } = require('@tuckn/wsh-packager');

// Ex1.
// [File structure]
// D:\MyWshFolder\
// ├─ Package.wsf
// └─ src\
//     ├─ Function.js
//     ├─ Object.js
//     └─ JSON.js

// [The content of Package.wsf]
// <package>
//   <job id = "./dist/JSON.min.js">
//     <script language="JScript" src="./src/Function.js"></script>
//     <script language="JScript" src="./src/Object.js"></script>
//     <script language="JScript" src="./src/JSON.js"></script>
//   </job>
// </package>

bundleWshFiles('D:\\MyWshFolder');
// [The result]
// D:\MyWshFolder\
// ├─ Package.wsf
// ├─ dist\
// │  └─ JSON.min.js
// └─ src\
//     ├─ Function.js
//     ├─ Object.js
//     └─ JSON.js

// Ex2.
// [File structure]
// D:\MyWshFolder\
// ├─ Package.wsf
// └─ src\
//     ├─ CLI.js
//     ├─ Excel.vbs
//     ├─ Function.js
//     ├─ Object.js
//     ├─ JSON.js
//     └─ Util.vbs

// [The content of Package.wsf]
// <package>
//   <job id = "./dist/MyModule.vbs">
//     <script language="VBScript" src="./src/Util.vbs"></script>
//     <script language="VBScript" src="./src/Excel.vbs"></script>
//   </job>
//   <job id = "./dist/JSON.min.js">
//     <script language="JScript" src="./src/Function.js"></script>
//     <script language="JScript" src="./src/Object.js"></script>
//     <script language="JScript" src="./src/JSON.js"></script>
//   </job>
//   <job id = "./dist/Run.wsf">
//     <script language="JScript" src="./src/Function.js"></script>
//     <script language="VBScript" src="./src/Excel.vbs"></script>
//     <script language="JScript" src="./src/CLI.js"></script>
//   </job>
// </package>

bundleWshFiles('D:\\MyWshFolder');
// [The result]
// D:\MyWshFolder\
// ├─ Package.wsf
// ├─ dist\
// │  ├─ JSON.min.js
// │  ├─ MyModule.vbs
// │  └─ Run.wsf
// └─ src\
//     ├─ CLI.js
//     ├─ Excel.vbs
//     ├─ Function.js
//     ├─ Object.js
//     ├─ JSON.js
//     └─ Util.vbs
Parameters:
Name Type Attributes Description
dirPath string

A directory path where Package.wsf is located or the full-path of your .wsf file.

options object <optional>

Optional parameters

Properties
Name Type Attributes Description
jobId string <optional>

A job id to be bundled (Default: "\.(js|vbs|wsf)$").

baseDir string <optional>

Default is the dirPath

ignoreSrc string | RegExp <optional>

Ex. "main\.js$"

Returns:
Type
void

(static) minifyJsCode(code) → {string}

Source:

Minify JScript code

Parameters:
Name Type Description
code string

A code of JScript

Returns:
  • A minified JScript code
Type
string

(static) minifyVbsCode(code) → {string}

Source:

Minify VBScript code

Parameters:
Name Type Description
code string

A code of VBScript

Returns:
  • A minified VBScript code
Type
string

(static) surroundWithPackageJob(content) → {string}

Source:

Surrounds WSH contents with package and job tags for .wsf file. The "job id" will be "run".

Parameters:
Name Type Description
content string
Returns:
  • A code surrounded
Type
string

(static) surroundWshCode(wshCode, lang) → {string}

Source:

Surrounds A WSH code with script tag

Parameters:
Name Type Description
wshCode string

WSH code string

lang string

A value of language attribute. JScript of VBScript

Returns:
  • A code surrounded
Type
string