Skip to content

chore: added types for few utility methods #2172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
12 changes: 12 additions & 0 deletions lib/utils/colors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
'use strict';

const colors = {
/**
* info color Method
* @param {?boolean} useColor - use color with message
* @param {string} msg - log message
* @returns {string}
*/
info(useColor, msg) {
if (useColor) {
// Make text blue and bold, so it *pops*
Expand All @@ -9,6 +15,12 @@ const colors = {

return msg;
},
/**
* error color Method
* @param {?boolean} useColor - use color with message
* @param {string} msg - log message
* @returns {string}
*/
error(useColor, msg) {
if (useColor) {
// Make text red and bold, so it *pops*
Expand Down
13 changes: 13 additions & 0 deletions lib/utils/createCertificate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
'use strict';

const selfsigned = require('selfsigned');
/**
* Pem Type generated by the generatePem method of selfsigned package
* @typedef {Object} pemType
* @property {string} private - privateKeyToPem
* @property {string} public - publicKeyToPem
* @property {string} cert - certificateToPem
* @property {string} fingerprint
*/

/**
* Create Certificate Method
* @param {Object} attributes - selfsigned attributes refs : https://github.com/digitalbazaar/forge/blob/0.7.5/lib/x509.js#L129
* @returns {pemType}
*/
function createCertificate(attributes) {
return selfsigned.generate(attributes, {
algorithm: 'sha256',
Expand Down
18 changes: 18 additions & 0 deletions lib/utils/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ const path = require('path');
const isAbsoluteUrl = require('is-absolute-url');
const defaultTo = require('./defaultTo');

/**
* Webpack-dev-server options
* @typedef {Object} WDSOptions - refs https://github.com/webpack/webpack-dev-server/blob/master/bin/options.js#L14
*/

/**
* Custom Configs passed as third argument to createConfig method
* @typedef {Object} customConfigs
* @property {number} port - port to listen
*/

/**
* Create Config Method
* @param {Object} config - Webpack config, refs https://webpack.js.org/configuration/
* @param {Object} argv - WDS CLI Arguments passed, refs https://github.com/webpack/webpack-dev-server/blob/master/bin/options.js#L14
* @param {customConfigs} customArgs
* @returns {WDSOptions}
*/
function createConfig(config, argv, { port }) {
const firstWpOpt = Array.isArray(config) ? config[0] : config;
const options = firstWpOpt.devServer || {};
Expand Down
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@
"types": ["node"],
"esModuleInterop": true
},
"include": ["lib/utils/addEntries.js"]
"include": [
"lib/utils/addEntries.js",
"lib/utils/colors.js",
"lib/utils/createCertificate.js",
"lib/utils/createConfig.js"
]
}