Skip to content

Commit

Permalink
Allow components to be imported & migrate to unbuild (#21)
Browse files Browse the repository at this point in the history
* Reorganize component system

Small improvements to the component system:
- Components in their own file
- Renamed `content` to `body` for clarity
- Moved generation logic to `tracker.ts` file

* Fix Vitepress example not ignoring Spanish files

* Fix dashboard generation by removing `null` usage

* Improve TypeScript bundling

* Move package building to `unbuild`

* Create calm-pumas-rhyme.md
  • Loading branch information
yanthomasdev authored Oct 29, 2023
1 parent 7dbcd3a commit 06f5f4c
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 312 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-pumas-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lunariajs/core": patch
---

Allow components to be imported
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"private": true,
"version": "1.0.0",
"scripts": {
"dev:docs": "pnpm --filter lunaria-docs dev",
"dev:core": "pnpm --filter @lunariajs/core dev",
"docs": "pnpm --filter lunaria-docs dev",
"build": "pnpm run build:core",
"build:core": "pnpm --filter @lunariajs/core build",
"lint": "pnpm run lint:core",
Expand Down
14 changes: 14 additions & 0 deletions packages/core/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineBuildConfig } from 'unbuild';

export default defineBuildConfig({
clean: true,
declaration: true,
sourcemap: true,
rollup: {
emitCJS: true,
inlineDependencies: true,
esbuild: {
minify: true,
},
},
});
25 changes: 17 additions & 8 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"type": "module",
"version": "0.0.0",
"description": "Translation management system for open-source projects",
"main": "./dist/index.js",
"module": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
Expand All @@ -13,8 +13,18 @@
"default": "./dist/index.cjs"
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
},
"./components": {
"require": {
"types": "./dist/dashboard/components.d.cts",
"default": "./dist/dashboard/components.cjs"
},
"import": {
"types": "./dist/dashboard/components.d.mts",
"default": "./dist/dashboard/components.mjs"
}
}
},
Expand All @@ -37,15 +47,14 @@
},
"bugs": "https://github.com/Yan-Thomas/lunaria/issues",
"scripts": {
"build": "tsup src/index.ts --format esm,cjs --dts",
"dev": "tsup src/index.ts --watch",
"build": "unbuild",
"lint": "tsc"
},
"devDependencies": {
"@types/micromatch": "^4.0.3",
"@types/node": "^20.8.9",
"tsup": "^7.2.0",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"unbuild": "^2.0.0"
},
"dependencies": {
"fast-glob": "^3.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/dashboard/components.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { html } from 'lit-html';
import {
import type {
Dashboard,
FileTranslationStatus,
Locale,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import run from './tracker';
import { LunariaConfigSchema, LunariaUserConfig } from './utils/config';
import { LunariaConfigSchema, type LunariaUserConfig } from './utils/config';
import { handleShallowRepo } from './utils/git';

export { html } from 'lit-html';
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import micromatch from 'micromatch';
import { dirname, extname, join, resolve } from 'path';
import { rehype } from 'rehype';
import rehypeFormat from 'rehype-format';
import { DefaultLogFields, ListLogLine } from 'simple-git';
import type { DefaultLogFields, ListLogLine } from 'simple-git';
import { Page } from './dashboard/components';
import {
import type {
AugmentedFileData,
DictionaryObject,
FileContentIndex,
Expand All @@ -16,7 +16,7 @@ import {
LunariaConfig,
RegExpGroups,
} from './types';
import { SharedPathResolver } from './utils/config';
import type { SharedPathResolver } from './utils/config';
import { getGitHostingUrl, getPageHistory } from './utils/git';
import {
getFrontmatterFromFile,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TemplateResult } from 'lit-html';
import { LunariaConfig } from './utils/config';
import type { TemplateResult } from 'lit-html';
import type { LunariaConfig } from './utils/config';

export { Dashboard, Locale, LunariaConfig, SharedPathResolver } from './utils/config';
export type { Dashboard, Locale, LunariaConfig, SharedPathResolver } from './utils/config';

export type AugmentedFileData = FileData & AdditionalContentData;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod';
import { CustomComponent, CustomStatusComponent } from '../types';
import type { CustomComponent, CustomStatusComponent } from '../types';

function createComponentSchema<ComponentType extends CustomComponent | CustomStatusComponent>() {
return z.custom<ComponentType>((val) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fs from 'fs';
import os from 'os';
import { join, resolve } from 'path';
import { simpleGit } from 'simple-git';
import { GitHostingUrl } from '../types';
import { LunariaConfig } from './config';
import type { GitHostingUrl } from '../types';
import type { LunariaConfig } from './config';

const git = simpleGit({
maxConcurrentProcesses: Math.max(2, Math.min(32, os.cpus().length)),
Expand Down
Loading

0 comments on commit 06f5f4c

Please sign in to comment.