Skip to content

Commit 662e91f

Browse files
Merge pull request #13 from salamaashoush/new-plugin
Split plugins into separate packages
2 parents 3955e58 + 4f86a0b commit 662e91f

File tree

104 files changed

+1072
-287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+1072
-287
lines changed

.changeset/real-moons-teach.md

+9

apps/cli/README.md

+3-69

apps/cli/design-sync.config.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { cssPlugin, defineConfig, jsonPlugin, vanillaExtractPlugin } from '.';
1+
import { cssPlugin } from '@design-sync/css-plugin';
2+
import { jsonPlugin } from '@design-sync/json-plugin';
3+
import { defineConfig } from '@design-sync/manager';
4+
import { vanillaExtractPlugin } from '@design-sync/vanilla-extract-plugin';
25

6+
console.log('dedupe-tokens config');
37
export default defineConfig({
48
uri: 'github:salamaashoush/kda-design-system/tokens#dedupe-tokens',
59
out: 'generated',

apps/cli/package.json

+7-9
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,21 @@
2323
"precommit": "lint-staged"
2424
},
2525
"dependencies": {
26+
"@design-sync/manager": "workspace:*",
2627
"@design-sync/utils": "workspace:*",
2728
"@design-sync/w3c-dtfm": "workspace:*",
28-
"c12": "^1.5.1",
2929
"citty": "^0.1.5",
30-
"consola": "^3.2.3",
31-
"fast-glob": "^3.3.2",
32-
"giget": "^1.1.3"
33-
},
34-
"peerDependencies": {
35-
"prettier": "^3.0.0"
30+
"nypm": "^0.3.3"
3631
},
3732
"devDependencies": {
33+
"@design-sync/css-plugin": "workspace:*",
3834
"@design-sync/eslint-config": "workspace:*",
35+
"@design-sync/json-plugin": "workspace:*",
3936
"@design-sync/tsconfig": "workspace:*",
37+
"@design-sync/vanilla-extract-plugin": "workspace:*",
4038
"@types/node": "^20.9.3",
4139
"@vanilla-extract/css": "^1.14.0",
4240
"@vitest/coverage-v8": "^0.34.6",
43-
"changelogen": "^0.5.5",
4441
"eslint": "^8.54.0",
4542
"prettier": "^3.1.0",
4643
"tsx": "^4.2.0",
@@ -69,5 +66,6 @@
6966
"main": "./dist/index.cjs",
7067
"module": "./dist/index.mjs",
7168
"types": "./dist/index.d.ts"
72-
}
69+
},
70+
"packageManager": "pnpm@8.10.5"
7371
}

apps/cli/src/commands/init.ts

+59-15
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,68 @@
1+
import { logger } from '@design-sync/manager';
2+
import { camelCase } from '@design-sync/utils';
13
import { defineCommand } from 'citty';
24
import { existsSync } from 'fs';
35
import { writeFile } from 'fs/promises';
6+
import { addDevDependency } from 'nypm';
47
import { join } from 'path';
5-
import { ConfigTemplateOptions, generateConfigTemplate } from '../configTemplate';
6-
import { logger } from '../logger';
8+
export interface ConfigTemplateOptions {
9+
out: string;
10+
uri: string;
11+
plugins: string[];
12+
prettify: boolean;
13+
}
14+
15+
export function generateCJSConfigTemplate({ out, uri, plugins, prettify }: ConfigTemplateOptions) {
16+
const pluginImports = plugins.map(
17+
(plugin) => `const ${camelCase(plugin)}Plugin = require('@design-sync/${plugin}-plugin');`,
18+
);
19+
const pluginCalls = plugins.map((plugin) => `${camelCase(plugin)}Plugin()`);
20+
return `const { defineConfig } = require('@design-sync/manager');
21+
${pluginImports.join('\n')}
22+
23+
module.exports = defineConfig({
24+
uri: "${uri}",
25+
out: "${out}",
26+
plugins: [${pluginCalls.join(', ')}],
27+
prettify: ${prettify},
28+
});`;
29+
}
30+
31+
export function generateESMConfigTemplate({ out, uri, plugins, prettify }: ConfigTemplateOptions) {
32+
const pluginImports = plugins.map(
33+
(plugin) => `import { ${camelCase(plugin)}Plugin } from '@design-sync/${plugin}-plugin';`,
34+
);
35+
const pluginCalls = plugins.map((plugin) => `${camelCase(plugin)}Plugin()`);
36+
return `import { defineConfig } from '@design-sync/manager';
37+
${pluginImports.join('\n')}
38+
39+
export default defineConfig({
40+
uri: "${uri}",
41+
out: "${out}",
42+
plugins: [${pluginCalls.join(', ')}],
43+
prettify: ${prettify},
44+
});`;
45+
}
46+
47+
export function generateConfigTemplate(options: ConfigTemplateOptions, isCJS: boolean) {
48+
return isCJS ? generateCJSConfigTemplate(options) : generateESMConfigTemplate(options);
49+
}
750

