Skip to content

Commit

Permalink
Adds arg alias
Browse files Browse the repository at this point in the history
  • Loading branch information
origami-z committed Feb 2, 2024
1 parent 2a5c6bb commit a7335d1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
29 changes: 23 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import {
migrateCssVar,
warnUnknownSaltThemeVars,
} from "./migration/utils.js";
import { latestSupportedVersion, parsedArgs } from "./utils/args.js";
import {
DEFAULT_FROM_VERSION,
LATEST_SUPPORTED_VERSION,
parsedArgs,
} from "./utils/args.js";
import { verboseOnlyDimLog } from "./utils/log.js";

const {
Expand All @@ -37,7 +41,7 @@ const {
verbose,
organizeImports,
dryRun,
only,
file: fileFilter,
mode,
from: fromInput,
to: toInput,
Expand All @@ -63,8 +67,8 @@ const v1150 = parse("1.15.0");
const v1160 = parse("1.16.0");
// NOTE: don't forget to modify `latestSupportedVersion`

const fromVersion = parse(fromInput) || parse("1.0.0");
const toVersion = parse(toInput) || parse(latestSupportedVersion);
const fromVersion = parse(fromInput) || parse(DEFAULT_FROM_VERSION);
const toVersion = parse(toInput) || parse(LATEST_SUPPORTED_VERSION);

console.log(
"Running codemod from version",
Expand All @@ -73,6 +77,10 @@ console.log(
chalk.bold(toVersion.format())
);

if (dryRun) {
console.log(chalk.bold("Dry run mode"));
}

// <-------- TS Code ---------->

if (mode === undefined || mode === "ts") {
Expand Down Expand Up @@ -109,7 +117,8 @@ if (mode === undefined || mode === "ts") {

for (const file of sourceFiles) {
const filePath = file.getFilePath();
if (only && !filePath.includes(only)) {
if (fileFilter && !filePath.includes(fileFilter)) {
verboseOnlyDimLog("Skipping file due to --file", filePath);
continue;
}

Expand Down Expand Up @@ -260,6 +269,10 @@ if (mode === undefined || mode === "css") {
const knownCssRenameCheckRegex = getCssRenameCheckRegex(cssMigrationMap);

for (const filePath of filePaths) {
if (fileFilter && !filePath.includes(fileFilter)) {
verboseOnlyDimLog("Skipping file due to --file", filePath);
continue;
}
verboseOnlyDimLog("Processing", filePath);

const originalContent = readFileSync(filePath, {
Expand Down Expand Up @@ -301,4 +314,8 @@ if (mode === undefined || mode === "css") {
console.log(chalk.dim("CSS variable migrations done."));
}

console.log("All done!");
if (dryRun) {
console.log("Dry run mode done!");
} else {
console.log("All done!");
}
23 changes: 16 additions & 7 deletions utils/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import _yargs from "yargs";
import { hideBin } from "yargs/helpers";
const yargs = _yargs(hideBin(process.argv));

export const latestSupportedVersion = "1.16.0";
export const LATEST_SUPPORTED_VERSION = "1.16.0";
export const DEFAULT_FROM_VERSION = "1.0.0";

export const parsedArgs = await yargs
.scriptName("salt-ts-morph")
.version(LATEST_SUPPORTED_VERSION)
.alias("version", "v")
.usage("$0 <cmd> [args]")
.option("tsconfig", {
default: "tsconfig.json",
Expand All @@ -30,24 +33,30 @@ export const parsedArgs = await yargs
})
.option("dryRun", {
type: "boolean",
alias: "n",
default: false,
description: "When set, no file change will be saved.",
description:
"When set, no file change will be saved but only logging to console.",
})
.option("only", {
.option("file", {
type: "string",
description:
"When set, only operate on the file matching name. Useful for debugging.",
"When set, only operate on the file matching name, after glob filtering. Useful for debugging.",
})
.option("mode", {
type: "string",
description: `Use this to operate only one sub-section of the codemod needed. i.e. "ts", "css". `,
})
.option("from", {
type: "string",
description: `Semver of @salt-ds/core package you're currently on`,
alias: "f",
default: DEFAULT_FROM_VERSION,
description: `Semver of @salt-ds/core package you're currently on.`,
})
.option("to", {
type: "string",
description: `Semver of @salt-ds/core package you're migrating to. Latest supported is ${latestSupportedVersion}`,
alias: "t",
description: `Semver of @salt-ds/core package you're migrating to. Latest supported is ${LATEST_SUPPORTED_VERSION}.`,
})
.help().argv;
.help()
.alias("help", "h").argv;

0 comments on commit a7335d1

Please sign in to comment.