@navikt/aksel 2.9.1 → 2.9.3-beta.1

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 (29) hide show
  1. package/README.md +157 -1
  2. package/dist/codemod/index.js +36 -0
  3. package/dist/codemod/migrations.js +75 -0
  4. package/dist/codemod/run-codeshift.js +91 -0
  5. package/dist/codemod/tokens-map.mjs +364 -0
  6. package/dist/codemod/transforms/rename-prop/rename-prop.js +21 -0
  7. package/dist/codemod/transforms/v1.0.0/chat/chat.js +65 -0
  8. package/dist/codemod/transforms/v1.0.0/pagination/pagination.js +66 -0
  9. package/dist/codemod/transforms/v1.0.0/preset/preset.js +19 -0
  10. package/dist/codemod/transforms/v1.0.0/tabs/tabs.js +78 -0
  11. package/dist/codemod/transforms/v2.0.0/update-css-tokens/update-css-tokens.js +21 -0
  12. package/dist/codemod/transforms/v2.0.0/update-js-tokens/update-js-tokens.js +36 -0
  13. package/dist/codemod/transforms/v2.0.0/update-less-tokens/update-less-tokens.js +18 -0
  14. package/dist/codemod/transforms/v2.0.0/update-sass-tokens/update-sass-tokens.js +18 -0
  15. package/dist/codemod/utils/check.js +66 -0
  16. package/dist/codemod/utils/imports.js +20 -0
  17. package/dist/codemod/utils/rename-props.js +13 -0
  18. package/dist/codemod/utils/translate-token.js +20 -0
  19. package/dist/codemod/validation.js +41 -0
  20. package/dist/css-imports/config.js +5 -2
  21. package/dist/css-imports/generate-output.js +42 -35
  22. package/dist/css-imports/get-directories.js +12 -5
  23. package/dist/css-imports/get-version.js +11 -4
  24. package/dist/css-imports/index.js +36 -33
  25. package/dist/css-imports/inquiry.js +11 -4
  26. package/dist/css-imports/scan-code.js +10 -5
  27. package/dist/help.js +17 -6
  28. package/dist/index.js +22 -6
  29. package/package.json +21 -13
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,19 +8,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import { StyleMappings } from "@navikt/ds-css/config/_mappings.js";
11
- import { generateImportOutput } from "./generate-output.js";
12
- import { ComponentPrefix } from "./config.js";
13
- import { inquiry } from "./inquiry.js";
14
- import { exec } from "child_process";
15
- import { fileURLToPath } from "url";
16
- import { dirname } from "path";
17
- import { getAllVersions } from "./get-version.js";
18
- import chalk from "chalk";
19
- import { getDirectories } from "./get-directories.js";
20
- const __filename = fileURLToPath(import.meta.url);
21
- const __dirname = dirname(__filename);
22
- export function cssImportsCommand() {
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.cssImportsCommand = void 0;
16
+ const _mappings_1 = require("@navikt/ds-css/config/_mappings");
17
+ const generate_output_1 = require("./generate-output");
18
+ const config_1 = require("./config");
19
+ const inquiry_1 = require("./inquiry");
20
+ const child_process_1 = require("child_process");
21
+ const chalk_1 = __importDefault(require("chalk"));
22
+ const get_directories_1 = require("./get-directories");
23
+ const get_version_1 = require("./get-version");
24
+ function cssImportsCommand() {
23
25
  return __awaiter(this, void 0, void 0, function* () {
24
26
  let answers = {
25
27
  "config-type": "regular",
@@ -32,7 +34,7 @@ export function cssImportsCommand() {
32
34
  imports: null,
33
35
  output: "print-clipboard",
34
36
  };
35
- yield inquiry(answers, [
37
+ yield (0, inquiry_1.inquiry)(answers, [
36
38
  {
37
39
  type: "select",
38
40
  name: "config-type",
@@ -44,7 +46,7 @@ export function cssImportsCommand() {
44
46
  { message: "Full control (global + components)", name: "advanced" },
45
47
  ],
46
48
  footer() {
47
- return chalk.grey(`${chalk.cyan(`\n Documentation:`)}\n Regular: https://aksel.nav.no/grunnleggende/kode/css-import
49
+ return chalk_1.default.grey(`${chalk_1.default.cyan(`\n Documentation:`)}\n Regular: https://aksel.nav.no/grunnleggende/kode/css-import
48
50
  Partial: https://aksel.nav.no/grunnleggende/kode/css-import#h64650b1a4ad6
49
51
  Full: https://aksel.nav.no/grunnleggende/kode/css-import#h4037598416ef\n`);
50
52
  },
@@ -61,7 +63,7 @@ export function cssImportsCommand() {
61
63
  },
62
64
  ]);
63
65
  if ((answers === null || answers === void 0 ? void 0 : answers.cdn) === "no") {
64
- yield inquiry(answers, [
66
+ yield (0, inquiry_1.inquiry)(answers, [
65
67
  {
66
68
  type: "select",
67
69
  name: "tailwind",
@@ -85,10 +87,10 @@ export function cssImportsCommand() {
85
87
  ]);
86
88
  }
87
89
  else {
88
- let versions = (yield getAllVersions()).filter((x) => !x.includes("-"));
90
+ let versions = (yield (0, get_version_1.getAllVersions)()).filter((x) => !x.includes("-"));
89
91
  const index = versions.findIndex((x) => x.startsWith("2.9.0"));
90
92
  versions = versions.slice(index).reverse();
91
- yield inquiry(answers, [
93
+ yield (0, inquiry_1.inquiry)(answers, [
92
94
  {
93
95
  type: "autocomplete",
94
96
  name: "version",
@@ -97,17 +99,17 @@ export function cssImportsCommand() {
97
99
  initial: 0,
98
100
  choices: versions,
99
101
  footer() {
100
- return chalk.grey('Remember to match version with @navikt/ds-react!\nNote: CDN was introduced in v2.9.0, older versions not available.\nUse "static" import instead.');
102
+ return chalk_1.default.grey('Remember to match version with @navikt/ds-react!\nNote: CDN was introduced in v2.9.0, older versions not available.\nUse "static" import instead.');
101
103
  },
102
104
  },
103
105
  ]);
104
106
  }
105
107
  if (answers["config-type"] === "regular") {
106
- yield generateImportOutput(answers);
108
+ yield (0, generate_output_1.generateImportOutput)(answers);
107
109
  return;
108
110
  }
109
111
  answers["config-type"] === "advanced" &&
110
- (yield inquiry(answers, [
112
+ (yield (0, inquiry_1.inquiry)(answers, [
111
113
  {
112
114
  type: "select",
113
115
  name: "autoscan",
@@ -120,44 +122,44 @@ export function cssImportsCommand() {
120
122
  },
121
123
  ]));
122
124
  answers.autoscan === "yes" &&
123
- (yield inquiry(answers, [
125
+ (yield (0, inquiry_1.inquiry)(answers, [
124
126
  {
125
127
  type: "autocomplete",
126
128
  name: "scandir",
127
129
  message: `Directory to scan`,
128
130
  limit: 6,
129
131
  initial: 0,
130
- choices: getDirectories(),
132
+ choices: (0, get_directories_1.getDirectories)(),
131
133
  footer() {
132
- return chalk.grey("filtered out: node_moduels, dist, build, lib, .* (dotfiles)");
134
+ return chalk_1.default.grey("filtered out: node_moduels, dist, build, lib, .* (dotfiles)");
133
135
  },
134
136
  },
135
137
  ]));
136
138
  let foundComponents = [];
137
139
  if (answers["autoscan"] === "yes") {
138
140
  foundComponents = yield new Promise((resolve) => {
139
- exec(`node ${__dirname}/scan-code.js ${answers.scandir}`, (_, stdout) => {
141
+ (0, child_process_1.exec)(`node ${__dirname}/scan-code.js ${answers.scandir}`, (_, stdout) => {
140
142
  resolve(stdout ? JSON.parse(stdout.trim().split("\n").slice(1).join("")) : []);
141
143
  });
142
144
  });
143
145
  }
144
- yield inquiry(answers, [
146
+ yield (0, inquiry_1.inquiry)(answers, [
145
147
  {
146
148
  type: "multiselect",
147
149
  name: "imports",
148
150
  message: "Imports",
149
151
  initial: [
150
- ...StyleMappings.baseline.map((x) => x.main.replace(".css", "")),
151
- ...StyleMappings.components
152
+ ..._mappings_1.StyleMappings.baseline.map((x) => x.main.replace(".css", "")),
153
+ ..._mappings_1.StyleMappings.components
152
154
  .filter((x) => foundComponents.includes(x.component))
153
- .map((x) => `${ComponentPrefix}${x.component}`),
155
+ .map((x) => `${config_1.ComponentPrefix}${x.component}`),
154
156
  ],
155
157
  choices: [
156
158
  {
157
159
  message: "Default-imports",
158
160
  name: "default",
159
161
  choices: [
160
- ...StyleMappings.baseline.map((x) => ({
162
+ ..._mappings_1.StyleMappings.baseline.map((x) => ({
161
163
  message: `${x.main.replace(".css", "")}${x.optional ? "" : " (required)"}`,
162
164
  name: x.main.replace(".css", ""),
163
165
  })),
@@ -169,9 +171,9 @@ export function cssImportsCommand() {
169
171
  message: "Components",
170
172
  name: "components",
171
173
  choices: [
172
- ...StyleMappings.components.map((x) => ({
174
+ ..._mappings_1.StyleMappings.components.map((x) => ({
173
175
  message: x.component,
174
- name: `${ComponentPrefix}${x.component}`,
176
+ name: `${config_1.ComponentPrefix}${x.component}`,
175
177
  })),
176
178
  ],
177
179
  },
@@ -180,6 +182,7 @@ export function cssImportsCommand() {
180
182
  ],
181
183
  },
182
184
  ]);
183
- yield generateImportOutput(answers);
185
+ yield (0, generate_output_1.generateImportOutput)(answers);
184
186
  });
185
187
  }
188
+ exports.cssImportsCommand = cssImportsCommand;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,11 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import Enquirer from "enquirer";
11
- import chalk from "chalk";
12
- export function inquiry(answers, questions) {
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.inquiry = void 0;
16
+ const enquirer_1 = __importDefault(require("enquirer"));
17
+ const chalk_1 = __importDefault(require("chalk"));
18
+ function inquiry(answers, questions) {
13
19
  return __awaiter(this, void 0, void 0, function* () {
14
- return yield Enquirer.prompt(questions.map((x) => (Object.assign(Object.assign({}, x), { cancel: () => process.exit(1), header: `\n${chalk.gray("Command 'css-imports' will not edit your files directly!")}\n` }))))
20
+ return yield enquirer_1.default.prompt(questions.map((x) => (Object.assign(Object.assign({}, x), { cancel: () => process.exit(1), header: `\n${chalk_1.default.gray("Command 'css-imports' will not edit your files directly!")}\n` }))))
15
21
  .then((a) => {
16
22
  Object.entries(a).forEach(([key, value]) => {
17
23
  answers[key] = value;
@@ -27,3 +33,4 @@ export function inquiry(answers, questions) {
27
33
  });
28
34
  });
29
35
  }
36
+ exports.inquiry = inquiry;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,8 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import path from "path";
11
- import scanner from "react-scanner";
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const path_1 = __importDefault(require("path"));
16
+ const react_scanner_1 = __importDefault(require("react-scanner"));
12
17
  run();
13
18
  function run() {
14
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -21,13 +26,13 @@ function scanCode() {
21
26
  const cwd = process.cwd();
22
27
  const config = {
23
28
  rootDir: cwd,
24
- crawlFrom: `${(_a = process.argv[2]) !== null && _a !== void 0 ? _a : ""}`.replace(path.basename(cwd), "."),
29
+ crawlFrom: `${(_a = process.argv[2]) !== null && _a !== void 0 ? _a : ""}`.replace(path_1.default.basename(cwd), "."),
25
30
  globs: ["**/!(*.test|*.spec|*.stories|*.story).@(jsx|tsx)"],
26
31
  exclude: (dirname) => dirname === "node_modules",
27
- getComponentName: ({ imported, moduleName, }) => imported || path.basename(moduleName),
32
+ getComponentName: ({ imported, moduleName, }) => imported || path_1.default.basename(moduleName),
28
33
  };
29
34
  let result = null;
30
- yield scanner
35
+ yield react_scanner_1.default
31
36
  .run(Object.assign(Object.assign({}, config), { importedFrom: /@navikt\/ds-react/, processors: [
32
37
  "count-components",
33
38
  ({ report }) => {
package/dist/help.js CHANGED
@@ -1,15 +1,26 @@
1
- import chalk from "chalk";
2
- export function helpCommand() {
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.helpCommand = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const figlet_1 = __importDefault(require("figlet"));
9
+ function helpCommand() {
10
+ console.log(figlet_1.default.textSync("Aksel CLI"));
3
11
  console.log(`
4
- ✨ Aksel client-tool
5
-
6
12
  📝 Documentation
7
- - ${chalk.blueBright("https://aksel.nav.no/grunnleggende/kode/kommandolinje")}
13
+ - ${chalk_1.default.blueBright("https://aksel.nav.no/grunnleggende/kode/kommandolinje")}
8
14
 
9
15
  💻 Commands:
10
- - ${chalk.cyan(`npx @navikt/aksel ${chalk.green("css-imports")}`)}
16
+ - ${chalk_1.default.cyan(`npx @navikt/aksel ${chalk_1.default.green("css-imports")}`)}
11
17
  ✔︎ Helps with CSS imports for all Aksel components
12
18
  ✔︎ Supports Static and CDN-imports
13
19
  ✔︎ Handles cascading, tailwind and @layer rules
20
+
21
+ - ${chalk_1.default.cyan(`npx @navikt/aksel ${chalk_1.default.green("codemod")} ${chalk_1.default.gray("<migration>")}`)}
22
+ ✔︎ Code-transformations for breaking changes when updating Aksel
23
+ ✔︎ Run with ${chalk_1.default.cyan(`${chalk_1.default.green("--help")}`)} to get started!
14
24
  `);
15
25
  }
26
+ exports.helpCommand = helpCommand;
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ "use strict";
2
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
5
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,22 +9,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
9
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
10
  });
10
11
  };
11
- import chalk from "chalk";
12
- import { helpCommand } from "./help.js";
13
- import { cssImportsCommand } from "./css-imports/index.js";
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const help_1 = require("./help");
18
+ const index_1 = require("./css-imports/index");
19
+ const index_2 = require("./codemod/index");
20
+ const fs_1 = __importDefault(require("fs"));
14
21
  run();
15
22
  function run() {
16
23
  return __awaiter(this, void 0, void 0, function* () {
17
24
  if (!process.argv[2] || process.argv[2] === "help") {
18
- helpCommand();
25
+ (0, help_1.helpCommand)();
19
26
  return;
20
27
  }
21
28
  else if (process.argv[2] === "css-imports") {
22
- yield cssImportsCommand();
29
+ yield (0, index_1.cssImportsCommand)();
30
+ return;
31
+ }
32
+ else if (process.argv[2] === "codemod") {
33
+ (0, index_2.codemodCommand)();
34
+ return;
35
+ }
36
+ else if (process.argv[2] === "-v" || process.argv[2] === "--version") {
37
+ const pkg = JSON.parse(fs_1.default.readFileSync("./package.json").toString()).version;
38
+ console.log(pkg);
23
39
  return;
24
40
  }
25
41
  else {
26
- console.log(chalk.red(`Unknown command: ${process.argv[2]}.\nRun ${chalk.cyan("npx @navikt/aksel help")} for all available commands.`));
42
+ console.log(chalk_1.default.red(`Unknown command: ${process.argv[2]}.\nRun ${chalk_1.default.cyan("npx @navikt/aksel help")} for all available commands.`));
27
43
  }
28
44
  });
29
45
  }
package/package.json CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "@navikt/aksel",
3
- "version": "2.9.1",
4
- "description": "Aksel command line interface. Handles css-imports, codemods (planned) and more",
3
+ "version": "2.9.3-beta.1",
4
+ "description": "Aksel commandline interface. Handles css-imports, codemods and more",
5
5
  "author": "Aksel | NAV designsystem team",
6
6
  "license": "MIT",
7
7
  "keywords": [
8
- "react",
9
- "command-line",
8
+ "Commandline",
10
9
  "CLI",
11
- "css",
12
- "CDN"
10
+ "CDN",
11
+ "Codemods"
13
12
  ],
14
13
  "files": [
15
- "dist"
14
+ "dist",
15
+ "!dist/**/tests"
16
16
  ],
17
17
  "scripts": {
18
18
  "clean": "rimraf dist",
19
19
  "build": "yarn clean && tsc -p tsconfig.json",
20
- "dev": "tsc --watch -p tsconfig.json"
20
+ "dev": "tsc --watch -p tsconfig.json",
21
+ "test": "yarn build && jest",
22
+ "test:watch": "jest --watch"
21
23
  },
22
24
  "bin": "./dist/index.js",
23
25
  "repository": {
@@ -25,21 +27,28 @@
25
27
  "url": "git+https://github.com/navikt/aksel.git",
26
28
  "directory": "@navikt/aksel"
27
29
  },
28
- "type": "module",
29
30
  "homepage": "https://aksel.nav.no/grunnleggende/kode/kommandolinje",
30
31
  "dependencies": {
31
- "@navikt/ds-css": "2.9.1",
32
+ "@navikt/ds-css": "2.9.3",
32
33
  "axios": "1.3.6",
33
34
  "chalk": "4.1.0",
34
- "clipboardy": "^3.0.0",
35
+ "clipboardy": "^2.3.0",
36
+ "commander": "10.0.1",
35
37
  "enquirer": "^2.3.6",
36
38
  "fast-glob": "3.2.11",
39
+ "figlet": "1.6.0",
40
+ "is-git-clean": "1.1.0",
41
+ "jscodeshift": "0.13.1",
42
+ "jscodeshift-add-imports": "1.0.10",
37
43
  "lodash": "4.17.21",
38
44
  "react-scanner": "^1.1.0"
39
45
  },
40
46
  "devDependencies": {
41
47
  "@types/inquirer": "^9.0.3",
48
+ "@types/jest": "^29.0.0",
49
+ "jest": "^29.0.0",
42
50
  "rimraf": "3.0.2",
51
+ "ts-jest": "^29.0.0",
43
52
  "typescript": "^4.8.0"
44
53
  },
45
54
  "sideEffects": false,
@@ -47,7 +56,6 @@
47
56
  "node": ">=16.0.0"
48
57
  },
49
58
  "publishConfig": {
50
- "access": "public",
51
- "provenance": true
59
+ "access": "public"
52
60
  }
53
61
  }