851
async function configPrompt() {
9-
const repo = await logger.prompt('What is the url of your tokens git repo?', {
52+
const uri = await logger.prompt('What is the uri of your tokens git repo?', {
1053
type: 'text',
1154
placeholder: 'gh:username/repo/path/to/tokens#branch',
1255
default: 'gh:username/repo/path/to/tokens#branch',
1356
});
1457

15-
const tokensPath = await logger.prompt('Where are your tokens located?', {
16-
type: 'text',
17-
placeholder: 'tokens.json',
18-
default: 'tokens.json',
19-
});
20-
2158
const out = await logger.prompt('Where would you like to output your tokens?', {
2259
type: 'text',
2360
placeholder: 'src/design-sync',
2461
default: 'src/design-sync',
2562
});
2663

27-
const plugin = await logger.prompt('Which plugin would you like to use?', {
28-
type: 'select',
64+
const plugins = await logger.prompt('Which plugin would you like to use?', {
65+
type: 'multiselect',
2966
options: [
3067
'vanilla-extract',
3168
// 'styled-components',
@@ -45,7 +82,7 @@ async function configPrompt() {
4582
initial: false,
4683
});
4784

48-
return { repo, tokensPath, out, plugin, prettify };
85+
return { uri, out, plugins, prettify };
4986
}
5087

5188
export default defineCommand({
@@ -68,10 +105,9 @@ export default defineCommand({
68105
},
69106
async run({ args }) {
70107
let config: ConfigTemplateOptions = {
71-
repo: 'gh:username/repo/path/to/tokens#branch',
108+
uri: 'gh:username/repo/path/to/tokens#branch',
72109
out: 'src/design-sync',
73-
tokensPath: 'tokens.json',
74-
plugin: 'vanilla-extract',
110+
plugins: ['json'],
75111
prettify: false,
76112
};
77113

@@ -81,6 +117,14 @@ export default defineCommand({
81117
const isCJS = typeof require !== 'undefined';
82118
const isTypescript = existsSync(`${args.cwd}/tsconfig.json`);
83119
const template = generateConfigTemplate(config, isCJS);
120+
121+
const deps = ['@design-sync/cli', ...config.plugins.map((plugin) => `@design-sync/${plugin}-plugin`)];
122+
logger.start(`Installing dependencies ${deps.join(', ')} ...`);
123+
for (const dep of deps) {
124+
await addDevDependency(dep, { cwd: args.cwd });
125+
}
126+
logger.success('Dependencies installed');
127+
84128
const configPath = isTypescript ? 'design-sync.config.ts' : 'design-sync.config.js';
85129
await writeFile(join(args.cwd, configPath), template);
86130
logger.success(`Config file created at ${configPath}`);

apps/cli/src/commands/sync.ts

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1+
import { TokensManager, logger } from '@design-sync/manager';
12
import { defineCommand } from 'citty';
2-
import { resolveConfig } from '../config';
3-
import { fetchTokens } from '../fetch';
4-
import { logger } from '../logger';
5-
import { TokensManager } from '../manager';
63

74
export default defineCommand({
85
meta: {
@@ -38,19 +35,9 @@ export default defineCommand({
3835
},
3936
},
4037
async run({ args }) {
41-
const config = await resolveConfig(args);
42-
const tokensManager = new TokensManager(config);
43-
const { uri, auth, plugins = [] } = config;
44-
for (const plugin of plugins) {
45-
logger.info(`Loading plugin ${plugin.name}`);
46-
tokensManager.use(plugin);
47-
}
48-
38+
const tokensManager = new TokensManager();
4939
try {
50-
const tokensObj = await fetchTokens(uri, auth);
51-
logger.start('Processing tokens...');
52-
await tokensManager.run(tokensObj);
53-
logger.success('Tokens processed successfully.');
40+
await tokensManager.run(args);
5441
} catch (error) {
5542
// eslint-disable-next-line no-console
5643
logger.error(error);

apps/cli/src/configTemplate.ts

-38
This file was deleted.

apps/cli/src/index.ts

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
1-
import type { DesignSyncConfig } from './types';
2-
3-
export * from './fetch';
4-
export * from './logger';
5-
export * from './manager';
6-
export * from './plugins';
7-
export * from './types';
8-
export * from './utils';
9-
10-
export function defineConfig(config: Partial<DesignSyncConfig>) {
11-
return config;
12-
}
1+
export {};

apps/cli/src/plugins/index.ts

-3
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

apps/new-plugin/src/components/SelectInput.tsx apps/figma-plugin/src/components/SelectInput.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Dropdown, DropdownOption, Text } from '@create-figma-plugin/ui';
22
import { h } from 'preact';
3-
import { FormField } from './FormField';
3+
import { FormField } from './FormField.tsx';
44
import { errorStyle } from './formField.css.ts';
55

66
interface SelectInputProps {

apps/new-plugin/src/components/TextInput.tsx apps/figma-plugin/src/components/TextInput.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Text, Textbox } from '@create-figma-plugin/ui';
22
import { ReadonlySignal } from '@preact/signals';
33
import { JSX, Ref, h } from 'preact';
44
import { forwardRef } from 'preact/compat';
5-
import { FormField } from './FormField';
5+
import { FormField } from './FormField.tsx';
66
import { errorStyle } from './formField.css.ts';
77

88
interface TextInputProps {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

apps/new-plugin/src/screens/Settings/RemoteStorageCard/RemoteStorageCard.tsx apps/figma-plugin/src/screens/Settings/RemoteStorageCard/RemoteStorageCard.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Bold, IconAdjust32, IconButton, IconTrash32, Text } from '@create-figma-plugin/ui';
22
import { h } from 'preact';
3-
import { Box } from '../../../components/Box';
3+
import { Box } from '../../../components/Box.tsx';
44
import { remoteStorageCard } from './remoteStorageCard.css.ts';
55

66
interface RemoteStorageCardProps {
File renamed without changes.
File renamed without changes.
File renamed without changes.

packages/css-plugin/.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
coverage
3+
dist

packages/css-plugin/.eslintrc.cjs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@design-sync/eslint-config/node',
4+
};

packages/css-plugin/.lintstagedrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
// eslint
3+
'src/**/*.{js,jsx,ts,tsx}': ' eslint',
4+
5+
// tsc
6+
'src/**/*.{ts,tsx}': () => 'tsc',
7+
};

packages/css-plugin/CHANGELOG.md

0 commit comments

Comments
 (0)