Skip to content

Commit

Permalink
Embed templates in create-app (#528)
Browse files Browse the repository at this point in the history
* Embed templates in create-app

* mend
  • Loading branch information
ericanderson authored Jul 25, 2024
1 parent e54f413 commit 9e956e3
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 24 deletions.
7 changes: 4 additions & 3 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
"commit": false,
"fixed": [
["@osdk/foundry.*", "@osdk/foundry"],
["@osdk/client.api", "@osdk/client"]
["@osdk/client.api", "@osdk/client"],
["@osdk/create-app", "@osdk/create-app.template.*"]
],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [
"@osdk/examples.*",
"@osdk/monorepo.*",
"@osdk/tests.*",
"@osdk/version-updater",
"@osdk/monorepo.*"
"@osdk/version-updater"
],
"bumpVersionsWithWorkspaceProtocolOnly": true,
"snapshot": {
Expand Down
5 changes: 5 additions & 0 deletions .changeset/old-deers-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/create-app": minor
---

Makes the templates get embedded create-app instead of referencing them
8 changes: 8 additions & 0 deletions .monorepolint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ function standardPackageRules(shared, options) {
*/
export default {
rules: [
packageEntry({
includePackages: ["@osdk/create-app.template.*"],
options: {
entries: {
private: true,
},
},
}),
fileContents({
includePackages: ["@osdk/create-app.template.*"],
options: {
Expand Down
1 change: 1 addition & 0 deletions packages/create-app.template-packager/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@osdk/create-app.template-packager",
"private": true,
"version": "0.0.0",
"license": "Apache-2.0",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@osdk/create-app.template.next-static-export",
"private": true,
"version": "0.17.0",
"license": "Apache-2.0",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions packages/create-app.template.react/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@osdk/create-app.template.react",
"private": true,
"version": "0.17.0",
"license": "Apache-2.0",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@osdk/create-app.template.tutorial-todo-aip-app",
"private": true,
"version": "0.17.0",
"license": "Apache-2.0",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@osdk/create-app.template.tutorial-todo-app",
"private": true,
"version": "0.17.0",
"license": "Apache-2.0",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions packages/create-app.template.vue/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@osdk/create-app.template.vue",
"private": true,
"version": "0.17.0",
"license": "Apache-2.0",
"repository": {
Expand Down
10 changes: 5 additions & 5 deletions packages/create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
"typecheck": "monorepo.tool.typecheck esm"
},
"dependencies": {
"@osdk/create-app.template.next-static-export": "workspace:*",
"@osdk/create-app.template.react": "workspace:*",
"@osdk/create-app.template.tutorial-todo-aip-app": "workspace:*",
"@osdk/create-app.template.tutorial-todo-app": "workspace:*",
"@osdk/create-app.template.vue": "workspace:*",
"consola": "^3.2.3",
"find-up": "^7.0.0",
"handlebars": "^4.7.8",
"yargs": "^17.7.2"
},
"devDependencies": {
"@osdk/create-app.template.next-static-export": "workspace:*",
"@osdk/create-app.template.react": "workspace:*",
"@osdk/create-app.template.tutorial-todo-aip-app": "workspace:*",
"@osdk/create-app.template.tutorial-todo-app": "workspace:*",
"@osdk/create-app.template.vue": "workspace:*",
"@osdk/monorepo.api-extractor": "workspace:~",
"@osdk/monorepo.tsconfig": "workspace:~",
"@osdk/monorepo.tsup": "workspace:~",
Expand Down
4 changes: 1 addition & 3 deletions packages/create-app/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ export async function run(
const files: Map<
string,
{ type: "base64"; body: string } | { type: "raw"; body: string }
> = (await import(
`@osdk/create-app.template.${template.id.replace(/^template-/, "")}`
)).files;
> = await template.getFiles();

for (const [filePath, contents] of files) {
const finalPath = path.join(root, filePath);
Expand Down
21 changes: 21 additions & 0 deletions packages/create-app/src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export interface Template {
envPrefix: string;
buildDirectory: string;
hidden?: boolean;
getFiles: () => Promise<
Map<
string,
{ type: "base64"; body: string } | { type: "raw"; body: string }
>
>;
}

export interface TemplateContext {
Expand All @@ -35,31 +41,46 @@ export const TEMPLATES: readonly Template[] = [
label: "React",
envPrefix: "VITE_",
buildDirectory: "./dist",
getFiles: async () => ((await import(
`@osdk/create-app.template.react`
)).files),
},
{
id: "template-vue",
label: "Vue",
envPrefix: "VITE_",
buildDirectory: "./dist",
getFiles: async () => ((await import(
`@osdk/create-app.template.vue`
)).files),
},
{
id: "template-next-static-export",
label: "Next (static export)",
envPrefix: "NEXT_PUBLIC_",
buildDirectory: "./out",
getFiles: async () => ((await import(
`@osdk/create-app.template.next-static-export`
)).files),
},
{
id: "template-tutorial-todo-app",
label: "Tutorial: To do App",
envPrefix: "VITE_",
buildDirectory: "./dist",
hidden: true,
getFiles: async () => ((await import(
`@osdk/create-app.template.tutorial-todo-app`
)).files),
},
{
id: "template-tutorial-todo-aip-app",
label: "Tutorial: To do AIP App",
envPrefix: "VITE_",
buildDirectory: "./dist",
hidden: true,
getFiles: async () => ((await import(
`@osdk/create-app.template.tutorial-todo-aip-app`
)).files),
},
];
26 changes: 13 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9e956e3

Please sign in to comment.