@hellocoop/quickstart 2.5.3 → 2.6.0

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/express.mjs ADDED
@@ -0,0 +1,89 @@
1
+ // express quickstart
2
+
3
+ import { statSync, appendFileSync } from 'fs'
4
+ import chalk from 'chalk';
5
+ import fs from 'fs-extra'
6
+ import quickstart from './index.js';
7
+ import { randomBytes } from 'crypto'
8
+
9
+ const HELLO_CONFIG_FILE = 'hello.config.js'
10
+ const ENV_FILE = '.env'
11
+
12
+ import dotenv from 'dotenv'
13
+
14
+ // TODO check if @hellocoop/express is installed
15
+
16
+ const writeConfig = async (options,name) => {
17
+ const client_id = await quickstart(options)
18
+
19
+ const filePath = process.cwd()+'/'+HELLO_CONFIG_FILE
20
+ try {
21
+ statSync(filePath)
22
+ const append = `
23
+ // added by @hellocoop/quickstart --${name} on ${(new Date()).toISOString()}
24
+ config.client_id = '${client_id}'
25
+ `
26
+ appendFileSync( filePath, append)
27
+ console.log(`${chalk.greenBright('✓')} Updated ${HELLO_CONFIG_FILE} with client_id ${chalk.blueBright(client_id)}`)
28
+ return
29
+ } catch (err) {
30
+ if (err.code !== 'ENOENT') { // error other than file does not exist
31
+ throw(err)
32
+ }
33
+ }
34
+ const config =`// ${HELLO_CONFIG_FILE}
35
+ // see https://hello.dev/docs/sdks/${name}/#configuration for details
36
+
37
+ const config = {
38
+ client_id: '${client_id}',
39
+ }
40
+ modules.export = config
41
+ `
42
+ fs.outputFileSync( filePath, config)
43
+ console.log(`${chalk.greenBright('✓')} Created ${HELLO_CONFIG_FILE} with client_id ${chalk.blueBright(client_id)}`)
44
+ }
45
+
46
+
47
+ const writeEnvLocal = async (name) => {
48
+
49
+ const existingSecret = process.env.HELLO_COOKIE_SECRET
50
+ if (existingSecret) {
51
+ console.log(`${chalk.yellowBright('⚠')} Skipping - HELLO_COOKIE_SECRET already exists`)
52
+ return
53
+ }
54
+
55
+ const secret = randomBytes(16).toString('hex')
56
+ const env = `
57
+ # added by @hellocoop/quickstart --${name} on ${(new Date()).toISOString()}
58
+ HELLO_COOKIE_SECRET='${secret}'
59
+ `
60
+ const outputFile = process.cwd()+'/'+ENV_FILE
61
+ appendFileSync(outputFile,env)
62
+ console.log(`${chalk.greenBright('✓')} Updated ${ENV_FILE} with HELLO_COOKIE_SECRET ${chalk.blueBright(secret)}`)
63
+ }
64
+
65
+ const defaultOptions = {
66
+ integration: 'quickstart-express',
67
+ suffix: 'Express App',
68
+ wildcard_domain: true,
69
+ provider_hint: 'google github gitlab apple-- email--'
70
+ }
71
+ const express = async (options, name = 'express') => {
72
+ dotenv.config()
73
+ options = { ...defaultOptions, ...options }
74
+ try {
75
+ await writeConfig(options,name)
76
+ await writeEnvLocal(name)
77
+ } catch (e) {
78
+ console.error(e)
79
+ process.exit(1)
80
+ }
81
+ }
82
+
83
+ export default express
84
+
85
+
86
+
87
+
88
+
89
+
package/fastify.mjs ADDED
@@ -0,0 +1,14 @@
1
+ // fastify.mjs
2
+
3
+ import express from './express.mjs'
4
+
5
+ const defaultOptions = {
6
+ integration: 'quickstart-fastify',
7
+ suffix: ' Fastify App',
8
+ }
9
+
10
+ const fastify = async ( options ) => {
11
+ await express({ ...defaultOptions, ...options }, 'fastify')
12
+ }
13
+
14
+ export default fastify
package/index.js CHANGED
@@ -33,6 +33,8 @@ const quickstart = async function (params) {
33
33
  paramKeys.forEach( param => {
34
34
  if (!validQuickstartParams.includes(param))
35
35
  throw(new Error(`Invalid param:${param}`))
36
+ if (!params[param])
37
+ delete params[param]
36
38
  })
37
39
  }
38
40
 
