Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,240 changes: 4,240 additions & 0 deletions .rehearsal/migrate-report.json

Large diffs are not rendered by default.

6,786 changes: 6,786 additions & 0 deletions .rehearsal/migrate-report.sarif

Large diffs are not rendered by default.

100 changes: 100 additions & 0 deletions .rehearsal/migrate-state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"name": "supported",
"packageMap": {
".": [
"./lib/util.js",
"./lib/time/index.js",
"./lib/output/messages.js",
"./lib/output/cli-output.js",
"./lib/output/csv-output.js",
"./lib/policy-rules.js",
"./lib/lts/index.js",
"./lib/project/index.js",
"./lib/project/multiple-projects.js",
"./lib/help.js",
"./lib/cli.js",
"./lib/npm/config.js",
"./lib/project/setup-project.js"
]
},
"files": {
"./lib/util.js": {
"origin": "./lib/util.js",
"current": "./lib/util.ts",
"package": ".",
"errorCount": 13
},
"./lib/time/index.js": {
"origin": "./lib/time/index.js",
"current": "./lib/time/index.ts",
"package": ".",
"errorCount": 24
},
"./lib/output/messages.js": {
"origin": "./lib/output/messages.js",
"current": "./lib/output/messages.ts",
"package": ".",
"errorCount": 7
},
"./lib/output/cli-output.js": {
"origin": "./lib/output/cli-output.js",
"current": "./lib/output/cli-output.ts",
"package": ".",
"errorCount": 60
},
"./lib/output/csv-output.js": {
"origin": "./lib/output/csv-output.js",
"current": "./lib/output/csv-output.ts",
"package": ".",
"errorCount": 11
},
"./lib/policy-rules.js": {
"origin": "./lib/policy-rules.js",
"current": "./lib/policy-rules.ts",
"package": ".",
"errorCount": 11
},
"./lib/lts/index.js": {
"origin": "./lib/lts/index.js",
"current": "./lib/lts/index.ts",
"package": ".",
"errorCount": 25
},
"./lib/project/index.js": {
"origin": "./lib/project/index.js",
"current": "./lib/project/index.ts",
"package": ".",
"errorCount": 20
},
"./lib/project/multiple-projects.js": {
"origin": "./lib/project/multiple-projects.js",
"current": "./lib/project/multiple-projects.ts",
"package": ".",
"errorCount": 12
},
"./lib/help.js": {
"origin": "./lib/help.js",
"current": "./lib/help.ts",
"package": ".",
"errorCount": 1
},
"./lib/cli.js": {
"origin": "./lib/cli.js",
"current": "./lib/cli.ts",
"package": ".",
"errorCount": 9
},
"./lib/npm/config.js": {
"origin": "./lib/npm/config.js",
"current": "./lib/npm/config.ts",
"package": ".",
"errorCount": 2
},
"./lib/project/setup-project.js": {
"origin": "./lib/project/setup-project.js",
"current": "./lib/project/setup-project.ts",
"package": ".",
"errorCount": 19
}
}
}
110 changes: 0 additions & 110 deletions lib/cli.js

This file was deleted.

137 changes: 137 additions & 0 deletions lib/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
'use strict';
//check for node version as first thing
/* @ts-expect-error @rehearsal TODO TS2305: Module '"../lib/util"' has no exported member 'handleInput'. */
import { checkNodeCompatibility, processDate, handleInput } from '../lib/util';
/* @ts-expect-error @rehearsal TODO TS2554: Expected 1 arguments, but got 0. */
checkNodeCompatibility();

// proceed iff the node version is good.
import ora from 'ora';
import fs from 'fs';
import { displayResults } from '../lib/output/cli-output';
import { processPolicies } from '../lib/project/multiple-projects';
/* @ts-expect-error @rehearsal TODO TS2305: Module '"./output/messages"' has no exported member 'DEFAULT_SUPPORT_MESSAGE'. */
import { DEFAULT_SUPPORT_MESSAGE } from './output/messages';
import { generateCsv } from '../lib/output/csv-output';

