Skip to content

Commit cc75826

Browse files
authored
add: Solid JS Scaffolding Support (#249)
1 parent 43bb3c8 commit cc75826

16 files changed

+112
-29
lines changed

.github/workflows/release.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
21
name: CD
32

43
on:
54
release:
65
types: [created]
76

87
jobs:
9-
build:
8+
Build:
109
runs-on: ubuntu-latest
1110
steps:
1211
- uses: actions/checkout@v3
@@ -17,7 +16,7 @@ jobs:
1716
- run: npm run lint
1817
- run: npm run coverage
1918

20-
publish-npm:
19+
Publish:
2120
needs: build
2221
runs-on: ubuntu-latest
2322
steps:

.github/workflows/test.yaml

+13-14
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@ name: CI
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: ["main"]
66
pull_request:
7-
branches: [ "main" ]
7+
branches: ["main"]
88

99
jobs:
10-
build:
11-
10+
Build:
1211
runs-on: ubuntu-latest
1312

1413
strategy:
1514
matrix:
1615
node-version: [16.x]
1716

1817
steps:
19-
- uses: actions/checkout@v3
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v3
22-
with:
23-
node-version: ${{ matrix.node-version }}
24-
cache: 'npm'
25-
- run: npm ci
26-
- run: npm run lint
27-
- run: npm run coverage
28-
- run: npm run build
18+
- uses: actions/checkout@v3
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
cache: "npm"
24+
- run: npm ci
25+
- run: npm run lint
26+
- run: npm run coverage
27+
- run: npm run build

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Below commands will install the `@latest` versions of the respective frameworks.
4343
| Svelte Kit | `npx twify@latest create svelte <my-app>` |
4444
| Laravel Vite | `npx twify@latest create laravel <my-app>` |
4545
| Vite | `npx twify@latest create vite <my-app>` |
46+
| Solid Start | `npx twify@latest create solid <my-app>` |
4647
| Angular | `npx twify@latest create angular <my-app>` |
4748
| Create React App | `npx twify@latest create react <my-app>` |
4849

@@ -111,7 +112,7 @@ Below are the list of Supported Projects,
111112
| Vite | :white_check_mark: | :white_check_mark: |
112113
| Angular | :white_check_mark: | :white_check_mark: |
113114
| Create React App | :white_check_mark: | :white_check_mark: |
114-
| Solid JS | :o: WIP | :o: WIP |
115+
| Solid JS | :white_check_mark: | :white_check_mark: |
115116
| Astro | :o: WIP | :o: WIP |
116117
| Qwik | :o: WIP | :o: WIP |
117118

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "twify",
3-
"version": "0.4.3",
3+
"version": "0.5.0",
44
"description": "A Tool to Setup TailwindCSS in your Project with a Single Command",
55
"bin": {
66
"twify": "dist/main.js"

src/drivers.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export const drivers = {
1010
Angular: (): DriverImport => import('./frameworks/angular'),
1111
CreateReactApp: (): DriverImport => import('./frameworks/cra'),
1212
LaravelVite: (): DriverImport => import('./frameworks/laravel'),
13+
Solid: (): DriverImport => import('./frameworks/solid'),
1314
};

src/frameworks/solid.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Framework } from '../types';
2+
import { resolveCssLocation } from './steps/solid';
3+
4+
const Solid: Framework = {
5+
requiredDependencies: ['tailwindcss', 'postcss', 'autoprefixer'],
6+
initCommands: ['npx tailwindcss init -p'],
7+
cssLocation: resolveCssLocation,
8+
content: ['./src/**/*.{js,jsx,ts,tsx}'],
9+
steps: [],
10+
};
11+
12+
export default Solid;

src/frameworks/steps/next.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import glob from 'glob';
22
import util from 'util';
33

44
export async function resolveCssLocation() {
5-
const [match] = await util.promisify(glob)('./**/globals.css');
5+
const [match] = await util.promisify(glob)('./**/globals.css', {
6+
ignore: ['node_modules'],
7+
});
68

79
if (!match) {
810
return './styles/globals.css';

src/frameworks/steps/solid.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import glob from 'glob';
2+
import util from 'util';
3+
4+
export async function resolveCssLocation() {
5+
const [match] = await util.promisify(glob)('./src/**/root.css', {
6+
ignore: ['node_modules'],
7+
});
8+
9+
if (!match) {
10+
return './src/index.css';
11+
}
12+
13+
return match;
14+
}

src/helpers.ts

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function detectFramework(): Driver | undefined {
3939
if (dependencies['nuxt']) return 'Nuxt2';
4040
if (dependencies['@angular/core']) return 'Angular';
4141
if (dependencies['react-scripts']) return 'CreateReactApp';
42+
if (dependencies['solid-js']) return 'Solid';
4243
if (devDependencies['laravel-vite-plugin']) return 'LaravelVite';
4344
if (devDependencies['@sveltejs/kit']) return 'SvelteKit';
4445
if (devDependencies['nuxt']) return 'Nuxt3';

src/makers.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { runCommand } from './helpers';
2-
import { PackageManager } from './types';
3-
import { drivers } from './drivers';
2+
import { Driver, PackageManager } from './types';
43

5-
export type Maker = { cmd: string; project: keyof typeof drivers };
4+
export type Maker = { cmd: string; project: Driver };
65
export type SpecialMaker = (packageManager: PackageManager) => Promise<Maker>;
76

87
const globalInstallPrefix: Record<PackageManager, string> = {
@@ -38,6 +37,7 @@ const regularMakes: Record<string, Maker> = {
3837
next: { cmd: 'next-app', project: 'NextJS' },
3938
react: { cmd: 'react-app', project: 'CreateReactApp' },
4039
nuxt: { cmd: 'nuxt-app', project: 'Nuxt2' },
40+
solid: { cmd: 'solid', project: 'Solid' },
4141
};
4242

4343
export async function resolveMakeCommand(args: string[]): Promise<Maker> {

tests/__snapshots__/drivers.spec.ts.snap

+18
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,21 @@ exports[`Drivers > has a list of drivers 9`] = `
189189
],
190190
}
191191
`;
192+
193+
exports[`Drivers > has a list of drivers 10`] = `
194+
{
195+
"content": [
196+
"./src/**/*.{js,jsx,ts,tsx}",
197+
],
198+
"cssLocation": [Function],
199+
"initCommands": [
200+
"npx tailwindcss init -p",
201+
],
202+
"requiredDependencies": [
203+
"tailwindcss",
204+
"postcss",
205+
"autoprefixer",
206+
],
207+
"steps": [],
208+
}
209+
`;

tests/drivers.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('Drivers', () => {
1313
'Angular',
1414
'CreateReactApp',
1515
'LaravelVite',
16+
'Solid',
1617
] as (keyof typeof drivers)[];
1718
expect(driversList).toEqual(expectedDrivers);
1819

tests/helpers.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ describe('Helpers', () => {
4747
pkg.mockReturnValue({ dependencies: { 'react-scripts': '1.0.0' } });
4848
expect(detectFramework()).toBe('CreateReactApp');
4949

50+
pkg.mockReturnValue({ dependencies: { 'solid-js': '1.0.0' } });
51+
expect(detectFramework()).toBe('Solid');
52+
5053
pkg.mockReturnValue({
5154
devDependencies: { 'laravel-vite-plugin': '1.0.0' },
5255
});

tests/steps/next.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ describe('Next JS CSS', () => {
1414

1515
it('can resolve css location', async () => {
1616
vi.mocked(glob)
17-
.mockImplementationOnce((_, cb) => {
17+
.mockImplementationOnce((_, __, cb) => {
1818
console.log(typeof cb, cb);
1919
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20-
return (cb as any)(null, ['foo']) as any;
20+
return cb(null, ['foo']) as any;
2121
})
22-
.mockImplementationOnce((_, cb) => {
22+
.mockImplementationOnce((_, __, cb) => {
2323
// eslint-disable-next-line @typescript-eslint/no-explicit-any
24-
return (cb as any)(null, []) as any;
24+
return cb(null, []) as any;
2525
});
2626
const first = await resolveCssLocation();
2727
const second = await resolveCssLocation();

tests/steps/solid.spec.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import glob from 'glob';
2+
import { resolveCssLocation } from '../../src/frameworks/steps/solid';
3+
4+
vi.mock('glob');
5+
6+
describe('Solid JS CSS', () => {
7+
afterEach(() => {
8+
vi.clearAllMocks();
9+
});
10+
11+
afterAll(() => {
12+
vi.resetAllMocks();
13+
});
14+
15+
it('can resolve css location', async () => {
16+
vi.mocked(glob)
17+
.mockImplementationOnce((_, __, cb) => {
18+
console.log(typeof cb, cb);
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20+
return cb(null, ['foo']) as any;
21+
})
22+
.mockImplementationOnce((_, __, cb) => {
23+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
24+
return cb(null, []) as any;
25+
});
26+
const first = await resolveCssLocation();
27+
const second = await resolveCssLocation();
28+
29+
expect(first).toStrictEqual('foo');
30+
expect(second).toStrictEqual('./src/index.css');
31+
});
32+
});

0 commit comments

Comments
 (0)