@@ -67,14 +69,14 @@ const quickstart = async function (params) {
67
69
  const hellooDomain = process.env.HELLO_DOMAIN || 'hello.coop'
68
70
  const quickstartURL = `https://quickstart.${hellooDomain}/?${queryString}`
69
71
  server.listen(port, host, () => {
70
- console.log('\nObtaining a client_id with Hellō Quickstart\n')
72
+ console.log('Obtaining a Hellō client_id with:')
71
73
  console.log(chalk.blueBright(quickstartURL))
72
74
  const rl = readline.createInterface({
73
75
  input: process.stdin,
74
76
  output: process.stdout
75
77
  });
76
78
 
77
- rl.question('\nPress ENTER to open in the browser...', (answer) => {
79
+ rl.question('Press ENTER to open in the browser...', (answer) => {
78
80
  open(quickstartURL)
79
81
  rl.close();
80
82
  });
package/next.mjs CHANGED
@@ -4,7 +4,6 @@ import semver from 'semver';
4
4
  import { statSync, appendFileSync } from 'fs'
5
5
  import chalk from 'chalk';
6
6
  import fs from 'fs-extra'
7
- import 'dotenv/config'
8
7
  import quickstart from './index.js';
9
8
  import { randomBytes } from 'crypto'
10
9
 
@@ -12,6 +11,8 @@ const HELLO_CONFIG_FILE = 'hello.config.ts'
12
11
  const HELLO_COOP_FILE = 'pages/api/hellocoop.ts'
13
12
  const ENV_FILE = '.env.local'
14
13
 
14
+ import dotenv from 'dotenv'
15
+
15
16
  // check if @hellocoop/nextjs is installed
16
17
 
17
18
 
@@ -26,64 +27,55 @@ const writeConfig = async (options) => {
26
27
  config.client_id = '${client_id}'
27
28
  `
28
29
  appendFileSync( filePath, append)
29
- console.log(`\nUpdated ${filePath} with:`)
30
- console.log(chalk.blueBright(append))
30
+ console.log(`${chalk.greenBright('✓')} Updated ${HELLO_CONFIG_FILE} with client_id ${chalk.blueBright(client_id)}`)
31
31
  return
32
32
  } catch (err) {
33
- if (err.code !== 'ENOENT') { // file does not exist
33
+ if (err.code !== 'ENOENT') { // error other than file does not exist
34
34
  throw(err)
35
35
  }
36
36
  }
37
37
  const config =`// ${HELLO_CONFIG_FILE}
38
- import { Config } from '@hellocoop/nextjs'
38
+ // see https://hello.dev/docs/sdks/nextjs/#configuration for details
39
+ import type { Config } from '@hellocoop/nextjs'
39
40
 
40
41
  const config = {
41
42
  client_id: '${client_id}',
42
- // see https://hello.dev/docs/sdks/nextjs/#configuration for details
43
- // scope:[]
44
- // provider_hint:[]
45
43
  }
46
44
  export default config
47
45
  `
48
46
  fs.outputFileSync( filePath, config)
49
- console.log(`created ${filePath} with\nclient_id:${chalk.blueBright(client_id)}`)
50
- // console.log(
51
- // `You can update the:
52
- // - Application Logo
53
- // - Application Name
54
- // - Terms of Service URL
55
- // - Privacy Policy URL
56
- // - Redirect URIs
57
- // at the Hellō Developer Console https://console.hello.coop`)
47
+ console.log(`${chalk.greenBright('✓')} Created ${HELLO_CONFIG_FILE} with client_id ${chalk.blueBright(client_id)}`)
58
48
  }
59
49
 
60
50
  const writeHelloCoop = async () => {
61
51
  const filePath = process.cwd()+'/'+HELLO_COOP_FILE
62
52
  try {
63
53
  statSync(filePath);
64
- console.error(`${HELLO_COOP_FILE} already exists at:\n${filePath}\nSkipping creating file`)
54
+ console.log(`${chalk.yellowBright('⚠')} Skipping - ${HELLO_COOP_FILE} already exists`)
65
55
  return
66
56
  } catch (err) {
67
- if (err.code !== 'ENOENT') { // file does not exist
57
+ if (err.code !== 'ENOENT') { // error other than file does not exist
68
58
  throw(err)
69
59
  }
70
60
  }
71
61
 
72
62
  const content = `// ${HELLO_COOP_FILE}
73
63
  // generated by @hellocoop/quickstart --nextjs on ${(new Date()).toISOString()}
74
- // this file should not need to be edited
64
+ // NOTE: this file should not need to be edited
75
65
  import config from '../../hello.config'
76
66
  import { pageAuth } from '@hellocoop/nextjs'
77
67
  export default pageAuth(config)
78
68
  `
79
69
  fs.outputFileSync( filePath, content )
70
+ console.log(`${chalk.greenBright('✓')} Created ${HELLO_COOP_FILE}`)
71
+
80
72
  }
81
73
 
82
74
 
83
75
  const writeEnvLocal = async () => {
84
76
  const existingSecret = process.env.HELLO_COOKIE_SECRET
85
77
  if (existingSecret) {
86
- console.error(`HELLO_COOKIE_SECRET already set to ${existingSecret}`)
78
+ console.log(`${chalk.yellowBright('⚠')} Skipping - HELLO_COOKIE_SECRET already exists`)
87
79
  return
88
80
  }
89
81
 
@@ -94,15 +86,23 @@ HELLO_COOKIE_SECRET='${secret}'
94
86
  `
95
87
  const outputFile = process.cwd()+'/'+ENV_FILE
96
88
  appendFileSync(outputFile,env)
97
- console.log(`\nUpdated ${outputFile} with:`)
98
- console.log(chalk.blueBright(env))
89
+ console.log(`${chalk.greenBright('✓')} Updated ${ENV_FILE} with HELLO_COOKIE_SECRET ${chalk.blueBright(secret)}`)
90
+ }
91
+
92
+ const defaultOptions = {
93
+ integration: 'quickstart-nextjs',
94
+ suffix: 'Next.js App',
95
+ wildcard_domain: true,
96
+ provider_hint: 'google github gitlab apple-- email--'
99
97
  }
100
98
 
101
99
  const next = async (options) => {
100
+ dotenv.config({ path: './.env.local' })
101
+ options = { ...defaultOptions, ...options }
102
102
  try {
103
+ await writeConfig(options)
103
104
  await writeHelloCoop()
104
105
  await writeEnvLocal()
105
- await writeConfig(options)
106
106
  } catch (e) {
107
107
  console.error(e)
108
108
  process.exit(1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellocoop/quickstart",
3
- "version": "2.5.3",
3
+ "version": "2.6.0",
4
4
  "description": "A CLI and module to start the Hello Quickstart web app and return a client_id",
5
5
  "main": "index.js",
6
6
  "bin": {
package/quickstart.mjs CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import semver from 'semver';
4
- import next from './next.mjs'
4
+ import nextConfig from './next.mjs'
5
+ import expressConfig from './express.mjs'
6
+ import fastifyConfig from './fastify.mjs'
5
7
 
6
8
  const requiredVersion = '>=18.3.0';
7
9
 
@@ -20,53 +22,70 @@ if (!process.stdout.isTTY) {
20
22
  }
21
23
 
22
24
  let {
23
- values: { nextjs, provider_hint, suffix, file, secret, wildcard, integration, debug },
25
+ values: { nextjs, express, fastify, provider_hint, suffix, wildcard_domain, integration },
24
26
  } = parseArgs({
25
27
  options: {
26
28
  nextjs: {
27
29
  type: "boolean"
28
30
  },
31
+ express: {
32
+ type: "boolean"
33
+ },
34
+ fastify: {
35
+ type: "boolean"
36
+ },
29
37
  provider_hint: {
30
38
  type: "string",
31
39
  short: "p",
32
- default: '',
33
40
  },
34
41
  suffix: {
35
42
  type: "string",
36
43
  short: "x",
37
- default: '',
38
44
  },
39
45
  integration: {
40
46
  type: "string",
41
47
  short: "i",
42
- default: ''
43
48
  },
44
- wildcard: {
49
+ wildcard_domain: {
45
50
  type: "boolean",
46
51
  short: "w",
47
52
  }
48
53
  },
49
54
  });
50
55
 
51
- import 'dotenv/config'
52
56
  import quickstart from './index.js';
57
+ import dotenv from 'dotenv'
58
+
59
+ const options = {}
60
+ if (provider_hint)
61
+ options.provider_hint = provider_hint
62
+ if (suffix)
63
+ options.suffix = suffix
64
+ if (integration)
65
+ options.integration = integration
66
+ if (wildcard_domain)
67
+ options.wildcard_domain = wildcard
53
68
 
54
- (async () => {
69
+ ;(async () => {
55
70
 
56
71
  if (nextjs) {
57
- await next({ provider_hint, suffix, integration })
72
+ await nextConfig(options)
73
+ process.exit(0)
74
+ }
75
+
76
+ if (express) {
77
+ await expressConfig(options)
78
+ process.exit(0)
79
+ }
80
+
81
+ if (fastify) {
82
+ await fastifyConfig(options)
58
83
  process.exit(0)
59
84
  }
60
85
 
61
- const options = {}
62
- if (provider_hint)
63
- options.provider_hint = provider_hint
64
- if (suffix)
65
- options.suffix = suffix
66
- if (integration)
67
- options.integration = integration
68
- if (wildcard)
69
- options.wildcard_domain = wildcard
86
+ // direct invocation
87
+
88
+ dotenv.config() // .env
70
89
 
71
90
  const client_id = await quickstart(options)
72
91
  console.log(`client_id=${client_id}`)