@navikt/aksel 7.17.2 → 7.17.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/codemod/codeshift.utils.js +30 -0
  2. package/dist/codemod/migrations.js +9 -12
  3. package/dist/codemod/run-codeshift.js +3 -17
  4. package/dist/codemod/transforms/darkside/prop-deprecate/prop-deprecate.js +32 -0
  5. package/dist/codemod/transforms/{darkside → spacing}/primitives-spacing/spacing.js +7 -6
  6. package/dist/codemod/transforms/spacing/spacing.utils.js +34 -0
  7. package/dist/codemod/transforms/{darkside → spacing}/token-spacing/spacing.js +2 -2
  8. package/dist/codemod/transforms/{darkside → spacing}/token-spacing-js/spacing.js +4 -3
  9. package/dist/codemod/transforms/v2.0.0/update-js-tokens/update-js-tokens.js +1 -1
  10. package/dist/codemod/{transforms/darkside/darkside.utils.js → utils/ast.js} +0 -32
  11. package/dist/darkside/config/TokenStatus.js +145 -0
  12. package/dist/darkside/config/darkside.tokens.js +398 -0
  13. package/dist/darkside/config/legacy-component.tokens.js +407 -0
  14. package/dist/{codemod/transforms/darkside/darkside.tokens.js → darkside/config/legacy.tokens.js} +390 -796
  15. package/dist/darkside/config/token-regex.js +52 -0
  16. package/dist/darkside/config/token.utils.js +57 -0
  17. package/dist/darkside/index.js +28 -0
  18. package/dist/darkside/run-tooling.js +220 -0
  19. package/dist/darkside/tasks/print-remaining.js +51 -0
  20. package/dist/darkside/tasks/status.js +122 -0
  21. package/dist/darkside/transforms/darkside-tokens-css.js +17 -0
  22. package/dist/darkside/transforms/darkside-tokens-js.js +51 -0
  23. package/dist/darkside/transforms/darkside-tokens-less.js +14 -0
  24. package/dist/darkside/transforms/darkside-tokens-scss.js +14 -0
  25. package/dist/darkside/transforms/darkside-tokens-tailwind.js +33 -0
  26. package/dist/help.js +5 -0
  27. package/dist/index.js +5 -0
  28. package/package.json +5 -2
  29. package/dist/codemod/transforms/darkside/darkside.test.js +0 -20
  30. package/dist/codemod/transforms/darkside/token-update/token-update.js +0 -110
  31. package/dist/codemod/transforms/darkside/token-update-js/token-update-js.js +0 -96
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCompositeTwRegex = createCompositeTwRegex;
4
+ exports.createSingleTwRegex = createSingleTwRegex;
5
+ exports.getFrameworkRegexes = getFrameworkRegexes;
6
+ exports.getTokenRegex = getTokenRegex;
7
+ const translate_token_1 = require("../../codemod/utils/translate-token");
8
+ const createTwRegexForBreakpoints = (token) => new RegExp(`(?<!:)(?<=\\s|^)${token}:(?=\\w)`, "gm");
9
+ function getFrameworkRegexes({ token, twString, legacy = false, }) {
10
+ const regexes = {
11
+ css: getTokenRegex(token, "css"),
12
+ scss: getTokenRegex(token, "scss"),
13
+ less: getTokenRegex(token, "less"),
14
+ /* New JS tokens dont have a prefix */
15
+ js: legacy
16
+ ? getTokenRegex(token, "js")
17
+ : getTokenRegex(token.replace("--ax-", ""), "js"),
18
+ tailwind: null,
19
+ };
20
+ if (!twString) {
21
+ return regexes;
22
+ }
23
+ const twTokens = twString.split(",");
24
+ if (token.includes("breakpoint")) {
25
+ /* We assume that breakpoint tw token only has a single declaration */
26
+ regexes.tailwind = createTwRegexForBreakpoints(twTokens[0]);
27
+ }
28
+ else {
29
+ regexes.tailwind = createCompositeTwRegex(twTokens);
30
+ }
31
+ return regexes;
32
+ }
33
+ function getTokenRegex(variable, format) {
34
+ switch (format) {
35
+ case "css":
36
+ return new RegExp(`(\\s|^)?(${variable})(?=\\s|$|[^\\w-])`, "gm");
37
+ case "scss":
38
+ return new RegExp(`(\\s|^)?(\\${(0, translate_token_1.translateToken)(variable, "scss")})(?=\\s|$|[^\\w-])`, "gm");
39
+ case "less":
40
+ return new RegExp(`(\\s|^)?(${(0, translate_token_1.translateToken)(variable, "less")})(?=\\s|$|[^\\w-])`, "gm");
41
+ case "js":
42
+ return new RegExp(`(\\s|^)?(${(0, translate_token_1.translateToken)(variable, "js")})(?=\\s|$|[^\\w-])`, "gm");
43
+ }
44
+ }
45
+ function createCompositeTwRegex(tokens) {
46
+ return new RegExp(`(?<!:)(\\s|^)?(${tokens.join("|")}|${tokens
47
+ .map((t) => `:${t}`)
48
+ .join("|")})(?=\\s|$|[^\\w-])`, "gm");
49
+ }
50
+ function createSingleTwRegex(token) {
51
+ return new RegExp(`(?<!:)(\\s|^)?(${token})(?=\\s|$|[^\\w-])`, "gm");
52
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateRoundedTwTags = generateRoundedTwTags;
4
+ exports.generateBgTwTags = generateBgTwTags;
5
+ function generateRoundedTwTags(name, addNewPrefix = false) {
6
+ const options = [
7
+ "s",
8
+ "e",
9
+ "t",
10
+ "r",
11
+ "b",
12
+ "l",
13
+ "ss",
14
+ "se",
15
+ "ee",
16
+ "es",
17
+ "tl",
18
+ "tr",
19
+ "br",
20
+ "bl",
21
+ ];
22
+ return `rounded-${name},${options
23
+ .map((option) => `rounded-${option}-${addNewPrefix ? "ax-" : ""}${name}`)
24
+ .join(",")}`;
25
+ }
26
+ function generateBgTwTags(name, addNewPrefix = false) {
27
+ const options = [
28
+ "bg",
29
+ "to",
30
+ "via",
31
+ "from",
32
+ "fill",
33
+ "text",
34
+ "caret",
35
+ "ring",
36
+ "divide",
37
+ "border",
38
+ "stroke",
39
+ "accent",
40
+ "shadow",
41
+ "outline",
42
+ "border-x",
43
+ "border-y",
44
+ "border-s",
45
+ "border-e",
46
+ "border-t",
47
+ "border-r",
48
+ "border-b",
49
+ "border-l",
50
+ "decoration",
51
+ "placeholder",
52
+ "ring-offset",
53
+ ];
54
+ return `${options
55
+ .map((option) => `${option}-${addNewPrefix ? "ax-" : ""}${name}`)
56
+ .join(",")}`;
57
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.darksideCommand = darksideCommand;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const commander_1 = require("commander");
9
+ const validation_js_1 = require("../codemod/validation.js");
10
+ // import figlet from "figlet";
11
+ // import { getMigrationString } from "./migrations.js";
12
+ const run_tooling_js_1 = require("./run-tooling.js");
13
+ const program = new commander_1.Command();
14
+ function darksideCommand() {
15
+ program.name(`${chalk_1.default.blueBright(`npx @navikt/aksel`)}`);
16
+ program
17
+ .option("-g, --glob [glob]", "Globbing pattern, overrides --ext! Run with 'noglob' if using zsh-terminal. ")
18
+ .option("-d, --dry-run", "Dry run, no changes will be made")
19
+ .option("-f, --force", "Forcibly run updates without checking git-changes")
20
+ .description("Update tool for darkside token updates");
21
+ program.parse();
22
+ const options = program.opts();
23
+ /* Makes sure that you don't migrate lots of files while having other uncommitted changes */
24
+ if (!options.force) {
25
+ (0, validation_js_1.validateGit)(options, program);
26
+ }
27
+ (0, run_tooling_js_1.runTooling)(options, program);
28
+ }
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.runTooling = runTooling;
39
+ const chalk_1 = __importDefault(require("chalk"));
40
+ const enquirer_1 = __importDefault(require("enquirer"));
41
+ const fast_glob_1 = __importDefault(require("fast-glob"));
42
+ const jscodeshift = __importStar(require("jscodeshift/src/Runner"));
43
+ const path_1 = __importDefault(require("path"));
44
+ const codeshift_utils_1 = require("../codemod/codeshift.utils");
45
+ const validation_1 = require("../codemod/validation");
46
+ const print_remaining_1 = require("./tasks/print-remaining");
47
+ const status_1 = require("./tasks/status");
48
+ // Constants
49
+ const TRANSFORMS = {
50
+ "css-tokens": "./transforms/darkside-tokens-css",
51
+ "scss-tokens": "./transforms/darkside-tokens-scss",
52
+ "less-tokens": "./transforms/darkside-tokens-less",
53
+ "js-tokens": "./transforms/darkside-tokens-js",
54
+ "tailwind-tokens": "./transforms/darkside-tokens-tailwind",
55
+ };
56
+ const TASK_MENU = {
57
+ type: "select",
58
+ name: "task",
59
+ message: "Task",
60
+ initial: "status",
61
+ choices: [
62
+ { message: "Check status", name: "status" },
63
+ { message: "Print remaining tokens", name: "print-remaining-tokens" },
64
+ { message: "Migrate CSS tokens", name: "css-tokens" },
65
+ { message: "Migrate Scss tokens", name: "scss-tokens" },
66
+ { message: "Migrate Less tokens", name: "less-tokens" },
67
+ { message: "Migrate JS tokens", name: "js-tokens" },
68
+ { message: "Migrate tailwind tokens", name: "tailwind-tokens" },
69
+ { message: "Run all migrations", name: "run-all-migrations" },
70
+ { message: "Exit", name: "exit" },
71
+ ],
72
+ };
73
+ /**
74
+ * Main entry point for the tooling system
75
+ */
76
+ function runTooling(options, program) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ var _a;
79
+ // Find matching files based on glob pattern
80
+ const filepaths = fast_glob_1.default.sync([(_a = options.glob) !== null && _a !== void 0 ? _a : (0, codeshift_utils_1.getDefaultGlob)(options === null || options === void 0 ? void 0 : options.ext)], {
81
+ cwd: process.cwd(),
82
+ ignore: codeshift_utils_1.GLOB_IGNORE_PATTERNS,
83
+ });
84
+ if (options.dryRun) {
85
+ console.info(chalk_1.default.yellow("Running in dry-run mode, no changes will be made"));
86
+ }
87
+ // Show initial status
88
+ (0, status_1.getStatus)(filepaths);
89
+ // Task execution loop
90
+ let task;
91
+ while ((task = yield getNextTask()) !== "exit") {
92
+ console.info("\n\n");
93
+ try {
94
+ yield executeTask(task, filepaths, options, program);
95
+ }
96
+ catch (error) {
97
+ program.error(chalk_1.default.red("Error:", error.message));
98
+ }
99
+ }
100
+ process.exit(0);
101
+ });
102
+ }
103
+ /**
104
+ * Executes the selected task
105
+ */
106
+ function executeTask(task, filepaths, options, program) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ switch (task) {
109
+ case "status":
110
+ (0, status_1.getStatus)(filepaths);
111
+ break;
112
+ case "print-remaining-tokens":
113
+ (0, print_remaining_1.printRemaining)(filepaths);
114
+ break;
115
+ case "css-tokens":
116
+ case "scss-tokens":
117
+ case "less-tokens":
118
+ case "js-tokens":
119
+ case "tailwind-tokens": {
120
+ const updatedStatus = (0, status_1.getStatus)(filepaths, "no-print").status;
121
+ const scopedFiles = getScopedFilesForTask(task, filepaths, updatedStatus);
122
+ yield runCodeshift(task, scopedFiles, {
123
+ dryRun: options.dryRun,
124
+ force: options.force,
125
+ });
126
+ break;
127
+ }
128
+ case "run-all-migrations": {
129
+ const tasks = [
130
+ "css-tokens",
131
+ "scss-tokens",
132
+ "less-tokens",
133
+ "js-tokens",
134
+ "tailwind-tokens",
135
+ ];
136
+ for (const migrationTask of tasks) {
137
+ if (!options.force) {
138
+ (0, validation_1.validateGit)(options, program);
139
+ }
140
+ console.info(`\nRunning ${migrationTask}...`);
141
+ yield runCodeshift(migrationTask, filepaths, {
142
+ dryRun: options.dryRun,
143
+ force: true,
144
+ });
145
+ }
146
+ break;
147
+ }
148
+ default:
149
+ program.error(chalk_1.default.red(`Unknown task: ${task}`));
150
+ }
151
+ });
152
+ }
153
+ /**
154
+ * Filter files based on the selected task
155
+ */
156
+ function getScopedFilesForTask(task, filepaths, status) {
157
+ return filepaths.filter((f) => {
158
+ switch (task) {
159
+ case "css-tokens":
160
+ return !!status.css.legacy.find((config) => config.fileName === f);
161
+ case "scss-tokens":
162
+ return !!status.scss.legacy.find((config) => config.fileName === f);
163
+ case "less-tokens":
164
+ return !!status.less.legacy.find((config) => config.fileName === f);
165
+ case "js-tokens":
166
+ return !!status.js.legacy.find((config) => config.fileName === f);
167
+ case "tailwind-tokens":
168
+ return !!status.tailwind.legacy.find((config) => config.fileName === f);
169
+ default:
170
+ return false;
171
+ }
172
+ });
173
+ }
174
+ /**
175
+ * Runs the jscodeshift codemod for the selected task
176
+ */
177
+ function runCodeshift(task, filepaths, options) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ if (!TRANSFORMS[task]) {
180
+ throw new Error(`No transform found for task: ${task}`);
181
+ }
182
+ const codemodPath = path_1.default.join(__dirname, `${TRANSFORMS[task]}.js`);
183
+ yield jscodeshift.run(codemodPath, filepaths, {
184
+ babel: true,
185
+ ignorePattern: codeshift_utils_1.GLOB_IGNORE_PATTERNS,
186
+ extensions: "tsx,ts,jsx,js",
187
+ parser: "tsx",
188
+ verbose: 2,
189
+ runInBand: true,
190
+ silent: false,
191
+ stdin: false,
192
+ dry: options === null || options === void 0 ? void 0 : options.dryRun,
193
+ force: options === null || options === void 0 ? void 0 : options.force,
194
+ print: false,
195
+ });
196
+ });
197
+ }
198
+ /**
199
+ * Prompts the user for the next task to run
200
+ */
201
+ function getNextTask() {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ try {
204
+ const response = yield enquirer_1.default.prompt([
205
+ Object.assign(Object.assign({}, TASK_MENU), { onCancel: () => process.exit(1) }),
206
+ ]);
207
+ return response.task;
208
+ }
209
+ catch (error) {
210
+ if (error.isTtyError) {
211
+ console.info("Oops, something went wrong! Looks like @navikt/aksel can't run in this terminal. " +
212
+ "Contact Aksel for support if this persists, or try another terminal.");
213
+ }
214
+ else {
215
+ console.error(error);
216
+ }
217
+ process.exit(1);
218
+ }
219
+ });
220
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.printRemaining = printRemaining;
7
+ const path_1 = __importDefault(require("path"));
8
+ const status_1 = require("./status");
9
+ function printRemaining(files) {
10
+ process.stdout.write("\nAnalyzing...");
11
+ const statusObj = (0, status_1.getStatus)(files, "no-print").status;
12
+ Object.entries(statusObj).forEach(([tokenType, data]) => {
13
+ console.group(`\n${tokenType.toUpperCase()}:`);
14
+ const fileLinks = [];
15
+ data.legacy.forEach((tokenData) => {
16
+ fileLinks.push(`${tokenData.name.replace(":", "")}:${tokenData.fileName}:${tokenData.lineNumber}:${tokenData.columnNumber}`);
17
+ });
18
+ if (fileLinks.length === 0) {
19
+ console.info("Nothing to update.");
20
+ console.groupEnd();
21
+ }
22
+ // Ensure every string is unique
23
+ const uniqueFileLinks = Array.from(new Set(fileLinks));
24
+ // Sort the unique fileLinks based on fileName first, lineNumber second, and columnNumber third
25
+ uniqueFileLinks.sort((a, b) => {
26
+ const [fileA, lineA, columnA] = a.split(":");
27
+ const [fileB, lineB, columnB] = b.split(":");
28
+ if (fileA !== fileB) {
29
+ return fileA.localeCompare(fileB);
30
+ }
31
+ if (Number(lineA) !== Number(lineB)) {
32
+ return Number(lineA) - Number(lineB);
33
+ }
34
+ return Number(columnA) - Number(columnB);
35
+ });
36
+ // Print the unique and sorted fileLinks as clickable links with full path
37
+ uniqueFileLinks.forEach((link) => {
38
+ const [tokenName, fileName, lineNumber, columnNumber] = link.split(":");
39
+ const fullPath = path_1.default.resolve(process.cwd(), fileName);
40
+ const withComment = data.legacy.find((token) => {
41
+ return token.name === tokenName && token.comment;
42
+ });
43
+ if (withComment) {
44
+ console.info(`\n/* ${withComment.comment} */`);
45
+ }
46
+ console.info(`${tokenName}: file://${fullPath}:${lineNumber}:${columnNumber}`);
47
+ });
48
+ console.groupEnd();
49
+ });
50
+ console.info("\n");
51
+ }
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getStatus = getStatus;
7
+ const cli_progress_1 = __importDefault(require("cli-progress"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const TokenStatus_1 = require("../config/TokenStatus");
10
+ const darkside_tokens_1 = require("../config/darkside.tokens");
11
+ const legacy_component_tokens_1 = require("../config/legacy-component.tokens");
12
+ const legacy_tokens_1 = require("../config/legacy.tokens");
13
+ const token_regex_1 = require("../config/token-regex");
14
+ const StatusStore = new TokenStatus_1.TokenStatus();
15
+ /**
16
+ * Get the status of the tokens in the files
17
+ */
18
+ function getStatus(files, action = "print") {
19
+ const progressBar = new cli_progress_1.default.SingleBar({
20
+ clearOnComplete: true,
21
+ hideCursor: true,
22
+ format: "{bar} | {value}/{total} | {fileName}",
23
+ }, cli_progress_1.default.Presets.shades_classic);
24
+ if (action === "print") {
25
+ progressBar.start(files.length, 0);
26
+ }
27
+ StatusStore.initStatus();
28
+ files.forEach((fileName, index) => {
29
+ const fileSrc = fs_1.default.readFileSync(fileName, "utf8");
30
+ /**
31
+ * We first parse trough all legacy tokens (--a-) prefixed tokens
32
+ */
33
+ for (const [legacyToken, config] of Object.entries(legacy_tokens_1.legacyTokenConfig)) {
34
+ if (!(0, token_regex_1.getTokenRegex)(legacyToken, "css").test(fileSrc)) {
35
+ continue;
36
+ }
37
+ for (const [regexKey, regex] of Object.entries(config.regexes)) {
38
+ if (!regex) {
39
+ continue;
40
+ }
41
+ let match;
42
+ while ((match = regex.exec(fileSrc))) {
43
+ const { row, column } = getWordPositionInFile(fileSrc, match.index);
44
+ StatusStore.add({
45
+ isLegacy: true,
46
+ comment: config.comment,
47
+ type: regexKey,
48
+ columnNumber: column,
49
+ lineNumber: row,
50
+ canAutoMigrate: regexKey === "tailwind"
51
+ ? !!config.twNew
52
+ : config.replacement.length > 0,
53
+ fileName,
54
+ name: match[0],
55
+ });
56
+ }
57
+ }
58
+ }
59
+ const legacyRegex = new RegExp(`(${legacy_component_tokens_1.legacyComponentTokenList.map((t) => `${t}:`).join("|")})`, "gm");
60
+ let legacyMatch;
61
+ while ((legacyMatch = legacyRegex.exec(fileSrc)) !== null) {
62
+ const { row, column } = getWordPositionInFile(fileSrc, legacyMatch.index);
63
+ StatusStore.add({
64
+ isLegacy: true,
65
+ type: "component",
66
+ columnNumber: column,
67
+ lineNumber: row,
68
+ canAutoMigrate: false,
69
+ fileName,
70
+ name: legacyMatch[0],
71
+ });
72
+ }
73
+ for (const [newTokenName, config] of Object.entries(darkside_tokens_1.darksideTokenConfig)) {
74
+ if (!(0, token_regex_1.getTokenRegex)(newTokenName, "css").test(fileSrc)) {
75
+ continue;
76
+ }
77
+ for (const [regexKey, regex] of Object.entries(config.regexes)) {
78
+ if (!regex) {
79
+ continue;
80
+ }
81
+ let match;
82
+ while ((match = regex.exec(fileSrc))) {
83
+ const { row, column } = getWordPositionInFile(fileSrc, match.index);
84
+ StatusStore.add({
85
+ isLegacy: false,
86
+ type: regexKey,
87
+ columnNumber: column,
88
+ lineNumber: row,
89
+ fileName,
90
+ name: match[0],
91
+ });
92
+ }
93
+ }
94
+ }
95
+ if (action === "print") {
96
+ progressBar.update(index + 1, { fileName });
97
+ }
98
+ });
99
+ if (action === "no-print") {
100
+ return StatusStore;
101
+ }
102
+ progressBar.stop();
103
+ StatusStore.printStatus("summary");
104
+ StatusStore.printStatusForAll();
105
+ StatusStore.printMigrationHelp();
106
+ console.info("\n");
107
+ return StatusStore;
108
+ }
109
+ function getWordPositionInFile(fileContent, index) {
110
+ const lines = fileContent.split("\n");
111
+ let lineNumber = 1;
112
+ let charCount = 0;
113
+ for (let i = 0; i < lines.length; i++) {
114
+ const lineLength = lines[i].length + 1; // +1 to account for the newline character that was removed by split
115
+ if (charCount + lineLength > index) {
116
+ return { row: lineNumber, column: index - charCount + 1 };
117
+ }
118
+ charCount += lineLength;
119
+ lineNumber++;
120
+ }
121
+ return { row: lineNumber, column: 0 }; // Should not reach here if the index is within the file content range
122
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
4
+ const legacy_tokens_1 = require("../config/legacy.tokens");
5
+ function transformer(file) {
6
+ let src = file.source;
7
+ for (const [oldToken, config] of Object.entries(legacy_tokens_1.legacyTokenConfig)) {
8
+ const oldCSSVar = `--a-${oldToken}`;
9
+ /* We update all re-definitions of a token to a "legacy" version */
10
+ const replaceRegex = new RegExp("(" + `${oldCSSVar}:` + ")", "gm");
11
+ src = src.replace(replaceRegex, `--aksel-legacy${oldCSSVar.replace("--", "__")}:`);
12
+ if (config.replacement.length > 0) {
13
+ src = src.replace(config.regexes.css, `--ax-${config.replacement}`);
14
+ }
15
+ }
16
+ return src;
17
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = transformer;
7
+ const imports_1 = require("../../codemod/utils/imports");
8
+ const lineterminator_1 = require("../../codemod/utils/lineterminator");
9
+ const moveAndRenameImport_1 = __importDefault(require("../../codemod/utils/moveAndRenameImport"));
10
+ const translate_token_1 = require("../../codemod/utils/translate-token");
11
+ const legacy_tokens_1 = require("../config/legacy.tokens");
12
+ function transformer(file, api) {
13
+ let src = file.source;
14
+ const j = api.jscodeshift;
15
+ let root = j(file.source);
16
+ const jsImport = root.find(j.ImportDeclaration).filter((x) => {
17
+ return ["@navikt/ds-tokens/dist/tokens"].includes(x.node.source.value);
18
+ });
19
+ if (jsImport.size() === 0) {
20
+ return src;
21
+ }
22
+ for (const [oldToken, config] of Object.entries(legacy_tokens_1.legacyTokenConfig)) {
23
+ const oldCSSVar = `--a-${oldToken}`;
24
+ const oldJsVar = (0, translate_token_1.translateToken)(oldCSSVar, "js");
25
+ let foundName = null;
26
+ (0, imports_1.getImportSpecifier)(j, root, oldJsVar, "@navikt/ds-tokens/dist/tokens").forEach((x) => {
27
+ foundName = x.node.imported.name;
28
+ });
29
+ if (!foundName) {
30
+ continue;
31
+ }
32
+ if (config.replacement.length > 0) {
33
+ /* We remove the prefix */
34
+ const jsToken = (0, translate_token_1.translateToken)(`--ax-${config.replacement}`, "js").slice(2);
35
+ const localName = (0, moveAndRenameImport_1.default)(j, root, {
36
+ fromImport: "@navikt/ds-tokens/dist/tokens",
37
+ toImport: "@navikt/ds-tokens/darkside-js",
38
+ fromName: foundName,
39
+ toName: jsToken,
40
+ ignoreAlias: true,
41
+ });
42
+ let code = root.toSource((0, lineterminator_1.getLineTerminator)(src));
43
+ const rgx = new RegExp(`(\\s|^)?(${localName})(?=\\s|$|[^\\w-])`, "gm");
44
+ code = code.replace(rgx, jsToken);
45
+ src = code;
46
+ root = j(code);
47
+ continue;
48
+ }
49
+ }
50
+ return root.toSource((0, lineterminator_1.getLineTerminator)(src));
51
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
4
+ const translate_token_1 = require("../../codemod/utils/translate-token");
5
+ const legacy_tokens_1 = require("../config/legacy.tokens");
6
+ function transformer(file) {
7
+ let src = file.source;
8
+ for (const config of Object.values(legacy_tokens_1.legacyTokenConfig)) {
9
+ if (config.replacement.length > 0) {
10
+ src = src.replace(config.regexes.less, (0, translate_token_1.translateToken)(`--ax-${config.replacement}`, "less"));
11
+ }
12
+ }
13
+ return src;
14
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
4
+ const translate_token_1 = require("../../codemod/utils/translate-token");
5
+ const legacy_tokens_1 = require("../config/legacy.tokens");
6
+ function transformer(file) {
7
+ let src = file.source;
8
+ for (const config of Object.values(legacy_tokens_1.legacyTokenConfig)) {
9
+ if (config.replacement.length > 0) {
10
+ src = src.replace(config.regexes.scss, (0, translate_token_1.translateToken)(`--ax-${config.replacement}`, "scss"));
11
+ }
12
+ }
13
+ return src;
14
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
4
+ const legacy_tokens_1 = require("../config/legacy.tokens");
5
+ const token_regex_1 = require("../config/token-regex");
6
+ function transformer(file) {
7
+ let src = file.source;
8
+ for (const [name, config] of Object.entries(legacy_tokens_1.legacyTokenConfig)) {
9
+ if (!config.twOld || !config.twNew) {
10
+ continue;
11
+ }
12
+ const isBreakpoint = name.includes("breakpoint");
13
+ if (isBreakpoint) {
14
+ src = src.replace(config.regexes.tailwind, `${config.twNew}:`);
15
+ continue;
16
+ }
17
+ const beforeSplit = config.twOld.split(",");
18
+ const afterSplit = config.twNew.split(",");
19
+ const matches = src.match(config.regexes.tailwind) || [];
20
+ for (const match of matches) {
21
+ const index = beforeSplit.indexOf(match.trim().replace(":", ""));
22
+ if (index >= 0) {
23
+ const withPrefix = match.trim().startsWith(":");
24
+ const addSpace = match.startsWith(" ");
25
+ const replacementToken = afterSplit[index];
26
+ src = src.replace((0, token_regex_1.createSingleTwRegex)(match), withPrefix
27
+ ? `:${replacementToken}`
28
+ : `${addSpace ? " " : ""}${replacementToken}`);
29
+ }
30
+ }
31
+ }
32
+ return src;
33
+ }