import meow, { AnyFlags, BooleanFlag, Options, Result, StringFlag } from 'meow';

interface MainConfig {
policyDetails: string;
setupProjectFn: () => void;
config: {};
}

type CliFlags = {
currentDate: StringFlag;
verbose: BooleanFlag;
json: BooleanFlag;
unsupported: BooleanFlag;
supported: BooleanFlag;
expiring: BooleanFlag;
configFile: StringFlag;
};

async function main(cli: Result<CliFlags>, { policyDetails, setupProjectFn, config }: MainConfig): Promise<void> {
const projectPaths = handleInput(cli.input, process.cwd());

if (projectPaths.length === 0) {
cli.showHelp(1);
} else {
const currentDate = processDate(cli.flags.currentDate as string) || undefined;

const configuration =
(cli.flags.configFile && JSON.parse(fs.readFileSync(cli.flags.configFile as string, 'utf-8'))) ||
config;

const spinner = ora('working').start();
let result;
let processed = false;
try {
result = await processPolicies(
projectPaths,
setupProjectFn,
spinner,
currentDate,
configuration,
);
if (result.isInSupportWindow === false) {
process.exitCode = 1;
}
processed = true;
} finally {
if (processed) {
spinner.stopAndPersist({
symbol: '✨',
});
} else {
/* @ts-expect-error @rehearsal TODO TS2554: Expected 0 arguments, but got 1. */
spinner.stop({
symbol: '✨',
});
}
}

if (cli.flags.json && result) {
console.log(JSON.stringify(result, null, 2));
} else if (cli.flags.csv && result) {
/* @ts-expect-error @rehearsal TODO TS2345: Argument of type '{0}' is not assignable to parameter of type 'projects: { projectName: unknown; projectPath: PathLike'. Consider verifying both types, using type assertion: '( result as string)', or using type guard: 'if ( result instanceof string) { ... }'. */
generateCsv(projectPaths, result, policyDetails);
} else {
displayResults(result, cli.flags, policyDetails);
}
}
}

/**
*
* @param {string} policyDetails Custom message that needs to be passed regarding the support audit run
* @param {*} setupProjectFn if the way project is setup is different then use this method to override.
*/
module.exports = run;
async function run(
policyDetails = DEFAULT_SUPPORT_MESSAGE(),
/* @ts-expect-error @rehearsal TODO TS7006: Parameter 'setupProjectFn' implicitly has an 'any' type. */
setupProjectFn,
help = require('./help')(),
/* @ts-expect-error @rehearsal TODO TS7006: Parameter 'config' implicitly has an 'any' type. */
config,
): Promise<void> {
const meowOptions: Options<CliFlags> = {
importMeta: import.meta,
flags: {
verbose: {
type: 'boolean',
alias: 'd',
},
json: {
type: 'boolean',
alias: 'j',
},
unsupported: {
type: 'boolean',
alias: 'u',
},
supported: {
type: 'boolean',
alias: 's',
},
expiring: {
type: 'boolean',
alias: 'e',
},
currentDate: {
type: 'string',
alias: 'c',
},
configFile: {
type: 'string',
alias: 'f',
},
},
};
await main(
meow(help, meowOptions),
{ policyDetails, setupProjectFn, config },
);
}
7 changes: 4 additions & 3 deletions lib/help.js → lib/help.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

const chalk = require('chalk');
const terminalLink = require('terminal-link');
const pkg = require('../package.json');
import chalk from 'chalk';
import terminalLink from 'terminal-link';
/* @ts-expect-error @rehearsal TODO TS2732: Cannot find module '../package.json'. Consider using '--resolveJsonModule' to import module with '.json' extension. */
import pkg from '../package.json';

module.exports = (commandName = 'supported', packageLink = pkg.homepage) => {
return chalk`
Expand Down
Loading