Skip to content

Commit

Permalink
Separate into packages (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
gossi authored Jul 7, 2023
1 parent bafd1ea commit 4ed6c34
Show file tree
Hide file tree
Showing 135 changed files with 87,423 additions and 4,372 deletions.
70 changes: 16 additions & 54 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,30 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup Tools
uses: volta-cli/action@v1
- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/[email protected]
with:
version: latest
- uses: wyvox/action@v1
- run: pnpm build
- run: pnpm build:fixtures
- run: pnpm lint

- run: pnpm install
- run: pnpm --filter 'theemo' lint
# build:
# runs-on: ubuntu-latest

# steps:
# - uses: wyvox/action@v1
# - run: pnpm build

test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x]

# needs: build
steps:
- uses: actions/checkout@v3
- name: Setup Tools
uses: volta-cli/action@v1
- uses: wyvox/action@v1
with:
node-version: ${{ matrix.node-version }}
- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/[email protected]
with:
version: latest

- run: pnpm install
- run: pnpm --filter 'theemo' test

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup Tools
uses: volta-cli/action@v1
- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/[email protected]
with:
version: latest

- run: pnpm install
- run: pnpm -r --parallel build
- run: pnpm --filter 'theemo' dts
- run: pnpm build
- run: pnpm build:fixtures
- run: pnpm --filter '@theemo/*' test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
.eslintcache
.env
node_modules/
coverage/
coverage/
dist/
.turbo/
4 changes: 4 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#public-hoist-pattern[]=*prettier*
#public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*prettier*
public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*ember-template-lint*
public-hoist-pattern[]=*stylelint*
strict-peer-dependencies=false
15 changes: 14 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
{
"typescript.preferences.importModuleSpecifier": "relative"
"typescript.preferences.importModuleSpecifier": "relative",
"eslint.workingDirectories": [
// problem with glob, doesn't work with `prettier/prettier` - wants me to
// use trailing comma, dafuq no!
// "packages/@theemo/*",
"packages/@theemo/cli",
"packages/@theemo/core",
"packages/@theemo/figma",
"packages/@theemo/sync",
"packages/@theemo/style-dictionary",
"packages/@theemo/theme",
"packages/theemo",
"testing/fixtures"
]
}
41 changes: 38 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,43 @@
"node": "18.13.0"
},
"scripts": {
"test": "pnpm run --filter theemo test",
"coverage": "pnpm run --filter theemo coverage",
"api": "pnpm run --filter theemo api"
"clean": "concurrently 'npm:clean:*'",
"clean:dist": "find . -not \\( -path './node_modules' -type d -prune \\) -name 'dist' -type d -exec rm -rf '{}' +",
"clean:node-modules": "find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +",
"clean:turbo": "find . -name '.turbo' -type d -prune -exec rm -rf '{}' +",
"_start": "turbo run --parallel --filter='@theemo/*' start",
"start": "pnpm run --parallel --filter='@theemo/*' start",
"test": "pnpm run --filter '@theemo/*' test",
"_coverage": "pnpm run --filter theemo coverage",
"_api": "pnpm run --filter theemo api",
"lint": "pnpm --filter '@theemo/*' lint",
"build": "pnpm run build:core && pnpm run build:sync && pnpm run build:figma && pnpm run build:style-dictionary && pnpm run build:cli",
"build:core": "pnpm run --filter='@theemo/core' build",
"build:sync": "pnpm run --filter='@theemo/sync' build",
"build:figma": "pnpm run --filter='@theemo/figma' build",
"build:style-dictionary": "pnpm run --filter='@theemo/style-dictionary' build",
"build:cli": "pnpm run --filter='@theemo/cli' build",
"build:fixtures": "pnpm run --filter='@theemo/fixtures' build",
"__build": "pnpm run --filter='@theemo/*' --filter='!@theemo/fixtures' --filter='!@theemo/theme' build",
"_build": "pnpm run --parallel --filter='@theemo/*' build"
},
"devDependencies": {
"@release-it-plugins/workspaces": "^3.2.0",
"concurrently": "^8.2.0",
"turbo": "^1.10.7",
"release-it": "^15.11.0"
},
"release-it": {
"plugins": {
"@release-it-plugins/workspaces": {
"workspaces": [
"packages/@theemo"
]
}
},
"git": {
"requireCleanWorkingDir": false,
"changelog": false
}
}
}
2 changes: 2 additions & 0 deletions packages/@theemo/cli/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
18 changes: 18 additions & 0 deletions packages/@theemo/cli/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const { configs } = require('@gossi/config-eslint');

const config = configs.nodeESM();

