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

[WIP] Implement plop base #1249

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
# Include specific folders
!/code
!/packages

# But exclude folders anywhere
node_modules
dist
build
public
.turbo

# Exclude Handlebars.js (.hbs) files
# TODO: Figure out how to format hanldebar templates
**/*.hbs
ptrkdan marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 23 additions & 0 deletions code/react/handlebar-templates/App.tsx.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Suspense } from "react";
{{#if router}}
import { Router } from './routes';
{{else}}
import Home from './ui/pages';
{{/if}}
import { AppProviders } from "./context";

function App() {
return (
<AppProviders>
<Suspense>
{{#if router}}
<Router />
{{else}}
<Home />
{{/if}}
</Suspense>
</AppProviders>
)
}

export default App;
3 changes: 2 additions & 1 deletion packages/start-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"degit": "2.8.4",
"fs-extra": "11.1.0",
"inquirer": "8.2.3",
"meow": "7.1.1"
"meow": "7.1.1",
"node-plop": "^0.32.0"
},
"devDependencies": {
"@types/concat-stream": "2.0.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/start-frontend/src/index.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-ignore
ptrkdan marked this conversation as resolved.
Show resolved Hide resolved
import { format } from "prettier";
import fse from "fs-extra";
import meow from "meow";
Expand Down Expand Up @@ -326,6 +327,16 @@ async function run() {
removeEslintConfig();
}

const { default: nodePlop } = await import("node-plop");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally importing nodePlop throws an ERR_REQUIRE_ESM error. (See #1222 (comment))

In order to successfully build with node-plop, dynamic importing it seem to work, with the plopFile.ts exporting using CommonJS syntax.

const plopFilePath = path.resolve(__dirname, "plopfile.js");
const plop = await nodePlop(plopFilePath, {
destBasePath: appDir,
force: true,
});

const baseGenerator = plop.getGenerator("constructBase");
baseGenerator.runActions({});

// Copy commons
copyCommon(appDir, sharedConfigDir);

Expand Down
25 changes: 25 additions & 0 deletions packages/start-frontend/src/plopfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { NodePlopAPI } from "node-plop";
import path from "node:path";

const TEMP_DIR = path.resolve(__dirname, "temp");

module.exports = function (plop: NodePlopAPI) {
plop.setHelper("reverseEach", (ctx, { fn }) =>
ctx.reverse().map(fn).join("")
);

plop.setGenerator("constructBase", {
actions: [
{
type: "add",
force: true,
path: "src/app.tsx",
templateFile: path.resolve(
TEMP_DIR,
"handlebar-templates",
"app.tsx.hbs"
),
},
],
});
};
3 changes: 2 additions & 1 deletion packages/start-frontend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "tsconfig/library.json",
"compilerOptions": {
"rootDir": "."
"rootDir": ".",
"module": "ESNext"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To allow the (dynamic) import of node-plop

},
"include": ["src", "tsup.config.ts"],
"exclude": ["templates"]
Expand Down
2 changes: 1 addition & 1 deletion packages/start-frontend/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig, Options } from "tsup";

export default defineConfig((options: Options) => ({
entry: ["src/index.ts"],
entry: ["src/index.ts", "src/plopfile.ts"],
format: ["cjs"],
clean: true,
define: {
Expand Down
Loading
Loading