create-houdini 1.2.9 → 1.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin.js CHANGED
@@ -73,6 +73,11 @@ if (fs.existsSync(projectDir)) {
73
73
  }
74
74
  }
75
75
 
76
+ // create the project directory if necessary
77
+ if (dirToCreate && !fs.existsSync(projectDir)) {
78
+ fs.mkdirSync(projectDir)
79
+ }
80
+
76
81
  const template = await p.select({
77
82
  message: 'Which template do you want to use?',
78
83
  initialValue: 'react-typescript',
@@ -81,49 +86,82 @@ const template = await p.select({
81
86
  if (p.isCancel(template)) {
82
87
  process.exit(1)
83
88
  }
89
+ const templateDir = path.join(templatesDir, template)
84
90
  const templateMeta = options.find((option) => option.value === template)
85
91
  if (!templateMeta) {
86
92
  // this will never happen, but it helps to types later
87
93
  exit(1)
88
94
  }
89
- const templateDir = sourcePath(path.join(templatesDir, template))
90
95
 
96
+ // ask if the schema is local or remote
97
+ const localSchema =
98
+ template !== 'sveltekit-demo' &&
99
+ (await p.confirm({
100
+ message: 'Is your api going to be defined in this project too?',
101
+ }))
102
+
103
+ // if we have a remote schema then we need to introspect it and write the value
91
104
  let apiUrl = templateMeta.apiUrl ?? ''
92
- let pullSchema_content = ''
93
- if (apiUrl === '') {
94
- const { apiUrl: apiUrlCli, pullSchema_content: pullSchema_content_cli } = await pullSchemaCli()
95
- apiUrl = apiUrlCli
96
- if (pullSchema_content_cli === null) {
97
- pCancel('We could not pull the schema. Please try again.')
98
- } else {
99
- pullSchema_content = pullSchema_content_cli
100
- }
101
- } else {
102
- const pullSchema_content_local = await pullSchema(apiUrl, {})
103
- if (pullSchema_content_local === null) {
104
- pCancel('We could not pull the schema. Please report this on Discord.')
105
+ if (!localSchema) {
106
+ let pullSchema_content = ''
107
+ if (apiUrl === '') {
108
+ const { apiUrl: apiUrlCli, pullSchema_content: pullSchema_content_cli } =
109
+ await pullSchemaCli()
110
+ apiUrl = apiUrlCli
111
+ if (pullSchema_content_cli === null) {
112
+ pCancel('We could not pull the schema. Please try again.')
113
+ } else {
114
+ pullSchema_content = pullSchema_content_cli
115
+ }
105
116
  } else {
106
- pullSchema_content = pullSchema_content_local
117
+ const pullSchema_content_local = await pullSchema(apiUrl, {})
118
+ if (pullSchema_content_local === null) {
119
+ pCancel('We could not pull the schema. Please report this on Discord.')
120
+ } else {
121
+ pullSchema_content = pullSchema_content_local
122
+ }
107
123
  }
108
- }
109
124
 
110
- // create the project directory if necessary
111
- if (dirToCreate) {
112
- fs.mkdirSync(projectDir)
125
+ writeFileSync(path.join(projectDir, 'schema.graphql'), pullSchema_content)
113
126
  }
114
- writeFileSync(path.join(projectDir, 'schema.graphql'), pullSchema_content)
127
+
128
+ // the final client config depends on whether we have a local schema or not
129
+ const clientConfig = localSchema
130
+ ? ``
131
+ : `{
132
+ url: '${apiUrl}',
133
+ }`
134
+
135
+ const configFile = localSchema
136
+ ? ''
137
+ : `
138
+ watchSchema: {
139
+ url: '${apiUrl}',
140
+ },
141
+ `
115
142
 
116
143
  copy(
117
- templateDir,
144
+ sourcePath(path.join(templatesDir, template)),
118
145
  projectDir,
119
146
  {
120
147
  API_URL: apiUrl,
121
148
  PROJECT_NAME: projectName,
122
149
  HOUDINI_VERSION: version,
150
+ ["'CLIENT_CONFIG'"]: clientConfig,
151
+ ["'CONFIG_FILE'"]: configFile,
123
152
  },
124
153
  ['.meta.json']
125
154
  )
126
155
 
156
+ // if we have a local schema then we have more fiiles to copy
157
+ if (localSchema) {
158
+ if (template === 'react') {
159
+ copy(sourcePath('./fragments/localApi'))
160
+ } else if (template === 'react-typescript') {
161
+ copy(sourcePath('./fragments/localApi-typescript'))
162
+ }
163
+ }
164
+
127
165
  // If anything goes wrong, we don't want to block the user
128
166
  let sponsor_msg = ''
129
167
  try {
@@ -134,9 +172,9 @@ try {
134
172
  p.outro(`🎉 Everything is ready!
135
173
 
136
174
  👉 Next Steps
137
- 0️⃣ Go to your project : ${green(`cd ${projectDir}`)}
138
- 1️⃣ Install dependencies : ${green(`npm i`)} | ${gray(`pnpm i`)} | ${gray(`yarn`)}
139
- 2️⃣ Start your application : ${green(`npm run dev`)} | ${gray(`pnpm dev`)} | ${gray(`yarn dev`)}`)
175
+ 0️⃣ Go to your project : cd ${projectDir}
176
+ 1️⃣ Install dependencies : npm i | pnpm i | yarn
177
+ 2️⃣ Start your application : npm run dev | pnpm dev | yarn dev`)
140
178
 
141
179
  console.log(
142
180
  gray(
@@ -152,9 +190,9 @@ console.log(
152
190
  // Function to copy files recursively
153
191
  function copy(
154
192
  /** @type {string} */ sourceDir,
155
- /** @type {string} */ destDir,
156
- /** @type {Record<string, string>} */ transformMap,
157
- /** @type {string[]} */ ignoreList
193
+ /** @type {string} */ destDir = projectDir,
194
+ /** @type {Record<string, string>} */ transformMap = {},
195
+ /** @type {string[]} */ ignoreList = []
158
196
  ) {
159
197
  if (!fs.existsSync(destDir)) {
160
198
  fs.mkdirSync(destDir)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-houdini",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "description": "A CLI for creating new Houdini projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,10 +1,6 @@
1
1
  /// <references types="houdini-react">
2
- /// <references types="houdini-router">
3
2
  /** @type {import('houdini').ConfigFile} */
4
- const config = {
5
- watchSchema: {
6
- url: 'API_URL',
7
- },
3
+ const config = {'CONFIG_FILE'
8
4
  plugins: {
9
5
  'houdini-react': {},
10
6
  },
@@ -13,10 +13,15 @@
13
13
  "houdini-react": "^HOUDINI_VERSION",
14
14
  "react": "^18.2.0",
15
15
  "react-dom": "^18.2.0",
16
- "react-streaming": "^0.3.14"
16
+ "react-streaming": "^0.3.14",
17
+ "graphql-yoga": "4.0.4",
18
+ "@whatwg-node/server": "^0.9.14"
17
19
  },
18
20
  "devDependencies": {
19
21
  "@vitejs/plugin-react": "^3.1.0",
20
22
  "vite": "^4.1.0"
23
+ },
24
+ "resolutions": {
25
+ "graphql": "15.5.1"
21
26
  }
22
27
  }
@@ -1,6 +1,4 @@
1
1
  import { HoudiniClient } from '$houdini'
2
2
 
3
3
  // Export the Houdini client
4
- export default new HoudiniClient({
5
- url: 'API_URL',
6
- })
4
+ export default new HoudiniClient('CLIENT_CONFIG')
@@ -1,10 +1,6 @@
1
1
  /// <references types="houdini-react">
2
- /// <references types="houdini-router">
3
2
  /** @type {import('houdini').ConfigFile} */
4
- const config = {
5
- watchSchema: {
6
- url: 'API_URL',
7
- },
3
+ const config = {'CONFIG_FILE'
8
4
  plugins: {
9
5
  'houdini-react': {},
10
6
  },
@@ -13,7 +13,9 @@
13
13
  "houdini-react": "^HOUDINI_VERSION",
14
14
  "react": "^18.2.0",
15
15
  "react-dom": "^18.2.0",
16
- "react-streaming": "^0.3.14"
16
+ "react-streaming": "^0.3.14",
17
+ "graphql-yoga": "4.0.4",
18
+ "@whatwg-node/server": "^0.9.14"
17
19
  },
18
20
  "devDependencies": {
19
21
  "@types/react": "^18.0.27",
@@ -21,5 +23,8 @@
21
23
  "@vitejs/plugin-react": "^3.1.0",
22
24
  "typescript": "^4.9.3",
23
25
  "vite": "^4.1.0"
26
+ },
27
+ "resolutions": {
28
+ "graphql": "15.5.1"
24
29
  }
25
30
  }
@@ -1,6 +1,4 @@
1
1
  import { HoudiniClient } from '$houdini'
2
2
 
3
3
  // Export the Houdini client
4
- export default new HoudiniClient({
5
- url: 'API_URL',
6
- })
4
+ export default new HoudiniClient('CLIENT_CONFIG')