@navikt/aksel 2.8.16-rc.0

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 ADDED
@@ -0,0 +1,17 @@
1
+ # Aksel command line interface
2
+
3
+ CLI tool for managing CSS-imports and more from when consuming Aksel-packages.
4
+
5
+ [Documentation](https://aksel.nav.no/preview/grunnleggende/kode/kommandolinje)
6
+
7
+ ```bash
8
+ run:
9
+ npx @navikt/aksel
10
+
11
+ commands:
12
+ css-imports: Generate css-imports for all components used from Aksel
13
+ ```
14
+
15
+ ## License
16
+
17
+ [MIT](https://github.com/navikt/aksel/blob/main/LICENCE)
@@ -0,0 +1,2 @@
1
+ export const ComponentPrefix = "C_";
2
+ export const layerSuffix = " layer(aksel)";
@@ -0,0 +1,133 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { ComponentPrefix, layerSuffix } from "./config.js";
11
+ import { formCss, typoCss, componentsCss, StyleMappings, componentDir, rootDir, globalDir, } from "@navikt/ds-css/config/_mappings.js";
12
+ import { inquiry } from "./inquiry.js";
13
+ import clipboard from "clipboardy";
14
+ import lodash from "lodash";
15
+ import chalk from "chalk";
16
+ export function generateImportOutput(answers) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ const useCdn = answers.cdn === "yes";
19
+ const useTailwind = answers.tailwind === "yes";
20
+ const version = answers.version;
21
+ const imports = [];
22
+ let importStr = "";
23
+ yield inquiry(answers, [
24
+ {
25
+ type: "select",
26
+ name: "output",
27
+ message: "Output format",
28
+ initial: "print-clipboard",
29
+ choices: [
30
+ { message: "Clipboard & Print", name: "clipboard-print" },
31
+ { message: "Clipboard", name: "clipboard" },
32
+ { message: "Print", name: "print" },
33
+ ],
34
+ },
35
+ ]);
36
+ answers["config-type"] === "regular"
37
+ ? imports.push(simpleOutput(useCdn, answers.layers === "yes", version))
38
+ : imports.push(...advancedOutput(answers, useCdn, answers.layers === "yes", version));
39
+ if (useTailwind) {
40
+ importStr = `@import "tailwindcss/base";
41
+ ${imports.join("\n")}
42
+
43
+ @import "tailwindcss/components";
44
+ @import "tailwindcss/utilities";
45
+ `;
46
+ }
47
+ else {
48
+ importStr = imports.join("\n");
49
+ }
50
+ if (answers.output.includes("print")) {
51
+ console.log(chalk.bold.cyan(`\nImports 🚀 \n`));
52
+ console.log(chalk.green(`${importStr}`));
53
+ }
54
+ if (useCdn) {
55
+ console.log(chalk.bold.underline.cyan(`\nNotes on CDN-usage 📝`));
56
+ console.log(`We recommend using Static imports, then uploading the your bundled static-files to your own CDN-instance.
57
+ ✔︎ This allows you to control the version of the CSS-files with package.json, and avoids desync between ds-react/ds-css.
58
+ ✔︎ Remember to add 'https://cdn.nav.no' to your applications CSP!`);
59
+ }
60
+ if (useTailwind) {
61
+ console.log(chalk.bold.underline.cyan(`\nNotes on Tailwind-use 📝`));
62
+ console.log(`When using tailwind with Aksel, you will need to add the postcss plugin ${chalk.cyan("postcss-import")}
63
+ ✔︎ NPM: https://www.npmjs.com/package/postcss-import
64
+ ✔︎ Read more here: https://aksel.nav.no/grunnleggende/kode/tailwind`);
65
+ }
66
+ answers.output.includes("clipboard") && clipboard.writeSync(importStr);
67
+ });
68
+ }
69
+ function simpleOutput(cdn, layers, version) {
70
+ const options = {
71
+ static: `@import "@navikt/ds-css"${layers ? layerSuffix : ""};`,
72
+ cdn: toCdn("index.css", version),
73
+ };
74
+ return cdn ? options.cdn : options.static;
75
+ }
76
+ function advancedOutput(answers, cdn, layers, version) {
77
+ const imports = ["/* Defaults */"];
78
+ const baselineImports = answers.imports.filter((x) => !x.startsWith(ComponentPrefix) && x !== "default");
79
+ const componentImports = answers.imports
80
+ .filter((x) => x.startsWith(ComponentPrefix) && x !== "components")
81
+ .map((x) => x.replace(ComponentPrefix, ""));
82
+ baselineImports.forEach((x) => {
83
+ cdn
84
+ ? imports.push(toCdn(`${globalDir}/${x}.css`, version))
85
+ : imports.push(toCssImport(`${globalDir}/${x}.css`, layers));
86
+ });
87
+ if (answers["config-type"] === "easy") {
88
+ cdn
89
+ ? imports.push(toCdn(componentsCss, version))
90
+ : imports.push(toCssImport(`${rootDir}/${componentsCss}`, layers));
91
+ return imports;
92
+ }
93
+ const components = new Set();
94
+ componentImports.forEach((x) => {
95
+ var _a;
96
+ const styleRef = StyleMappings.components.find((y) => y.component === x);
97
+ if (styleRef) {
98
+ components.add(styleRef.main);
99
+ (_a = styleRef === null || styleRef === void 0 ? void 0 : styleRef.dependencies) === null || _a === void 0 ? void 0 : _a.forEach((dep) => components.add(dep));
100
+ }
101
+ });
102
+ let componentImportsList = Array.from(components)
103
+ .filter((x) => x.length > 0)
104
+ .sort((a, b) => a.localeCompare(b));
105
+ if (componentImportsList.find((x) => x === formCss)) {
106
+ componentImportsList = componentImportsList.filter((x) => x !== formCss);
107
+ componentImportsList.unshift(formCss);
108
+ }
109
+ if (componentImportsList.find((x) => x === typoCss)) {
110
+ componentImportsList = componentImportsList.filter((x) => x !== typoCss);
111
+ componentImportsList.unshift(typoCss);
112
+ }
113
+ if (componentImportsList.length === 0) {
114
+ return imports;
115
+ }
116
+ imports.push(``);
117
+ imports.push(`/* Components */`);
118
+ componentImportsList.forEach((x) => {
119
+ const pascalCase = lodash.camelCase(x.replace("css", "")).toLowerCase();
120
+ cdn
121
+ ? imports.push(toCdn(`${componentDir}/${pascalCase}.css`, version))
122
+ : imports.push(toCssImport(`${componentDir}/${pascalCase}.css`, layers));
123
+ });
124
+ return imports;
125
+ }
126
+ function toCdn(str, version) {
127
+ return `<link rel="preload" href="https://cdn.nav.no/aksel/@navikt/ds-css/${version}/${str
128
+ .replace(".css", ".min.css")
129
+ .replace(`${rootDir}/`, "")}" as="style"></link>`;
130
+ }
131
+ function toCssImport(str, layers) {
132
+ return `@import "@navikt/ds-css/${str}"${layers ? layerSuffix : ""};`;
133
+ }
@@ -0,0 +1,28 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import fg from "fast-glob";
11
+ import path from "path";
12
+ export function getDirectories() {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ const baseDir = process.cwd();
15
+ const ignoreNodeModules = [
16
+ "**/node_modules/**",
17
+ "**/dist/**",
18
+ "**/build/**",
19
+ "**/lib/**",
20
+ ];
21
+ const directories = yield fg(`${baseDir}/**`, {
22
+ onlyDirectories: true,
23
+ ignore: ignoreNodeModules,
24
+ });
25
+ directories.sort((a, b) => a.length - b.length);
26
+ return [baseDir, ...directories].map((x) => x.replace(baseDir, path.basename(baseDir)));
27
+ });
28
+ }
@@ -0,0 +1,22 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import axios from "axios";
11
+ export function getAllVersions() {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ try {
14
+ const npmPackageData = yield axios.get(`https://registry.npmjs.org/@navikt/ds-css`);
15
+ return Object.keys(npmPackageData.data["versions"]);
16
+ }
17
+ catch (e) {
18
+ console.log(e);
19
+ return [];
20
+ }
21
+ });
22
+ }
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env node
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ import { StyleMappings } from "@navikt/ds-css/config/_mappings.js";
12
+ import { generateImportOutput } from "./generate-output.js";
13
+ import { ComponentPrefix } from "./config.js";
14
+ import { inquiry } from "./inquiry.js";
15
+ import { exec } from "child_process";
16
+ import { fileURLToPath } from "url";
17
+ import { dirname } from "path";
18
+ import { getAllVersions } from "./get-version.js";
19
+ import chalk from "chalk";
20
+ import { getDirectories } from "./get-directories.js";
21
+ const __filename = fileURLToPath(import.meta.url);
22
+ const __dirname = dirname(__filename);
23
+ main();
24
+ function main() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ let answers = {
27
+ "config-type": "regular",
28
+ cdn: "no",
29
+ version: "0.0.0",
30
+ autoscan: "no",
31
+ scandir: "",
32
+ tailwind: "no",
33
+ layers: "no",
34
+ imports: null,
35
+ output: "print-clipboard",
36
+ };
37
+ yield inquiry(answers, [
38
+ {
39
+ type: "select",
40
+ name: "config-type",
41
+ message: "Import variants:",
42
+ initial: 0,
43
+ choices: [
44
+ { message: "Regular (recommended)", name: "regular" },
45
+ { message: "Optional defaults + bundled components", name: "easy" },
46
+ { message: "Fine-grained (advanced)", name: "advanced" },
47
+ ],
48
+ },
49
+ {
50
+ type: "select",
51
+ name: "cdn",
52
+ message: "Import format",
53
+ initial: 0,
54
+ choices: [
55
+ { message: "Static import (default)", name: "no" },
56
+ { message: "CDN import (not recommended)", name: "yes" },
57
+ ],
58
+ },
59
+ ]);
60
+ if ((answers === null || answers === void 0 ? void 0 : answers.cdn) === "no") {
61
+ yield inquiry(answers, [
62
+ {
63
+ type: "select",
64
+ name: "tailwind",
65
+ message: "Add tailwind support?",
66
+ initial: 0,
67
+ choices: [
68
+ { message: "No", name: "no" },
69
+ { message: "Yes", name: "yes" },
70
+ ],
71
+ },
72
+ {
73
+ type: "select",
74
+ name: "layers",
75
+ message: "Add styling to custom @layer rule?",
76
+ initial: 0,
77
+ choices: [
78
+ { message: "No", name: "no" },
79
+ { message: "Yes", name: "yes" },
80
+ ],
81
+ },
82
+ ]);
83
+ }
84
+ else {
85
+ let versions = (yield getAllVersions()).filter((x) => !x.includes("-"));
86
+ const index = versions.findIndex((x) => x.startsWith("2.9.0"));
87
+ versions = versions.slice(index).reverse();
88
+ yield inquiry(answers, [
89
+ {
90
+ type: "autocomplete",
91
+ name: "version",
92
+ message: `@navikt/ds-css version from CDN:`,
93
+ limit: 6,
94
+ initial: 0,
95
+ choices: versions,
96
+ footer() {
97
+ 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.');
98
+ },
99
+ },
100
+ ]);
101
+ }
102
+ if (answers["config-type"] === "regular") {
103
+ yield generateImportOutput(answers);
104
+ return;
105
+ }
106
+ answers["config-type"] === "advanced" &&
107
+ (yield inquiry(answers, [
108
+ {
109
+ type: "select",
110
+ name: "autoscan",
111
+ message: "Scan current directory for '@navikt/ds-react' components?",
112
+ initial: 0,
113
+ choices: [
114
+ { message: "No", name: "no" },
115
+ { message: "Yes", name: "yes" },
116
+ ],
117
+ },
118
+ ]));
119
+ answers.autoscan === "yes" &&
120
+ (yield inquiry(answers, [
121
+ {
122
+ type: "autocomplete",
123
+ name: "scandir",
124
+ message: `Directory to scan`,
125
+ limit: 6,
126
+ initial: 0,
127
+ choices: getDirectories(),
128
+ footer() {
129
+ return chalk.grey("filtered out: node_moduels, dist, build, lib, .* (dotfiles)");
130
+ },
131
+ },
132
+ ]));
133
+ let foundComponents = [];
134
+ if (answers["autoscan"] === "yes") {
135
+ foundComponents = yield new Promise((resolve) => {
136
+ exec(`node ${__dirname}/scan-code.js ${answers.scandir}`, (_, stdout) => {
137
+ resolve(stdout ? JSON.parse(stdout.trim().split("\n").slice(1).join("")) : []);
138
+ });
139
+ });
140
+ }
141
+ yield inquiry(answers, [
142
+ {
143
+ type: "multiselect",
144
+ name: "imports",
145
+ message: "Imports",
146
+ initial: [
147
+ ...StyleMappings.baseline.map((x) => x.main.replace(".css", "")),
148
+ ...StyleMappings.components
149
+ .filter((x) => foundComponents.includes(x.component))
150
+ .map((x) => `${ComponentPrefix}${x.component}`),
151
+ ],
152
+ choices: [
153
+ {
154
+ message: "Default-imports",
155
+ name: "default",
156
+ choices: [
157
+ ...StyleMappings.baseline.map((x) => ({
158
+ message: `${x.main.replace(".css", "")}${x.optional ? "" : " (required)"}`,
159
+ name: x.main.replace(".css", ""),
160
+ })),
161
+ ],
162
+ },
163
+ ...(answers["config-type"] === "advanced"
164
+ ? [
165
+ {
166
+ message: "Components",
167
+ name: "components",
168
+ choices: [
169
+ ...StyleMappings.components.map((x) => ({
170
+ message: x.component,
171
+ name: `${ComponentPrefix}${x.component}`,
172
+ })),
173
+ ],
174
+ },
175
+ ]
176
+ : []),
177
+ ],
178
+ },
179
+ ]);
180
+ yield generateImportOutput(answers);
181
+ });
182
+ }
@@ -0,0 +1,28 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Enquirer from "enquirer";
11
+ export function inquiry(answers, questions) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ return yield Enquirer.prompt(questions.map((x) => (Object.assign(Object.assign({}, x), { cancel: () => process.exit(1) }))))
14
+ .then((a) => {
15
+ Object.entries(a).forEach(([key, value]) => {
16
+ answers[key] = value;
17
+ });
18
+ })
19
+ .catch((error) => {
20
+ if (error.isTtyError) {
21
+ console.log("Oops, something went wrong! Looks like @navikt/aksel-cli can't run in this terminal. Contact Aksel");
22
+ }
23
+ else {
24
+ console.error(error);
25
+ }
26
+ });
27
+ });
28
+ }
@@ -0,0 +1,40 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import path from "path";
11
+ import scanner from "react-scanner";
12
+ run();
13
+ function run() {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ yield scanCode();
16
+ });
17
+ }
18
+ function scanCode() {
19
+ var _a;
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const cwd = process.cwd();
22
+ const config = {
23
+ rootDir: cwd,
24
+ crawlFrom: `${(_a = process.argv[2]) !== null && _a !== void 0 ? _a : ""}`.replace(path.basename(cwd), "."),
25
+ globs: ["**/!(*.test|*.spec|*.stories|*.story).@(jsx|tsx)"],
26
+ exclude: (dirname) => dirname === "node_modules",
27
+ getComponentName: ({ imported, moduleName, }) => imported || path.basename(moduleName),
28
+ };
29
+ let result = null;
30
+ yield scanner
31
+ .run(Object.assign(Object.assign({}, config), { importedFrom: /@navikt\/ds-react/, processors: [
32
+ "count-components",
33
+ ({ report }) => {
34
+ result = report;
35
+ },
36
+ ] }))
37
+ .catch(() => null);
38
+ console.log(JSON.stringify(Object.keys(result)));
39
+ });
40
+ }
package/dist/help.js ADDED
@@ -0,0 +1,13 @@
1
+ import chalk from "chalk";
2
+ console.log(`
3
+ ✨ Aksel client-tool
4
+
5
+ 📝 Documentation
6
+ - ${chalk.blueBright("https://github.com/navikt/aksel/blob/main/%40navikt/aksel/README.md")}
7
+
8
+ 💻 Commands:
9
+ - ${chalk.cyan(`npx @navikt/aksel ${chalk.green("css-imports")}`)}
10
+ ✔︎ Helps with adding CSS imports for all Aksel-components
11
+ ✔︎ Supports Static and CDN-imports
12
+ ✔︎ Handles cascading, talwind and @layer rules
13
+ `);
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@navikt/aksel",
3
+ "version": "2.8.16-rc.0",
4
+ "description": "Aksel command line interface. Handles css-imports, codemods (planned) and more",
5
+ "author": "Aksel | NAV designsystem team",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "react",
9
+ "command-line",
10
+ "CLI",
11
+ "css",
12
+ "CDN"
13
+ ],
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "clean": "rimraf dist",
19
+ "build": "yarn clean && tsc -p tsconfig.json",
20
+ "dev": "tsc --watch -p tsconfig.json"
21
+ },
22
+ "bin": {
23
+ "aksel": "./dist/help.js",
24
+ "css-imports": "./dist/css-imports/index.js",
25
+ "help": "./dist/help.js"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/navikt/aksel.git",
30
+ "directory": "@navikt/aksel"
31
+ },
32
+ "type": "module",
33
+ "homepage": "https://aksel.nav.no/grunnleggende/kode/kommandolinje",
34
+ "dependencies": {
35
+ "@navikt/ds-css": "2.8.15",
36
+ "axios": "1.3.6",
37
+ "chalk": "4.1.0",
38
+ "clipboardy": "^3.0.0",
39
+ "enquirer": "^2.3.6",
40
+ "fast-glob": "3.2.11",
41
+ "lodash": "4.17.21",
42
+ "react-scanner": "^1.1.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/inquirer": "^9.0.3",
46
+ "rimraf": "3.0.2",
47
+ "typescript": "^4.8.0"
48
+ },
49
+ "sideEffects": false,
50
+ "engines": {
51
+ "node": ">=16.0.0"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ }
56
+ }