Skip to content

Commit

Permalink
feat: nestjs (#365)
Browse files Browse the repository at this point in the history
This pull request includes several updates to the `README.md` and
`TODO.md` files, as well as changes to various template files to add
support for the Nest.js framework and adjust the scope of several
templates. The most important changes include the addition of the
`nestjs` template, updates to the scope of existing templates, and the
introduction of a new utility function to empty directories.

### Documentation Updates:
*
[`README.md`](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R71):
Added `nestjs` to the list of templates and updated the scope of several
templates to "workspace".
[[1]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R71)
[[2]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L453-R457)
[[3]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L475-R476)
[[4]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R506-R524)

*
[`TODO.md`](diffhunk://#diff-5c6a1301c6b59b30a040d747d065e861d3dd98bde0e5a4356d92d594e9835986L4-R12):
Added TODOs for `nestjs` and other templates indicating that repo
support is not available at the moment.

### Template Changes:
*
[`packages/core/src/template.ts`](diffhunk://#diff-a00384074c972ef1fcbba57b53e443249ba635b63484b1eb1f7c4916e4339cc8R27):
Added `nestjs` to the core templates list.

*
[`packages/templates/src/index.ts`](diffhunk://#diff-e808eba3cb0d1f11d939ad3e832c543551d82e87ff0fd48759d89afcff94771fR8):
Exported `nestjs` from the templates index.

*
[`packages/templates/src/nestjs.ts`](diffhunk://#diff-194e877e0e7ac2f869e0aa51d8b15c8005f3931802a297c74a98e3001aa2095bR1-R37):
Added a new template for `nestjs` with a function to scaffold a Nest.js
server app.

### Utility Functions:
*
[`packages/core/src/directory.ts`](diffhunk://#diff-e48f537ea43df65f2f733b68e321624fd34237257fab618884ade5c6a77ef438R17-R24):
Added a new function `emptyDirectory` to remove all files from a
directory and recreate it.

### Scope Adjustments:
*
[`packages/templates/src/angular.ts`](diffhunk://#diff-628da3ea0ff520d22fe287969fa70433369e80a5c5cca0f56155b5b3897c81b8R41-R43):
Changed the scope of the `angular` template to "workspace" and added a
TODO comment.

*
[`packages/templates/src/cra.ts`](diffhunk://#diff-07e537610a9f89af168891b69382d6a2ec4c627c83b6cb21f38edb707fb5ddb2R43-R45):
Changed the scope of the `cra` template to "workspace" and added a TODO
comment.

*
[`packages/templates/src/next.ts`](diffhunk://#diff-7b8c2ff5e3fec4265f94f6fadba1066c1a83370bef545fe260a5fc1f71331974R23-R30):
Changed the scope of the `next` template to "workspace", added
`--turbopack` and `--yes` options, and added a TODO comment.
[[1]](diffhunk://#diff-7b8c2ff5e3fec4265f94f6fadba1066c1a83370bef545fe260a5fc1f71331974R23-R30)
[[2]](diffhunk://#diff-7b8c2ff5e3fec4265f94f6fadba1066c1a83370bef545fe260a5fc1f71331974R40-R42)

*
[`packages/templates/src/sanity.ts`](diffhunk://#diff-16b5865fb81eb3b101433586384690b1108e06837f7c278eed18f01c9328ceb0R43-R45):
Changed the scope of the `sanity` template to "workspace" and added a
TODO comment.
  • Loading branch information
hongaar authored Oct 25, 2024
1 parent ad9d73c commit e57e956
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 17 deletions.
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,
};

0 comments on commit e57e956

Please sign in to comment.