♻️(typescript) move tokens sources to absolute import

Relatives import are quite ugly and reduces readability, but
hard to say that Typescript handles it very well for compilation
time, but nothing for runtime. That's why I had to add tsc-alias
to the build script. Please see this issue for more details.
https://github.com/Microsoft/TypeScript/issues/15479
Furthermore, some configuration was needed for Jest to work well.
This commit is contained in:
Nathan Vasse
2022-12-30 12:12:04 +01:00
committed by NathanVss
parent 7a61402d4e
commit 3e98429d04
9 changed files with 55 additions and 16 deletions

View File

@@ -1,4 +1,9 @@
export default {
import type { JestConfigWithTsJest } from "ts-jest";
const jestConfig: JestConfigWithTsJest = {
preset: "ts-jest",
testEnvironment: "node",
moduleDirectories: ["node_modules", "src/bin"],
};
export default jestConfig;

View File

@@ -15,7 +15,7 @@
"scripts": {
"lint": "eslint . 'src/**/*.{ts,tsx}'",
"dev": "nodemon --watch 'src/bin' --ext '*' --exec 'yarn build'",
"build": "tsc -p tsconfig.json && cp src/bin/cunningham.dist.js dist/bin && chmod +x dist/bin/Main.js && yarn build-default-theme",
"build": "tsc -p tsconfig.json && tsc-alias && cp src/bin/cunningham.dist.js dist/bin && chmod +x dist/bin/Main.js && yarn build-default-theme",
"build-default-theme": "./dist/bin/Main.js -o dist -s html",
"test": "FORCE_COLOR=1 jest --verbose src/bin/tests"
},
@@ -23,7 +23,8 @@
"chalk": "4.1.2",
"commander": "9.4.1",
"deepmerge": "4.2.2",
"figlet": "1.5.2"
"figlet": "1.5.2",
"tsc-alias": "^1.8.2"
},
"devDependencies": {
"@types/figlet": "1.5.5",

View File

@@ -1,9 +1,9 @@
import path from "path";
import * as fs from "fs";
import deepmerge from "deepmerge";
import { ConfigShape } from "TokensGenerator";
import { workPath } from "Paths";
import Config from "./Config";
import { ConfigShape } from "./TokensGenerator";
import { workPath } from "./Paths";
const getLocalConfig = async () => {
const filename = Config.configurationFilenames

View File

@@ -1,8 +1,8 @@
import * as path from "path";
import * as fs from "fs";
import chalk from "chalk";
import Config from "./Config";
import { flatify } from "./Utils/Flatify";
import { flatify } from "Utils/Flatify";
import Config from "Config";
export const cssGenerator = async (
tokens: any,

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env node
import { run } from "./ThemeGenerator";
import { run } from "ThemeGenerator";
run(process.argv);

View File

@@ -1,10 +1,10 @@
import { program } from "commander";
import chalk from "chalk";
import figlet from "figlet";
import { getConfig } from "./ConfigLoader";
import { tokensGenerator } from "./TokensGenerator";
import { cssGenerator } from "./CssGenerator";
import { workPath } from "./Paths";
import { cssGenerator } from "Generators/CssGenerator";
import { getConfig } from "ConfigLoader";
import { tokensGenerator } from "TokensGenerator";
import { workPath } from "Paths";
export const buildTheme = async () => {
const options = program.opts();

View File

@@ -1,6 +1,6 @@
import * as fs from "fs";
import * as path from "path";
import { run } from "../ThemeGenerator";
import { run } from "ThemeGenerator";
import Config from "../Config";
jest.mock("../Paths", () => ({

View File

@@ -5,6 +5,10 @@
],
"compilerOptions": {
"baseUrl": "./src/bin",
"paths": {
"*": ["*"]
},
"resolveJsonModule": true,
"outDir": "./dist/bin",
}
}