Skip to content

Commit

Permalink
refactor: architecture (#275)
Browse files Browse the repository at this point in the history
Co-authored-by: Almanov Nikita <131481562+nikkeyl@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and nikkeyl authored Sep 23, 2024
1 parent 951ab53 commit 14c6844
Show file tree
Hide file tree
Showing 24 changed files with 55 additions and 67 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
},
"type": "module",
"imports": {
"#app": "./src/app/index.ts",
"#at-rule-parameters": "./src/features/at-rule/parameters.ts",
"#entities/*": "./src/entities/*",
"#features/*": "./src/features/*",
"#features": "./src/features/index.ts",
"#rule-parameters": "./src/features/rule/parameters.ts",
"#shared/*": "./src/shared/*"
"#shared": "./src/shared/index.ts"
},
"exports": {
".": "./index.js"
Expand Down
7 changes: 3 additions & 4 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import typescript from '@rollup/plugin-typescript';
const sourceFolder = 'src';

const fileFormat = 'es';
const entryFileName = 'app';
const outputFileName = 'index';
const fileName = 'index';

const entryFile = `${entryFileName}.ts`;
const outputFile = `${outputFileName}.js`;
const entryFile = `${fileName}.ts`;
const outputFile = `${fileName}.js`;

export default defineConfig([
{
Expand Down
31 changes: 16 additions & 15 deletions specs/features/at-rule.spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import { beforeEach, describe, expect, test as spec } from 'vitest';

import { createAtRule } from '#features/at-rule/at-rule.ts';
import { createAtRule } from '#features';

import type { Parameters } from '#at-rule-parameters';

describe('Create At Rule', () => {
describe('Create At Rule', async () => {
let atRule: Function;

beforeEach(() => {
const addAtRule = async (parameters: Parameters) => {
beforeEach(async () => {
atRule = async (parameters: Parameters) => {
const { name, hasBlock } = parameters;

return await createAtRule({ name, hasBlock }).then((parameters) => {
expect(parameters.name).equal(name);
expect(parameters.hasBlock).equal(hasBlock);
expect(parameters.type).equal('at-rule');
});
};
const result = await createAtRule({ name, hasBlock });

atRule = addAtRule;
expect(result.name).toBeTypeOf('string');
expect(result.hasBlock).toBeTypeOf('boolean');
expect(result.type).toEqual('at-rule');

return result;
};
});

spec('create an object with (name: String, hasBlock: true)', async () => {
return await atRule({ name: 'test-rule', hasBlock: true });
spec('should create an object with a block', async () => {
await atRule({ name: 'test-rule-1', hasBlock: true });
});

spec('create an object with (name: String, hasBlock: false)', async () => {
return await atRule({ name: 'test-rule', hasBlock: false });
spec('should create an object without a block', async () => {
await atRule({ name: 'test-rule-2', hasBlock: false });
});
});
2 changes: 1 addition & 1 deletion specs/features/logical-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test as spec } from 'vitest';

import { createLogicalGroup } from '#features/logical-group/logical-group.ts';
import { createLogicalGroup } from '#features';

describe('Create Logical Group', () => {
spec('create an object with (groupName: String, properties: [])', async () => {
Expand Down
43 changes: 12 additions & 31 deletions specs/features/rule.spec.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,26 @@
import { beforeEach, describe, expect, test as spec } from 'vitest';

import { createRule } from '#features/rule/rule.ts';
import { createRule } from '#features';

import type { Parameters } from '#rule-parameters';

describe('Create Rule', () => {
describe('Create Rule', async () => {
let rule: Function;

beforeEach(() => {
const addRule = async (parameters: Parameters) => {
beforeEach(async () => {
rule = async (parameters: Parameters) => {
const { selector } = parameters;

return await createRule({ selector }).then((parameters) => {
expect(parameters.selector).equal(`&${selector}`);
expect(parameters.type).equal('rule');
});
};

rule = addRule;
});

spec('create an object with (::pseudo-element)', async () => {
return await rule({ selector: '::pseudo-element' });
});

spec('create an object with (:pseudo-class)', async () => {
return await rule({ selector: ':pseudo-class' });
});

spec('create an object with (?\\[(.*)\\])', async () => {
return await rule({ selector: '?\\[(.*)\\]' });
});
const result = await createRule({ selector });

spec('create an object with (?\\.(.*))', async () => {
return await rule({ selector: '?\\.(.*)' });
});
expect(result.selector).toEqual(`&${selector.replace(/^&+/g, '')}`);
expect(result.type).toEqual('rule');

spec('create an object with (--)', async () => {
return await rule({ selector: '--' });
return result;
};
});

spec('create an object with (__)', async () => {
return await rule({ selector: '__' });
spec('should create an object with selector', async () => {
await rule({ selector: '&&&any-nested-css-selector' });
});
});
2 changes: 1 addition & 1 deletion specs/regex/bem-regex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test as spec } from 'vitest';

import { CSSRules } from '#entities/rules/css.ts';
import { CSSRules } from '#app';

describe('BEM Class Regex', () => {
const BEMClassRegex = new RegExp(CSSRules['selector-class-pattern'][0] as string);
Expand Down
3 changes: 3 additions & 0 deletions src/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { CSSRules, SCSSRules } from './rules/index.ts';
export { propertiesOrder } from './properties/index.ts';
export { plugins } from './plugins.ts';
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/app/properties/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { propertiesOrder } from './order.ts';
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { selectors } from '@archoleat/reglib';

import { createAtRule } from '#features/at-rule/at-rule.ts';
import { createLogicalGroup } from '#features/logical-group/logical-group.ts';
import { createRule } from '#features/rule/rule.ts';
import { createAtRule, createLogicalGroup, createRule } from '#features';

import { deprecated } from './deprecated.ts';
import { experimental } from './experimental.ts';
Expand All @@ -25,7 +23,7 @@ const limitedAvailabilityProperty = limitedAvailability.property;
const nonStandardProperty = nonStandard.property;
const warningProperty = warning.property;

const properties = {
const propertiesOrder = {
'order/order': [
'custom-properties',
'dollar-variables',
Expand Down Expand Up @@ -820,4 +818,4 @@ const properties = {
],
};

export { properties };
export { propertiesOrder };
File renamed without changes.
2 changes: 1 addition & 1 deletion src/entities/rules/css.ts → src/app/rules/css.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { selectors } from '@archoleat/reglib';

import { messages } from '#shared/messages.ts';
import { messages } from '#shared';

const BLOCK = selectors.bem.BLOCK_REGEX;
const ELEMENT = selectors.bem.ELEMENT_REGEX;
Expand Down
2 changes: 2 additions & 0 deletions src/app/rules/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { CSSRules } from './css.ts';
export { SCSSRules } from './scss.ts';
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/features/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { createAtRule } from './at-rule/index.ts';
export { createLogicalGroup } from './logical-group/index.ts';
export { createRule } from './rule/index.ts';
File renamed without changes.
4 changes: 3 additions & 1 deletion src/features/rule/rule.ts → src/features/rule/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import type { Parameters } from './parameters.ts';
const createRule = async (parameters: Parameters) => {
const { selector } = parameters;

const cleanSelector = selector.replaceAll(/^&+/g, '');

return {
type: 'rule',
selector: `&${selector}`,
selector: `&${cleanSelector}`,
};
};

Expand Down
7 changes: 2 additions & 5 deletions src/app.ts → src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { CSSRules } from '#entities/rules/css.ts';
import { SCSSRules } from '#entities/rules/scss.ts';
import { plugins } from '#entities/plugins.ts';
import { properties } from '#entities/properties/properties.ts';
import { CSSRules, SCSSRules, propertiesOrder, plugins } from '#app';

export default {
extends: ['stylelint-config-standard-scss', 'stylelint-prettier/recommended'],
Expand All @@ -18,7 +15,7 @@ export default {
],
rules: {
...plugins,
...properties,
...propertiesOrder,
...CSSRules,
...SCSSRules,
},
Expand Down
1 change: 1 addition & 0 deletions src/shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { messages } from './messages.ts';

0 comments on commit 14c6844

Please sign in to comment.