Skip to content

Commit

Permalink
Migrate project to TypeScript and update configurations
Browse files Browse the repository at this point in the history
This commit updates the file extensions and contents of multiple files across the project from JavaScript to TypeScript for better type checking and autocompletion. Additionally, the ESLint configuration file was converted from .js to .json format, and tsconfig.json was updated to remove "allowJs" and "checkJs" properties. Lastly, imports in files were converted to ES6 syntax.

Took 19 minutes
  • Loading branch information
erikyo committed Dec 11, 2023
1 parent 3812584 commit 40e3b55
Show file tree
Hide file tree
Showing 12 changed files with 619 additions and 1,485 deletions.
20 changes: 0 additions & 20 deletions .eslintrc.js

This file was deleted.

22 changes: 22 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"env": {
"browser": true,
"node": true,
"es2021": true,
"jest": true
},
"extends": ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
"parser": '@typescript-eslint/parser',
"plugins": ['@typescript-eslint'],
"extends": [
'eslint:recommended',
'plugin:@typescript-eslint/recommended'
],
"overrides": [],
'rules': {}
}
65 changes: 49 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
Expand All @@ -7,11 +31,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const core = require('@actions/core');
const exec = require('@actions/exec');
const fs = require('fs').promises;
const path = require('path');
const installer = require('./installer');
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const installer_1 = __importDefault(require("./installer"));
/**
* Runs the documentation generation process.
* @async
* @return {void}
*/
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
Expand Down Expand Up @@ -49,8 +82,8 @@ function run() {
const stripYamlFrontmatter = core.getInput('stripYamlFrontmatter');
if (source_dir) {
try {
const srcPath = path.join(GITHUB_WORKSPACE, source_dir);
yield fs.access(srcPath);
const srcPath = path_1.default.join(GITHUB_WORKSPACE, source_dir);
yield fs_1.default.promises.access(srcPath);
}
catch (error) {
core.setFailed('⛔️ Source directory does not exist');
Expand All @@ -59,38 +92,38 @@ function run() {
}
if (config_file) {
try {
const configPath = path.join(GITHUB_WORKSPACE, config_file);
yield fs.access(configPath);
const configPath = path_1.default.join(GITHUB_WORKSPACE, config_file);
yield fs_1.default.promises.access(configPath);
}
catch (error) {
core.setFailed('⛔️ Config file does not exist');
return;
}
}
if (theme) {
templateName = yield installer.installTemplate(theme);
templateName = yield (0, installer_1.default)(theme);
}
const typedocPath = path.join(__dirname, '../node_modules/typedoc/bin/typedoc');
const typedocPath = path_1.default.join(__dirname, '../node_modules/typedoc/bin/typedoc');
const cmd = 'node';
const args = [typedocPath];
if (source_dir) {
args.push(source_dir);
}
if (output_dir) {
args.push('--out', path.join(GITHUB_WORKSPACE, output_dir));
args.push('--out', path_1.default.join(GITHUB_WORKSPACE, output_dir));
}
if (config_file) {
const configPath = path.join(GITHUB_WORKSPACE, config_file);
const configPath = path_1.default.join(GITHUB_WORKSPACE, config_file);
args.push('--tsconfig', configPath);
}
if (theme) {
args.push('--theme', theme);
}
if (template_dir) {
args.push('--template_dir', path.join(GITHUB_WORKSPACE, '../node_modules/', templateName, template_dir));
args.push('--template_dir', path_1.default.join(GITHUB_WORKSPACE, '../node_modules/', templateName, template_dir));
}
if (front_page) {
const readmePath = path.join(GITHUB_WORKSPACE, front_page);
const readmePath = path_1.default.join(GITHUB_WORKSPACE, front_page);
args.push('--readme', readmePath);
}
if (core.getInput('lightHighlightTheme')) {
Expand All @@ -100,7 +133,7 @@ function run() {
args.push('--darkHighlightTheme', core.getInput('darkHighlightTheme'));
}
if (core.getInput('customCss')) {
args.push('--customCss', path.join(GITHUB_WORKSPACE, core.getInput('customCss')));
args.push('--customCss', path_1.default.join(GITHUB_WORKSPACE, core.getInput('customCss')));
}
if (core.getInput('markedOptions')) {
args.push('--markedOptions', core.getInput('markedOptions'));
Expand Down
54 changes: 41 additions & 13 deletions lib/installer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
Expand All @@ -7,11 +31,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const core = require('@actions/core');
const exec = require('@actions/exec');
const fs = require('fs');
const path = require('path');
const utils = require('./utils');
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec"));
const path_1 = __importDefault(require("path"));
const utils_1 = __importDefault(require("./utils"));
/**
* Installs a TSDoc template or theme by executing `npm install template/theme --production`.
* The template/theme needs to be a JavaScript package.
Expand All @@ -22,14 +49,17 @@ const utils = require('./utils');
function installTemplate(template) {
return __awaiter(this, void 0, void 0, function* () {
let templateName = '';
const actionDir = path.join(__dirname, '../');
const actionDir = path_1.default.join(__dirname, '../');
core.debug(`actionDir: ${actionDir}`);
const cmd = 'npm';
const args = ['install', template, '--production'];
core.info(`Installing TSDoc template/theme: ${template}`);
core.debug(`Command: ${cmd} ${args}`);
const options = {};
options.cwd = actionDir;
const options = {
cwd: actionDir,
options: {},
listeners: {}
};
yield exec.exec(cmd, args, options);
let lsOutput = '';
let lsError = '';
Expand All @@ -46,11 +76,9 @@ function installTemplate(template) {
if (lsError)
core.info(`Error: ${lsError}`);
const packageLocation = lsOutput.trim(); // path/to/template
const filePath = path.join(packageLocation + '/package.json');
templateName = yield utils.getPackageName(filePath);
const filePath = path_1.default.join(packageLocation + '/package.json');
templateName = yield (0, utils_1.default)(filePath);
return templateName;
});
}
module.exports = {
installTemplate
};
exports.default = installTemplate;
47 changes: 40 additions & 7 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
Expand All @@ -7,13 +31,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const core = require('@actions/core');
const fs = require('fs');
const util = require('util');
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const fs_1 = __importDefault(require("fs"));
const util_1 = __importDefault(require("util"));
/**
* Retrieves the package name from a package.json file.
*
* @param {string} filePath - The path to the package.json file.
* @returns {Promise<string>} - The package name.
*
*/
function getPackageName(filePath) {
return __awaiter(this, void 0, void 0, function* () {
let name = '';
const readFile = util.promisify(fs.readFile);
const readFile = util_1.default.promisify(fs_1.default.readFile);
const fileContents = yield readFile(filePath, 'utf8');
try {
const data = JSON.parse(fileContents);
Expand All @@ -25,6 +60,4 @@ function getPackageName(filePath) {
return name;
});
}
module.exports = {
getPackageName
};
exports.default = getPackageName;
Loading

0 comments on commit 40e3b55

Please sign in to comment.