Initial commit for project Spoon!
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import { execSync } from 'node:child_process';
|
||||
import type { PlopTypes } from '@turbo/gen';
|
||||
|
||||
interface PackageJson {
|
||||
name: string;
|
||||
scripts: Record<string, string>;
|
||||
dependencies: Record<string, string>;
|
||||
devDependencies: Record<string, string>;
|
||||
}
|
||||
|
||||
const generator = (plop: PlopTypes.NodePlopAPI): void => {
|
||||
plop.setGenerator('init', {
|
||||
description: 'Generate a new package for the Spoon workspace',
|
||||
prompts: [
|
||||
{
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
message:
|
||||
'What is the name of the package? (You can skip the `@spoon/` prefix)',
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'deps',
|
||||
message:
|
||||
'Enter a space separated list of dependencies you would like to install',
|
||||
},
|
||||
],
|
||||
actions: [
|
||||
(answers) => {
|
||||
if ('name' in answers && typeof answers.name === 'string') {
|
||||
if (answers.name.startsWith('@spoon/')) {
|
||||
answers.name = answers.name.replace('@spoon/', '');
|
||||
}
|
||||
}
|
||||
return 'Config sanitized';
|
||||
},
|
||||
{
|
||||
type: 'add',
|
||||
path: 'packages/{{ name }}/eslint.config.ts',
|
||||
templateFile: 'templates/eslint.config.ts.hbs',
|
||||
},
|
||||
{
|
||||
type: 'add',
|
||||
path: 'packages/{{ name }}/package.json',
|
||||
templateFile: 'templates/package.json.hbs',
|
||||
},
|
||||
{
|
||||
type: 'add',
|
||||
path: 'packages/{{ name }}/tsconfig.json',
|
||||
templateFile: 'templates/tsconfig.json.hbs',
|
||||
},
|
||||
{
|
||||
type: 'add',
|
||||
path: 'packages/{{ name }}/src/index.ts',
|
||||
template: "export const name = '{{ name }}';",
|
||||
},
|
||||
{
|
||||
type: 'modify',
|
||||
path: 'packages/{{ name }}/package.json',
|
||||
async transform(content, answers) {
|
||||
if ('deps' in answers && typeof answers.deps === 'string') {
|
||||
const pkg = JSON.parse(content) as PackageJson;
|
||||
for (const dep of answers.deps.split(' ').filter(Boolean)) {
|
||||
const version = await fetch(
|
||||
`https://registry.npmjs.org/-/package/${dep}/dist-tags`,
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.then((json) => json.latest);
|
||||
if (!pkg.dependencies) pkg.dependencies = {};
|
||||
pkg.dependencies[dep] = `^${version}`;
|
||||
}
|
||||
return JSON.stringify(pkg, null, 2);
|
||||
}
|
||||
return content;
|
||||
},
|
||||
},
|
||||
async (answers) => {
|
||||
/**
|
||||
* Install deps and format everything
|
||||
*/
|
||||
if ('name' in answers && typeof answers.name === 'string') {
|
||||
execSync('bun install', { stdio: 'inherit' });
|
||||
execSync(
|
||||
`bun prettier --write packages/${answers.name}/** --list-different`,
|
||||
{ stdio: 'inherit' },
|
||||
);
|
||||
return 'Package scaffolded';
|
||||
}
|
||||
return 'Package not scaffolded';
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
export default generator;
|
||||
@@ -0,0 +1,10 @@
|
||||
import { defineConfig } from "eslint/config";
|
||||
|
||||
import { baseConfig } from "@spoon/eslint-config/base";
|
||||
|
||||
export default defineConfig(
|
||||
{
|
||||
ignores: [],
|
||||
},
|
||||
baseConfig,
|
||||
);
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "@spoon/{{ name }}",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"clean": "git clean -xdf .cache .turbo dist node_modules",
|
||||
"dev": "tsc",
|
||||
"format": "prettier --check . --ignore-path ../../.gitignore",
|
||||
"lint": "eslint",
|
||||
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@spoon/eslint-config": "workspace:*",
|
||||
"@spoon/prettier-config": "workspace:*",
|
||||
"@spoon/tsconfig": "workspace:*",
|
||||
"eslint": "catalog:",
|
||||
"prettier": "catalog:",
|
||||
"typescript": "catalog:"
|
||||
},
|
||||
"prettier": "@spoon/prettier-config"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "@spoon/tsconfig/compiled-package.json",
|
||||
"compilerOptions": {},
|
||||
"include": ["*.ts", "src"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user