Skip to content

Commit

Permalink
add: Solid JS Scaffolding Support (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzsk authored Jan 23, 2023
1 parent 43bb3c8 commit cc75826
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 29 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

name: CD

on:
release:
types: [created]

jobs:
build:
Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -17,7 +16,7 @@ jobs:
- run: npm run lint
- run: npm run coverage

publish-npm:
Publish:
needs: build
runs-on: ubuntu-latest
steps:
Expand Down
27 changes: 13 additions & 14 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@ name: CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:

Build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run lint
- run: npm run coverage
- run: npm run build
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run lint
- run: npm run coverage
- run: npm run build
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Below commands will install the `@latest` versions of the respective frameworks.
| Svelte Kit | `npx twify@latest create svelte <my-app>` |
| Laravel Vite | `npx twify@latest create laravel <my-app>` |
| Vite | `npx twify@latest create vite <my-app>` |
| Solid Start | `npx twify@latest create solid <my-app>` |
| Angular | `npx twify@latest create angular <my-app>` |
| Create React App | `npx twify@latest create react <my-app>` |

Expand Down Expand Up @@ -111,7 +112,7 @@ Below are the list of Supported Projects,
| Vite | :white_check_mark: | :white_check_mark: |
| Angular | :white_check_mark: | :white_check_mark: |
| Create React App | :white_check_mark: | :white_check_mark: |
| Solid JS | :o: WIP | :o: WIP |
| Solid JS | :white_check_mark: | :white_check_mark: |
| Astro | :o: WIP | :o: WIP |
| Qwik | :o: WIP | :o: WIP |

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twify",
"version": "0.4.3",
"version": "0.5.0",
"description": "A Tool to Setup TailwindCSS in your Project with a Single Command",
"bin": {
"twify": "dist/main.js"
Expand Down
1 change: 1 addition & 0 deletions src/drivers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export const drivers = {
Angular: (): DriverImport => import('./frameworks/angular'),
CreateReactApp: (): DriverImport => import('./frameworks/cra'),
LaravelVite: (): DriverImport => import('./frameworks/laravel'),
Solid: (): DriverImport => import('./frameworks/solid'),
};
12 changes: 12 additions & 0 deletions src/frameworks/solid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Framework } from '../types';
import { resolveCssLocation } from './steps/solid';

const Solid: Framework = {
requiredDependencies: ['tailwindcss', 'postcss', 'autoprefixer'],
initCommands: ['npx tailwindcss init -p'],
cssLocation: resolveCssLocation,
content: ['./src/**/*.{js,jsx,ts,tsx}'],
steps: [],
};

export default Solid;
4 changes: 3 additions & 1 deletion src/frameworks/steps/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import glob from 'glob';
import util from 'util';

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

if (!match) {
return './styles/globals.css';
Expand Down
14 changes: 14 additions & 0 deletions src/frameworks/steps/solid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import glob from 'glob';
import util from 'util';

export async function resolveCssLocation() {
const [match] = await util.promisify(glob)('./src/**/root.css', {
ignore: ['node_modules'],
});

if (!match) {
return './src/index.css';
}

return match;
}
1 change: 1 addition & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function detectFramework(): Driver | undefined {
if (dependencies['nuxt']) return 'Nuxt2';
if (dependencies['@angular/core']) return 'Angular';
if (dependencies['react-scripts']) return 'CreateReactApp';
if (dependencies['solid-js']) return 'Solid';
if (devDependencies['laravel-vite-plugin']) return 'LaravelVite';
if (devDependencies['@sveltejs/kit']) return 'SvelteKit';
if (devDependencies['nuxt']) return 'Nuxt3';
Expand Down
6 changes: 3 additions & 3 deletions src/makers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { runCommand } from './helpers';
import { PackageManager } from './types';
import { drivers } from './drivers';
import { Driver, PackageManager } from './types';

export type Maker = { cmd: string; project: keyof typeof drivers };
export type Maker = { cmd: string; project: Driver };
export type SpecialMaker = (packageManager: PackageManager) => Promise<Maker>;

const globalInstallPrefix: Record<PackageManager, string> = {
Expand Down Expand Up @@ -38,6 +37,7 @@ const regularMakes: Record<string, Maker> = {
next: { cmd: 'next-app', project: 'NextJS' },
react: { cmd: 'react-app', project: 'CreateReactApp' },
nuxt: { cmd: 'nuxt-app', project: 'Nuxt2' },
solid: { cmd: 'solid', project: 'Solid' },
};

export async function resolveMakeCommand(args: string[]): Promise<Maker> {
Expand Down
18 changes: 18 additions & 0 deletions tests/__snapshots__/drivers.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,21 @@ exports[`Drivers > has a list of drivers 9`] = `
],
}
`;

exports[`Drivers > has a list of drivers 10`] = `
{
"content": [
"./src/**/*.{js,jsx,ts,tsx}",
],
"cssLocation": [Function],
"initCommands": [
"npx tailwindcss init -p",
],
"requiredDependencies": [
"tailwindcss",
"postcss",
"autoprefixer",
],
"steps": [],
}
`;
1 change: 1 addition & 0 deletions tests/drivers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Drivers', () => {
'Angular',
'CreateReactApp',
'LaravelVite',
'Solid',
] as (keyof typeof drivers)[];
expect(driversList).toEqual(expectedDrivers);

Expand Down
3 changes: 3 additions & 0 deletions tests/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ describe('Helpers', () => {
pkg.mockReturnValue({ dependencies: { 'react-scripts': '1.0.0' } });
expect(detectFramework()).toBe('CreateReactApp');

pkg.mockReturnValue({ dependencies: { 'solid-js': '1.0.0' } });
expect(detectFramework()).toBe('Solid');

pkg.mockReturnValue({
devDependencies: { 'laravel-vite-plugin': '1.0.0' },
});
Expand Down
8 changes: 4 additions & 4 deletions tests/steps/next.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ describe('Next JS CSS', () => {

it('can resolve css location', async () => {
vi.mocked(glob)
.mockImplementationOnce((_, cb) => {
.mockImplementationOnce((_, __, cb) => {
console.log(typeof cb, cb);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (cb as any)(null, ['foo']) as any;
return cb(null, ['foo']) as any;
})
.mockImplementationOnce((_, cb) => {
.mockImplementationOnce((_, __, cb) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (cb as any)(null, []) as any;
return cb(null, []) as any;
});
const first = await resolveCssLocation();
const second = await resolveCssLocation();
Expand Down
32 changes: 32 additions & 0 deletions tests/steps/solid.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import glob from 'glob';
import { resolveCssLocation } from '../../src/frameworks/steps/solid';

vi.mock('glob');

describe('Solid JS CSS', () => {
afterEach(() => {
vi.clearAllMocks();
});

afterAll(() => {
vi.resetAllMocks();
});

it('can resolve css location', async () => {
vi.mocked(glob)
.mockImplementationOnce((_, __, cb) => {
console.log(typeof cb, cb);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return cb(null, ['foo']) as any;
})
.mockImplementationOnce((_, __, cb) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return cb(null, []) as any;
});
const first = await resolveCssLocation();
const second = await resolveCssLocation();

expect(first).toStrictEqual('foo');
expect(second).toStrictEqual('./src/index.css');
});
});

0 comments on commit cc75826

Please sign in to comment.