Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: nestjs #365

Merged
merged 1 commit into from
Oct 25, 2024
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
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ yarn moker add --template bandersnatch cli
- [`express`](#express)
- [`github-action`](#github-action)
- [`lib`](#lib)
- [`nestjs`](#nestjs)
- [`next`](#next)
- [`sanity`](#sanity)
- [Commands](#commands)
Expand Down Expand Up @@ -450,10 +451,10 @@ script to the repo or both the workspace and the monorepo.

## `angular`

_Scope: repo or workspace_
_Scope: workspace_

Uses the [Angular CLI](https://angular.dev/tools/cli) to scaffold an Angular app
(web client).
Uses the [Angular CLI](https://angular.dev/tools/cli) to interactively scaffold
an Angular app (web client).

## `bandersnatch`

Expand All @@ -472,7 +473,7 @@ available monorepo plugins.

## `cra`

_Scope: repo or workspace_
_Scope: workspace_

Uses [create-react-app](https://create-react-app.dev/) to scaffold a React.js
app (web client).
Expand Down Expand Up @@ -502,17 +503,25 @@ _Scope: repo or workspace_
A plain shared library template with the [typescript](#typescript-workspace) and
[jest](#jest-workspace) plugins.

## `nestjs`

_Scope: workspace_

Uses the
[TypeScript starter project](https://github.com/nestjs/typescript-starter) to
scaffold a Nest.js server app.

## `next`

_Scope: repo or workspace_
_Scope: workspace_

Uses
[create-next-app](https://nextjs.org/docs/pages/api-reference/create-next-app)
to scaffold a Next.js app.

## `sanity`

_Scope: repo or workspace_
_Scope: workspace_

Uses [create-sanity](https://www.sanity.io/docs/installation) which
interactively scaffolds a Sanity Studio package.
Expand Down
19 changes: 12 additions & 7 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
### TODOs

| Filename | line # | TODO |
| :------------------------------------------------------------------------- | :----: | :--------------------------------------------------------------- |
| [packages/cli/test/add.test.ts](packages/cli/test/add.test.ts#L52) | 52 | remove when https://github.com/nodejs/node/issues/47614 resolves |
| [packages/core/src/license.ts](packages/core/src/license.ts#L43) | 43 | Contents is not perfect yet, e.g.: |
| [packages/core/src/yarnrc.ts](packages/core/src/yarnrc.ts#L23) | 23 | etc, fix later |
| [packages/plugins/src/jest/jest.ts](packages/plugins/src/jest/jest.ts#L31) | 31 | install jest without ts-jest |
| [packages/plugins/src/xv/xv.ts](packages/plugins/src/xv/xv.ts#L16) | 16 | install xv without ts-node |
| Filename | line # | TODO |
| :------------------------------------------------------------------------- | :----: | :---------------------------------------------------------------------- |
| [packages/cli/test/add.test.ts](packages/cli/test/add.test.ts#L52) | 52 | remove when https://github.com/nodejs/node/issues/47614 resolves |
| [packages/core/src/license.ts](packages/core/src/license.ts#L43) | 43 | Contents is not perfect yet, e.g.: |
| [packages/core/src/yarnrc.ts](packages/core/src/yarnrc.ts#L23) | 23 | etc, fix later |
| [packages/templates/src/angular.ts](packages/templates/src/angular.ts#L41) | 41 | repo not supported atm, because we'd need to restore yarn and git state |
| [packages/templates/src/cra.ts](packages/templates/src/cra.ts#L43) | 43 | repo not supported atm, because we'd need to restore yarn and git state |
| [packages/templates/src/nestjs.ts](packages/templates/src/nestjs.ts#L33) | 33 | repo not supported atm, because we'd need to restore yarn and git state |
| [packages/templates/src/next.ts](packages/templates/src/next.ts#L40) | 40 | repo not supported atm, because we'd need to restore yarn and git state |
| [packages/templates/src/sanity.ts](packages/templates/src/sanity.ts#L43) | 43 | repo not supported atm, because we'd need to restore yarn and git state |
| [packages/plugins/src/jest/jest.ts](packages/plugins/src/jest/jest.ts#L31) | 31 | install jest without ts-jest |
| [packages/plugins/src/xv/xv.ts](packages/plugins/src/xv/xv.ts#L16) | 16 | install xv without ts-node |
8 changes: 8 additions & 0 deletions packages/core/src/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ export async function createDirectory({ directory }: DirOption) {
return fs.promises.mkdir(directory, { recursive: true });
}

/**
* Removes all files from a directory.
*/
export async function emptyDirectory({ directory }: DirOption) {
await removeDirectory({ directory });
return createDirectory({ directory });
}

export async function isDirectory({ directory }: DirOption) {
try {
return (await fs.promises.stat(directory)).isDirectory();
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const CORE_TEMPLATES = [
"express",
"github-action",
"lib",
"nestjs",
"next",
"sanity",
];
Expand Down
3 changes: 2 additions & 1 deletion packages/templates/src/angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ async function apply({ directory }: TemplateArgs) {
await writePackage({ directory, data: oldPackage });
}

// @todo repo not supported atm, because we'd need to restore yarn and git state
export const angular = {
type: PluginType.RepoOrWorkspace,
type: PluginType.Workspace,
apply,
};
3 changes: 2 additions & 1 deletion packages/templates/src/cra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ async function apply({ directory }: TemplateArgs) {
await writePackage({ directory, data: oldPackage });
}

// @todo repo not supported atm, because we'd need to restore yarn and git state
export const cra = {
type: PluginType.RepoOrWorkspace,
type: PluginType.Workspace,
apply,
};
1 change: 1 addition & 0 deletions packages/templates/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export * from "./cra.js";
export * from "./express.js";
export * from "./githubAction.js";
export * from "./lib.js";
export * from "./nestjs.js";
export * from "./next.js";
export * from "./sanity.js";
37 changes: 37 additions & 0 deletions packages/templates/src/nestjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
PluginType,
emptyDirectory,
exec,
readPackage,
removeFile,
writePackage,
type TemplateArgs,
} from "@mokr/core";
import { join } from "path";

async function apply({ directory }: TemplateArgs) {
const oldPackage = await readPackage({ directory });

await emptyDirectory({ directory });

await exec(
"yarn",
["dlx", "degit", "https://github.com/nestjs/typescript-starter"],
{
cwd: directory,
},
);

await removeFile({ path: join(directory, "package-lock.json") });

delete oldPackage.scripts?.["build"];
delete oldPackage.scripts?.["test"];

await writePackage({ directory, data: oldPackage });
}

// @todo repo not supported atm, because we'd need to restore yarn and git state
export const nestjs = {
type: PluginType.Workspace,
apply,
};
5 changes: 4 additions & 1 deletion packages/templates/src/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ async function apply({ directory }: TemplateArgs) {
"create-next-app",
basename(directory),
"--app",
"--turbopack",
"--typescript",
"--eslint",
"--no-tailwind",
"--src-dir",
'--import-alias "@/*"',
"--use-yarn",
"--yes",
],
{
cwd: dirname(directory),
Expand All @@ -35,7 +37,8 @@ async function apply({ directory }: TemplateArgs) {
await writePackage({ directory, data: oldPackage });
}

// @todo repo not supported atm, because we'd need to restore yarn and git state
export const next = {
type: PluginType.RepoOrWorkspace,
type: PluginType.Workspace,
apply,
};
3 changes: 2 additions & 1 deletion packages/templates/src/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ async function apply({ directory }: TemplateArgs) {
await writePackage({ directory, data: oldPackage });
}

// @todo repo not supported atm, because we'd need to restore yarn and git state
export const sanity = {
type: PluginType.RepoOrWorkspace,
type: PluginType.Workspace,
interactive: true,
apply,
};