@navikt/aksel 2.9.2 → 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.
- package/README.md +157 -1
- package/dist/codemod/index.js +36 -0
- package/dist/codemod/migrations.js +75 -0
- package/dist/codemod/run-codeshift.js +91 -0
- package/dist/codemod/tokens-map.mjs +364 -0
- package/dist/codemod/transforms/rename-prop/rename-prop.js +21 -0
- package/dist/codemod/transforms/v1.0.0/chat/chat.js +65 -0
- package/dist/codemod/transforms/v1.0.0/pagination/pagination.js +66 -0
- package/dist/codemod/transforms/v1.0.0/preset/preset.js +19 -0
- package/dist/codemod/transforms/v1.0.0/tabs/tabs.js +78 -0
- package/dist/codemod/transforms/v2.0.0/update-css-tokens/update-css-tokens.js +21 -0
- package/dist/codemod/transforms/v2.0.0/update-js-tokens/update-js-tokens.js +36 -0
- package/dist/codemod/transforms/v2.0.0/update-less-tokens/update-less-tokens.js +18 -0
- package/dist/codemod/transforms/v2.0.0/update-sass-tokens/update-sass-tokens.js +18 -0
- package/dist/codemod/utils/check.js +66 -0
- package/dist/codemod/utils/imports.js +20 -0
- package/dist/codemod/utils/rename-props.js +13 -0
- package/dist/codemod/utils/translate-token.js +20 -0
- package/dist/codemod/validation.js +41 -0
- package/dist/css-imports/config.js +5 -2
- package/dist/css-imports/generate-output.js +42 -35
- package/dist/css-imports/get-directories.js +12 -5
- package/dist/css-imports/get-version.js +11 -4
- package/dist/css-imports/index.js +36 -33
- package/dist/css-imports/inquiry.js +11 -4
- package/dist/css-imports/scan-code.js +10 -5
- package/dist/help.js +17 -6
- package/dist/index.js +22 -6
- package/package.json +20 -13
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Aksel command line interface
|
|
2
2
|
|
|
3
|
-
CLI tool for managing CSS-imports and
|
|
3
|
+
CLI tool for managing CSS-imports and Codemods when consuming Aksel-packages.
|
|
4
4
|
|
|
5
5
|
[Documentation](https://aksel.nav.no/preview/grunnleggende/kode/kommandolinje)
|
|
6
6
|
|
|
@@ -10,6 +10,162 @@ npx @navikt/aksel
|
|
|
10
10
|
|
|
11
11
|
commands:
|
|
12
12
|
css-imports: Generate css-imports for all components from Aksel
|
|
13
|
+
codemod: Codemods for version-migrations related to Aksel
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Codemods
|
|
17
|
+
|
|
18
|
+
Codemods are code-transformations that patches breaking changes in your project. This helps when migrating without spending time doing it manually.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
To get started:
|
|
22
|
+
npx @navikt/aksel codemod --help
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### v1 -> v2
|
|
26
|
+
|
|
27
|
+
[Documentation](https://aksel.nav.no/grunnleggende/kode/migrering#h76f47744d112)
|
|
28
|
+
|
|
29
|
+
v2-css: Patches changed css-variables
|
|
30
|
+
v2-js: Patches changed js-variables
|
|
31
|
+
v2-sass: Patches changed sass-variables
|
|
32
|
+
v2-less: Patches changed less-variables
|
|
33
|
+
|
|
34
|
+
#### css-tokens (--navds format)
|
|
35
|
+
|
|
36
|
+
`npx @navikt/aksel codemod v2-css src`
|
|
37
|
+
|
|
38
|
+
When having redefined a token, you will need to manually find and replace these instances after the codemod-run. A global search for `--v2-migration__` will show all found instances where you had redefined a token.
|
|
39
|
+
|
|
40
|
+
```diff
|
|
41
|
+
.example{
|
|
42
|
+
- color: var(--navds-global-color-gray-900);
|
|
43
|
+
+ color: var(--a-gray-900);
|
|
44
|
+
|
|
45
|
+
- --navds-semantic-color-text: red;
|
|
46
|
+
+ --v2-migration__navds-semantic-color-text: red;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### sass/scss-tokens ($navds format)
|
|
51
|
+
|
|
52
|
+
`npx @navikt/aksel codemod v2-sass src`
|
|
53
|
+
|
|
54
|
+
```diff
|
|
55
|
+
.example{
|
|
56
|
+
- color: $navds-global-color-gray-900;
|
|
57
|
+
+ color: $a-gray-900;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### less-tokens (@navds format)
|
|
62
|
+
|
|
63
|
+
`npx @navikt/aksel codemod v2-less src`
|
|
64
|
+
|
|
65
|
+
```diff
|
|
66
|
+
.example{
|
|
67
|
+
- color: @navds-global-color-gray-900;
|
|
68
|
+
+ color: @a-gray-900;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### js-tokens
|
|
73
|
+
|
|
74
|
+
`npx @navikt/aksel codemod v2-js src`
|
|
75
|
+
|
|
76
|
+
```diff
|
|
77
|
+
|
|
78
|
+
- import { NavdsGlobalColorGray900 } from "@navikt/ds-tokens";
|
|
79
|
+
+ import { AGray900 } from "@navikt/ds-tokens";
|
|
80
|
+
|
|
81
|
+
const styled = styled.p`
|
|
82
|
+
- color: ${NavdsGlobalColorGray900};
|
|
83
|
+
+ color: ${AGray900};
|
|
84
|
+
`
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### beta -> v1
|
|
88
|
+
|
|
89
|
+
[Documentation](https://aksel.nav.no/grunnleggende/kode/migrering#h50d54a5af8c1)
|
|
90
|
+
|
|
91
|
+
v1-preset: Runs all codemods for beta -> v1
|
|
92
|
+
v1-pagination: Fixes breaking API-changes for <Pagination /> component
|
|
93
|
+
v1-tabs: Fixes breaking API-changes for <Tabs /> component
|
|
94
|
+
v1-chat: Fixes breaking API-changes for <SpeechBubble /> (now <Chat/>) component
|
|
95
|
+
|
|
96
|
+
#### preset
|
|
97
|
+
|
|
98
|
+
Combines all avaliable codemods for migrating from beta -> v1. This transform should only be ran once.
|
|
99
|
+
|
|
100
|
+
Includes these transforms
|
|
101
|
+
|
|
102
|
+
- v1-tabs
|
|
103
|
+
- v1-chat
|
|
104
|
+
- v1-pagination
|
|
105
|
+
|
|
106
|
+
#### tabs
|
|
107
|
+
|
|
108
|
+
`npx @navikt/aksel codemod v1-tabs src`
|
|
109
|
+
|
|
110
|
+
```diff
|
|
111
|
+
<Tabs
|
|
112
|
+
defaultValue="logg"
|
|
113
|
+
onChange={(x) => console.log(x)}
|
|
114
|
+
- loop
|
|
115
|
+
+ iconPosition="left"
|
|
116
|
+
>
|
|
117
|
+
<Tabs.List
|
|
118
|
+
- loop
|
|
119
|
+
>
|
|
120
|
+
<Tabs.Tab
|
|
121
|
+
value="logg"
|
|
122
|
+
label="logg"
|
|
123
|
+
- iconPosition="left"
|
|
124
|
+
/>
|
|
125
|
+
</Tabs.List>
|
|
126
|
+
<Tabs.Panel value="logg">TabPanel for Logg-tab</Tabs.Panel>
|
|
127
|
+
</Tabs>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### chat
|
|
131
|
+
|
|
132
|
+
`npx @navikt/aksel codemod v1-chat src`
|
|
133
|
+
|
|
134
|
+
```diff
|
|
135
|
+
-<SpeechBubble
|
|
136
|
+
+<Chat
|
|
137
|
+
- illustration={<Illustration />}
|
|
138
|
+
- topText="Ola Normann 01.01.21 14:00"
|
|
139
|
+
- illustrationBgColor="blue"
|
|
140
|
+
+ avatar={<Illustration />}
|
|
141
|
+
+ name="Ola Normann 01.01.21 14:00"
|
|
142
|
+
+ avatarBgColor="blue"
|
|
143
|
+
backgroundColor="red"
|
|
144
|
+
>
|
|
145
|
+
- <SpeechBubble.Bubble>
|
|
146
|
+
+ <Chat.Bubble>
|
|
147
|
+
Aute minim nisi sunt mollit duis sunt nulla minim non proident.
|
|
148
|
+
- </SpeechBubble.Bubble>
|
|
149
|
+
+ </Chat.Bubble>
|
|
150
|
+
-</SpeechBubble>
|
|
151
|
+
+</Chat>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### pagination
|
|
155
|
+
|
|
156
|
+
`npx @navikt/aksel codemod v1-pagination src`
|
|
157
|
+
|
|
158
|
+
This codemod can only be ran once, since the size-scale will keep decreasing for each subsequent iteration.
|
|
159
|
+
|
|
160
|
+
```diff
|
|
161
|
+
-<Pagiation />
|
|
162
|
+
+<Pagiation size="small"/>
|
|
163
|
+
|
|
164
|
+
-<Pagiation size="medium"/>
|
|
165
|
+
+<Pagiation size="small"/>
|
|
166
|
+
|
|
167
|
+
-<Pagiation size="small"/>
|
|
168
|
+
+<Pagiation size="xsmall"/>
|
|
13
169
|
```
|
|
14
170
|
|
|
15
171
|
## License
|
|
@@ -0,0 +1,36 @@
|
|
|
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.codemodCommand = void 0;
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const figlet_1 = __importDefault(require("figlet"));
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const migrations_js_1 = require("./migrations.js");
|
|
11
|
+
const validation_js_1 = require("./validation.js");
|
|
12
|
+
const run_codeshift_js_1 = require("./run-codeshift.js");
|
|
13
|
+
const program = new commander_1.Command();
|
|
14
|
+
function codemodCommand() {
|
|
15
|
+
program.name(`${chalk_1.default.blueBright(`npx @navikt/aksel`)}`);
|
|
16
|
+
program
|
|
17
|
+
.command("codemod")
|
|
18
|
+
.addHelpText("beforeAll", figlet_1.default.textSync("Codemods"))
|
|
19
|
+
.addHelpText("afterAll", chalk_1.default.gray(`\nAvailable migrations:\n${(0, migrations_js_1.getMigrationString)()}`))
|
|
20
|
+
.description("Migrations for Aksel components and more")
|
|
21
|
+
.argument("<migration>", "Migration name")
|
|
22
|
+
.option("-e, --ext [extension]", "default: js,ts,jsx,tsx,css,scss,less")
|
|
23
|
+
.option("-g, --glob [glob]", "Globbing pattern, overrides --ext! Run with 'noglob' if using zsh-terminal. ")
|
|
24
|
+
.option("-d, --dry-run", "Dry run, no changes will be made")
|
|
25
|
+
.option("-p, --print", "Print transformed files")
|
|
26
|
+
.option("-f, --force", "Forcibly run migrations without checking git-changes")
|
|
27
|
+
.addHelpText("after", `\nExample:
|
|
28
|
+
$ npx @navikt/aksel --dry-run v2-css`)
|
|
29
|
+
.action((str, options) => {
|
|
30
|
+
(0, validation_js_1.validateMigration)(str, program);
|
|
31
|
+
(0, validation_js_1.validateGit)(options, program);
|
|
32
|
+
(0, run_codeshift_js_1.runCodeshift)(str, options, program);
|
|
33
|
+
});
|
|
34
|
+
program.parse();
|
|
35
|
+
}
|
|
36
|
+
exports.codemodCommand = codemodCommand;
|
|
@@ -0,0 +1,75 @@
|
|
|
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.getMigrationString = exports.getMigrationNames = exports.getMigrationPath = exports.migrations = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
exports.migrations = {
|
|
9
|
+
"1.0.0": [
|
|
10
|
+
{
|
|
11
|
+
description: "Runs all codemods for beta -> v1 migration",
|
|
12
|
+
value: "v1-preset",
|
|
13
|
+
path: "v1.0.0/preset/preset",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
description: "Fixes breaking API-changes for <Pagination /> component",
|
|
17
|
+
value: "v1-pagination",
|
|
18
|
+
path: "v1.0.0/pagination/pagination",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
description: "Fixes breaking API-changes for <Tabs /> component",
|
|
22
|
+
value: "v1-tabs",
|
|
23
|
+
path: "v1.0.0/tabs/tabs",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
description: "Fixes breaking API-changes for <SpeechBubble /> (now <Chat/>) component",
|
|
27
|
+
value: "v1-chat",
|
|
28
|
+
path: "v1.0.0/chat/chat",
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
"2.0.0": [
|
|
32
|
+
{
|
|
33
|
+
description: "Patches changed css-variables",
|
|
34
|
+
value: "v2-css",
|
|
35
|
+
path: "v2.0.0/update-css-tokens/update-css-tokens",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
description: "Patches changed js-variables",
|
|
39
|
+
value: "v2-js",
|
|
40
|
+
path: "v2.0.0/update-js-tokens/update-js-tokens",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
description: "Patches changed sass-variables",
|
|
44
|
+
value: "v2-sass",
|
|
45
|
+
path: "v2.0.0/update-sass-tokens/update-sass-tokens",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
description: "Patches changed less-variables",
|
|
49
|
+
value: "v2-less",
|
|
50
|
+
path: "v2.0.0/update-less-tokens/update-less-tokens",
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
function getMigrationPath(str) {
|
|
55
|
+
var _a;
|
|
56
|
+
return (_a = Object.values(exports.migrations)
|
|
57
|
+
.reduce((acc, val) => [...val, ...acc], [])
|
|
58
|
+
.find((x) => x.value === str)) === null || _a === void 0 ? void 0 : _a.path;
|
|
59
|
+
}
|
|
60
|
+
exports.getMigrationPath = getMigrationPath;
|
|
61
|
+
function getMigrationNames() {
|
|
62
|
+
return Object.values(exports.migrations).reduce((acc, val) => [...val.map((x) => x.value), ...acc], []);
|
|
63
|
+
}
|
|
64
|
+
exports.getMigrationNames = getMigrationNames;
|
|
65
|
+
function getMigrationString() {
|
|
66
|
+
let str = "";
|
|
67
|
+
Object.entries(exports.migrations).forEach(([version, migrations]) => {
|
|
68
|
+
str += `\n${chalk_1.default.underline(version)}\n`;
|
|
69
|
+
migrations.forEach((migration) => {
|
|
70
|
+
str += `${chalk_1.default.blue(migration.value)}: ${migration.description}\n`;
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
return str;
|
|
74
|
+
}
|
|
75
|
+
exports.getMigrationString = getMigrationString;
|
|
@@ -0,0 +1,91 @@
|
|
|
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.runCodeshift = void 0;
|
|
39
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
40
|
+
const jscodeshift = __importStar(require("jscodeshift/src/Runner"));
|
|
41
|
+
const path_1 = __importDefault(require("path"));
|
|
42
|
+
const migrations_1 = require("./migrations");
|
|
43
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
44
|
+
const ignoreNodeModules = [
|
|
45
|
+
"**/node_modules/**",
|
|
46
|
+
"**/dist/**",
|
|
47
|
+
"**/build/**",
|
|
48
|
+
"**/lib/**",
|
|
49
|
+
"**/.next/**",
|
|
50
|
+
];
|
|
51
|
+
function runCodeshift(input, options, program) {
|
|
52
|
+
var _a;
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const codemodPath = path_1.default.join(__dirname, `./transforms/${(0, migrations_1.getMigrationPath)(input)}.js`);
|
|
55
|
+
const filepaths = fast_glob_1.default.sync([(_a = options.glob) !== null && _a !== void 0 ? _a : getDefaultGlob(options === null || options === void 0 ? void 0 : options.ext)], {
|
|
56
|
+
cwd: process.cwd(),
|
|
57
|
+
ignore: ignoreNodeModules,
|
|
58
|
+
});
|
|
59
|
+
console.log("\nRunning migration:", chalk_1.default.green("input"));
|
|
60
|
+
(options === null || options === void 0 ? void 0 : options.glob) && console.log(`Using glob: ${chalk_1.default.green(options.glob)}\n`);
|
|
61
|
+
try {
|
|
62
|
+
yield jscodeshift.run(codemodPath, filepaths, {
|
|
63
|
+
babel: true,
|
|
64
|
+
ignorePattern: ignoreNodeModules,
|
|
65
|
+
extensions: "tsx,ts,jsx,js",
|
|
66
|
+
parser: "tsx",
|
|
67
|
+
verbose: 2,
|
|
68
|
+
runInBand: true,
|
|
69
|
+
silent: false,
|
|
70
|
+
stdin: false,
|
|
71
|
+
dry: options === null || options === void 0 ? void 0 : options.dryRun,
|
|
72
|
+
force: options === null || options === void 0 ? void 0 : options.force,
|
|
73
|
+
print: options === null || options === void 0 ? void 0 : options.print,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
program.error(chalk_1.default.red("Error:", error.message));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.runCodeshift = runCodeshift;
|
|
82
|
+
function getDefaultGlob(ext) {
|
|
83
|
+
const defaultExt = "js,ts,jsx,tsx,css,scss,less";
|
|
84
|
+
return `**/*.{${cleanExtensions(ext !== null && ext !== void 0 ? ext : defaultExt).join(",")}}`;
|
|
85
|
+
}
|
|
86
|
+
function cleanExtensions(ext) {
|
|
87
|
+
return ext
|
|
88
|
+
.split(",")
|
|
89
|
+
.map((e) => e.trim())
|
|
90
|
+
.map((e) => e.replace(".", ""));
|
|
91
|
+
}
|