module.exports = {
...config,
overrides: [
...config.overrides,
{
files: ['**/*.ts'],
rules: {
'n/no-missing-import': 0
}
}
]
};
3 changes: 3 additions & 0 deletions packages/@theemo/cli/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('@gossi/config-prettier');
16 changes: 16 additions & 0 deletions packages/@theemo/cli/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"sourceMaps": true,
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": false,
"dynamicImport": true
},
"target": "es2019",
"loose": true
},
"module": {
"type": "es6"
}
}
4 changes: 4 additions & 0 deletions packages/@theemo/cli/bin/theemo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

// eslint-disable-next-line import/no-unassigned-import, n/no-missing-import
import '../dist/cli.js';
64 changes: 64 additions & 0 deletions packages/@theemo/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "@theemo/cli",
"version": "0.0.1",
"description": "Theemo CLI",
"license": "MIT",
"author": "Thomas Gossmann",
"homepage": "https://theemo.io",
"bugs": "https://github.com/theemo-tokens/theemo/issues",
"repository": "https://github.com/theemo-tokens/theemo",
"publishConfig": {
"access": "public"
},
"keywords": [
"design system",
"theme",
"design tokens"
],
"type": "module",
"bin": {
"theemo": "bin/theemo.js"
},
"files": [
"dist",
"bin",
"package.json"
],
"typings": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./package.json": "./package.json"
},
"scripts": {
"build": "concurrently -r 'npm:build:*'",
"build:js": "swc ./src -d ./dist",
"build:types": "tsc --emitDeclarationOnly",
"lint": "concurrently -g 'npm:lint:*(!fix)'",
"lint:fix": "concurrently -g 'npm:lint:*:fix'",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:types": "tsc --noEmit",
"start": "concurrently -r 'npm:start:*'",
"start:js": "swc ./src -d ./dist -w",
"start:types": "tsc --emitDeclarationOnly -w"
},
"dependencies": {
"@theemo/sync": "workspace:*",
"commander": "^11.0.0",
"cosmiconfig": "^8.2.0",
"dotenv": "^16.3.1",
"read-pkg-up": "^10.0.0",
"esm": "^3.2.25"
},
"devDependencies": {
"@gossi/config-eslint": "^0.4.0",
"@gossi/config-prettier": "^0.4.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.67",
"@types/node": "^20.3.3",
"concurrently": "^8.2.0",
"eslint": "^8.44.0",
"prettier": "^2.8.5",
"typescript": "^5.1.6"
}
}
88 changes: 88 additions & 0 deletions packages/@theemo/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import path from 'node:path';
import { argv } from 'node:process';
import { fileURLToPath } from 'node:url';

import { Command } from 'commander';
import { cosmiconfig } from 'cosmiconfig';
import dotenv from 'dotenv';
import { readPackageUp } from 'read-pkg-up';

import Theemo from './theemo.js';

import type { TheemoConfig } from './config.js';

dotenv.config();

async function loadPackage() {
// eslint-disable-next-line @typescript-eslint/naming-convention
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const foundPkg = await readPackageUp({ cwd: __dirname });

if (foundPkg) {
return foundPkg.packageJson;
}

return undefined;
}

async function loadConfig(program: Command): Promise<TheemoConfig | undefined> {
const explorer = cosmiconfig('theemo', {
searchPlaces: [
`.theemorc.js`,
`.theemorc.cjs`,
`.theemorc.mjs`,
`.config/theemorc.js`,
`.config/theemorc.cjs`,
`.config/theemorc.mjs`,
`theemo.config.js`,
`theemo.config.cjs`,
`theemo.config.mjs`
]
});
const result = await explorer.search();

if (result === null) {
return program.error(
'Cannot find config for theemo. Please provide a config for theemo to function properly'
);
}

return result.config as TheemoConfig;
}

export async function cli() {
// setup program
const program = new Command();
const pkg = await loadPackage();

if (pkg) {
program.version(pkg.version).name(pkg.name);
}

program.usage('command');

program
.command('sync')
.description('sync from your source into your token manager tool')
.action(async () => {
// config
const config = await loadConfig(program);

if (config) {
const theemo = new Theemo(config);

await theemo.sync();
}
});

// program
// .command('generate')
// .description('generates an adaptive CSS theme file')
// .action(() => {
// theemo.generate();
// });

program.parse(argv);
}

cli();
16 changes: 16 additions & 0 deletions packages/@theemo/cli/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { SyncConfig } from '@theemo/sync';

/**
* The main config to control all commands for theemo:
*
* - `sync`
* - `build`
*/
export interface TheemoConfig {
/** Config for the sync command */
sync?: SyncConfig;
}

export function defineConfig(config: TheemoConfig) {
return config;
}
1 change: 1 addition & 0 deletions packages/@theemo/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { defineConfig } from './config.js';
Loading

0 comments on commit 4ed6c34

Please sign in to comment.