Skip to content

Commit

Permalink
Merge pull request #246 from codeceptjs/some-improvements
Browse files Browse the repository at this point in the history
- handle errors when cannot load the docs
- open the links in new browser tab
- improve some scripts
  • Loading branch information
kobenguyent authored Feb 8, 2024
2 parents 4b8f413 + d6ea3de commit bb86601
Show file tree
Hide file tree
Showing 5 changed files with 9,190 additions and 36,360 deletions.
49 changes: 23 additions & 26 deletions lib/api/list-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,34 @@ const codeceptjsFactory = require('../model/codeceptjs-factory');
const { methodsOfObject } = require('codeceptjs/lib/utils');

module.exports = (req, res) => {
const { container } = codeceptjsFactory.getInstance();
const docsWebApiFolderPath = path.join(path.dirname(require.resolve('codeceptjs')), '/../docs/webapi');
const docFileList = [];
try {
const { container } = codeceptjsFactory.getInstance();
const docsWebApiFolderPath = path.join(path.dirname(require.resolve('codeceptjs')), '/../docs/webapi');
const docFileList = [];
fs.readdirSync(docsWebApiFolderPath).map(fileName => {
docFileList.push(path.basename(fileName,'.mustache'));
});
const helpers = container.helpers();
const actions = {};
for (const name in helpers) {
const helper = helpers[name];
methodsOfObject(helper).forEach((action) => {

if(docFileList.includes(action)) {
let filePath = path.join(docsWebApiFolderPath, action + '.mustache');
let fn = helper[action].toString().replace(/\n/g,' ').replace(/\{.*\}/gm,'{}');
try{
let docData = fs.readFileSync(filePath, 'utf-8');
let params = parser.parse(fn);
actions[action] = { params: params, actionDoc: docData };
} catch(err) {
debug('Error in fetching doc for file content', fn, err);
}
}

});
}

res.send({ actions });
} catch (e) {
debug(`Could not fetch documentation due to: ${e.message}`);
debug(`No documentation found due to ${e.message}`);
}
const helpers = container.helpers();
const actions = {};
for (const name in helpers) {
const helper = helpers[name];
methodsOfObject(helper).forEach((action) => {

if (docFileList.includes(action)) {
let filePath = path.join(docsWebApiFolderPath, action + '.mustache');
let fn = helper[action].toString().replace(/\n/g, ' ').replace(/\{.*\}/gm, '{}');
try {
let docData = fs.readFileSync(filePath, 'utf-8');
let params = parser.parse(fn);
actions[action] = {params: params, actionDoc: docData};
} catch (err) {
debug('Error in fetching doc for file content', fn, err);
}
}
});
}
res.send({ actions });
};
11 changes: 8 additions & 3 deletions lib/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const { BrowserWindow, app } = require('electron');
const { BrowserWindow, app, shell } = require('electron');
const { getPort } = require('./config/env');

const NAME = 'CodeceptUI';
Expand All @@ -24,14 +24,14 @@ function createWindow() {
const x = screenWidth - Math.max(width, 500);
// Create the browser window.
win = new BrowserWindow({
width,
width: screenWidth / 1.2,
height: screenHeight,
minWidth: 500,
x,
y: 0,
title: NAME,
autoHideMenuBar: true,
icon: path.join(__dirname, '../build/icons/64x64.png'),
icon: path.join(__dirname, '/build/icons/64x64.png'),
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
Expand All @@ -46,6 +46,11 @@ function createWindow() {
win.on('closed', () => {
win = null;
});

win.webContents.setWindowOpenHandler(({ url }) => {
// open url in a browser and prevent default
shell.openExternal(url);
});
}

// Quit when all windows are closed.
Expand Down
Loading

0 comments on commit bb86601

Please sign in to comment.