Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a8b9d5e
:tada: Support ext
KenAJoh Nov 27, 2025
e7ff5b9
:zap: Optimize file indexing
KenAJoh Nov 27, 2025
7f74176
:zap: Optimize file-indexing
KenAJoh Nov 27, 2025
b455df1
:zap: Optimize regex creation
KenAJoh Nov 27, 2025
ff01ecb
:bug: Optimize indexing, add js and some tailwind-support
KenAJoh Nov 27, 2025
68194e2
:zap: Optimize tailwind codemod
KenAJoh Nov 27, 2025
ef094ce
:test_tube: More tests
KenAJoh Nov 27, 2025
fd0f2e0
:zap: Optimize css codemod
KenAJoh Nov 27, 2025
3c35331
:memo: Better status reports
KenAJoh Nov 27, 2025
80646d3
:memo: Better printouts
KenAJoh Nov 27, 2025
fc1ad30
:memo: Improve printouts
KenAJoh Nov 27, 2025
b7ccfca
:zap: Avoid re-running status-update
KenAJoh Nov 27, 2025
6f37bb5
:memo: Update summary
KenAJoh Nov 27, 2025
c0ae927
:fire: Removed waitfor keypress
KenAJoh Nov 27, 2025
a7fafcb
:memo: Changeset
KenAJoh Nov 27, 2025
3088ead
:recycle: Avoid inline assignment
KenAJoh Nov 27, 2025
d92febc
:memo: Added comments
KenAJoh Nov 28, 2025
2a210dd
:recycle: Small refactor, extracting complexity into functions
KenAJoh Nov 28, 2025
852158d
:fire: Removed commented code
KenAJoh Nov 28, 2025
ede3229
Update @navikt/aksel/src/codemod/run-codeshift.ts
KenAJoh Dec 2, 2025
ec9989b
Update @navikt/aksel/src/codemod/run-codeshift.ts
KenAJoh Dec 2, 2025
3896e6c
:recycle: No array for glob-list
KenAJoh Dec 2, 2025
cec98b1
:recycle: getWordPositionInFile -> getCharacterPositionInFile
KenAJoh Dec 2, 2025
c1b43f1
:recycle: Only comment once for grouped tokens
KenAJoh Dec 2, 2025
65b1d9c
:zap: Always update status on print
KenAJoh Dec 2, 2025
ab36f8b
Revert ":zap: Always update status on print"
KenAJoh Dec 2, 2025
719be1f
:zap: Always update status on print
KenAJoh Dec 2, 2025
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
5 changes: 5 additions & 0 deletions .changeset/legal-hands-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/aksel": patch
---

CLI: Improvements to v8-tokens codemod.
1 change: 1 addition & 0 deletions @navikt/aksel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"axios": "1.13.2",
"chalk": "4.1.0",
"cli-progress": "^3.12.0",
"clipboardy": "^2.3.0",
"commander": "10.0.1",
"enquirer": "^2.3.6",
"fast-glob": "3.2.11",
Expand Down
11 changes: 10 additions & 1 deletion @navikt/aksel/src/codemod/codeshift.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ type SupportedCodemodExtensions =
*/
function getDefaultGlob(ext: string): string {
const defaultExt = "js,ts,jsx,tsx,css,scss,less";
const extensions = cleanExtensions(ext ?? defaultExt);

return `**/*.{${cleanExtensions(ext ?? defaultExt).join(",")}}`;
/**
* Single-item braces are treated as a literal string by some globbing libraries,
* so we only use them when there are multiple extensions
*/
if (extensions.length > 1) {
return `**/*.{${extensions.join(",")}}`;
}

return `**/*.${extensions[0]}`;
}

/**
Expand Down
26 changes: 21 additions & 5 deletions @navikt/aksel/src/codemod/run-codeshift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,31 @@ export async function runCodeshift(
`./transforms/${getMigrationPath(input)}.js`,
);

const filepaths = fg.sync([options.glob ?? getDefaultGlob(options?.ext)], {
console.info(chalk.greenBright.bold("\nWelcome to Aksel codemods!"));
console.info("\nRunning migration:", chalk.green(input));

const globList = options.glob ?? getDefaultGlob(options?.ext);

console.info(
chalk.gray(
`Using glob pattern(s): ${globList}\nWorking directory: ${process.cwd()}\n`,
),
);

const filepaths = fg.sync(globList, {
cwd: process.cwd(),
ignore: GLOB_IGNORE_PATTERNS,
/**
* When globbing, do not follow symlinks to avoid processing files outside the directory.
* This is most likely to happen in monorepos where node_modules may contain symlinks to packages
* in other parts of the repo.
*
* While node_modules is already ignored via GLOB_IGNORE_PATTERNS, if user globs upwards (e.g., using '../src/**'),
* that ignore-pattern may be ignored, leading to unintended file processing.
*/
followSymbolicLinks: false,
});

console.info("\nRunning migration:", chalk.green("input"));

options?.glob && console.info(`Using glob: ${chalk.green(options.glob)}\n`);

const warning = getWarning(input);

const unsafeExtensions = getIgnoredFileExtensions(input);
Expand Down
16 changes: 6 additions & 10 deletions @navikt/aksel/src/darkside/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import chalk from "chalk";
import { Command } from "commander";
import { validateGit } from "../codemod/validation.js";
// import figlet from "figlet";
// import { getMigrationString } from "./migrations.js";
import { runTooling } from "./run-tooling.js";

const program = new Command();

export function darksideCommand() {
program.name(`${chalk.blueBright(`npx @navikt/aksel`)}`);
program.name(`${chalk.blueBright(`npx @navikt/aksel v8-tokens`)}`);

program
.option(
"-g, --glob [glob]",
"Globbing pattern, overrides --ext! Run with 'noglob' if using zsh-terminal. ",
)
.option(
"-e, --ext [ext]",
"File extensions to include, defaults to 'js,ts,jsx,tsx,css,scss,less'",
)
.option("-d, --dry-run", "Dry run, no changes will be made")
.option("-f, --force", "Forcibly run updates without checking git-changes")
.description("Update tool for darkside token updates");
.description("Update tool for v8 token updates");

program.parse();
const options = program.opts();

/* Makes sure that you don't migrate lots of files while having other uncommitted changes */
if (!options.force) {
validateGit(options, program);
}

runTooling(options as Parameters<typeof runTooling>["0"], program);
}
Loading