Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ jobs:
build:
runs-on: ubuntu-latest

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

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version-file: .nvmrc
- run: npm ci
- run: npm run build --if-present
- run: npm test
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: lts/*
node-version-file: .nvmrc
- name: Install dependencies
run: npm ci
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.18.0
20
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ The index.ts file is where the blueprint is defined. Its executes a runner funct
import { prompt, changeCase, AssembleContext, runner, assembleTemplate } from '@jdpnielsen/assemble';

runner(async (context: AssembleContext) => {
const currentDir = dirname(fileURLToPath(import.meta.url));

// Enquirer is bundled with Assemble and can be used to prompt the user for input
const { name } = await prompt([
{
Expand All @@ -41,7 +43,7 @@ runner(async (context: AssembleContext) => {

await assembleTemplate({
// Assemble uses eta for templating
input: path.join(__dirname, './blueprint.tsx.eta'),
input: path.join(currentDir, './blueprint.tsx.eta'),
output: path.join(context.cwd, `./src/components/${name.kebabCase}/${name.kebabCase}.tsx`),
templateVariables: {
componentName: name.pascalCase,
Expand Down
2 changes: 1 addition & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
'use strict';

require('../lib/cli.js');
import '../lib/cli.js';
2 changes: 1 addition & 1 deletion example/assemble.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig } from '../src/index';
import { defineConfig } from '@jdpnielsen/assemble';

export default defineConfig({
blueprints: [
Expand Down
17 changes: 10 additions & 7 deletions example/blueprints/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import {
ts,
} from '@jdpnielsen/assemble';

import path from 'path';
import path, { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

const { SyntaxKind } = ts;

runner(async (context: AssembleContext) => {
const currentDir = dirname(fileURLToPath(import.meta.url));

const answers = await prompt<{ name: string }>([
{
type: 'text',
Expand All @@ -32,42 +35,42 @@ runner(async (context: AssembleContext) => {
};

await assembleTemplate({
input: path.join(__dirname, './blueprint.tsx.eta'),
input: path.join(currentDir, './blueprint.tsx.eta'),
output: path.join(context.cwd, `./src/blocks/${vars.name}/${vars.name}.blocks.tsx`),
templateVariables: vars,
context,
});

await assembleTemplate({
input: path.join(__dirname, './blueprint.stories.tsx.eta'),
input: path.join(currentDir, './blueprint.stories.tsx.eta'),
output: path.join(context.cwd, `./src/blocks/${vars.name}/${vars.name}.stories.tsx`),
templateVariables: vars,
context,
});

await assembleTemplate({
input: path.join(__dirname, './blueprint.module.scss.eta'),
input: path.join(currentDir, './blueprint.module.scss.eta'),
output: path.join(context.cwd, `./src/blocks/${vars.name}/${vars.name}.module.scss`),
templateVariables: vars,
context,
});

await assembleTemplate({
input: path.join(__dirname, './blueprint.schema.ts.eta'),
input: path.join(currentDir, './blueprint.schema.ts.eta'),
output: path.join(context.cwd, `./src/blocks/${vars.name}/${vars.name}.schema.ts`),
templateVariables: vars,
context,
});

await assembleTemplate({
input: path.join(__dirname, './blueprint.query.ts.eta'),
input: path.join(currentDir, './blueprint.query.ts.eta'),
output: path.join(context.cwd, `./src/blocks/${vars.name}/${vars.name}.query.ts`),
templateVariables: vars,
context,
});

await assembleTemplate({
input: path.join(__dirname, './index.ts.eta'),
input: path.join(currentDir, './index.ts.eta'),
output: path.join(context.cwd, `./src/blocks/${vars.name}/index.ts`),
templateVariables: vars,
context,
Expand Down
11 changes: 7 additions & 4 deletions example/blueprints/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import {
runner,
assembleTemplate,
} from '@jdpnielsen/assemble';
import path from 'node:path';
import path, { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

runner(async (context: AssembleContext) => {
const currentDir = dirname(fileURLToPath(import.meta.url));

const answers = await prompt<{ name: string; destination: string }>([
{
type: 'text',
Expand All @@ -33,21 +36,21 @@ runner(async (context: AssembleContext) => {
};

await assembleTemplate({
input: path.join(__dirname, './blueprint.tsx.eta'),
input: path.join(currentDir, './blueprint.tsx.eta'),
output: path.join(context.cwd, `./${answers.destination}/${vars.name}/${vars.name}.tsx`),
templateVariables: vars,
context,
});

await assembleTemplate({
input: path.join(__dirname, './blueprint.stories.tsx.eta'),
input: path.join(currentDir, './blueprint.stories.tsx.eta'),
output: path.join(context.cwd, `./${answers.destination}/${vars.name}/${vars.name}.stories.tsx`),
templateVariables: vars,
context,
});

await assembleTemplate({
input: path.join(__dirname, './blueprint.module.scss.eta'),
input: path.join(currentDir, './blueprint.module.scss.eta'),
output: path.join(context.cwd, `./${answers.destination}/${vars.name}/${vars.name}.module.scss`),
templateVariables: vars,
context,
Expand Down
17 changes: 10 additions & 7 deletions example/blueprints/template/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import path, { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

import {
prompt,
changeCase,
Expand All @@ -8,11 +11,11 @@ import {
ts,
} from '@jdpnielsen/assemble';

import path from 'node:path';

const { SyntaxKind } = ts;

runner(async (context: AssembleContext) => {
const currentDir = dirname(fileURLToPath(import.meta.url));

const answers = await prompt<{ name: string }>([
{
type: 'text',
Expand All @@ -32,35 +35,35 @@ runner(async (context: AssembleContext) => {
};

await assembleTemplate({
input: path.join(__dirname, './blueprint.template.tsx.eta'),
input: path.join(currentDir, './blueprint.template.tsx.eta'),
output: path.join(context.cwd, `./src/templates/${vars.name}/${vars.name}.template.tsx`),
templateVariables: vars,
context,
});

await assembleTemplate({
input: path.join(__dirname, './blueprint.stories.tsx.eta'),
input: path.join(currentDir, './blueprint.stories.tsx.eta'),
output: path.join(context.cwd, `./src/templates/${vars.name}/${vars.name}.stories.tsx`),
templateVariables: vars,
context,
});

await assembleTemplate({
input: path.join(__dirname, './blueprint.query.ts.eta'),
input: path.join(currentDir, './blueprint.query.ts.eta'),
output: path.join(context.cwd, `./src/templates/${vars.name}/${vars.name}.query.ts`),
templateVariables: vars,
context,
});

await assembleTemplate({
input: path.join(__dirname, './blueprint.schema.ts.eta'),
input: path.join(currentDir, './blueprint.schema.ts.eta'),
output: path.join(context.cwd, `./src/templates/${vars.name}/${vars.name}.schema.ts`),
templateVariables: vars,
context,
});

await assembleTemplate({
input: path.join(__dirname, './index.ts.eta'),
input: path.join(currentDir, './index.ts.eta'),
output: path.join(context.cwd, `./src/templates/${vars.name}/index.ts`),
templateVariables: vars,
context,
Expand Down
20 changes: 0 additions & 20 deletions jest.config.js

This file was deleted.

33 changes: 33 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Config } from 'jest'
import { createJsWithTsEsmPreset } from 'ts-jest'

const presetConfig = createJsWithTsEsmPreset({
//...options
tsconfig: 'tsconfig.test.json',

})

export default {
displayName: 'ts-only',
...presetConfig,
collectCoverageFrom: [
'<rootDir>/src/**/*.ts',
'<rootDir>/src/**/*.mts',
'!<rootDir>/src/**/*.spec.ts',
'!<rootDir>/src/**/*.spec.mts',
'!<rootDir>/src/__tests__/**/*.ts',
'!<rootDir>/src/types/**/*.ts',
'!<rootDir>/src/cli.ts',
],
collectCoverage: true,
transform: {
'^.+\\.ts$': ['ts-jest', {
babel: true,
tsconfig: 'tsconfig.test.json',
}],
'^.+\\.mts$': ['ts-jest', {
babel: true,
tsconfig: 'tsconfig.test.json',
}]
},
} satisfies Config
Loading