@hellocoop/quickstart 2.5.4 → 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
 
package/next.mjs CHANGED
@@ -12,11 +12,6 @@ const HELLO_COOP_FILE = 'pages/api/hellocoop.ts'
12
12
  const ENV_FILE = '.env.local'
13
13
 
14
14
  import dotenv from 'dotenv'
15
- dotenv.config({ path: './.env.local' })
16
-
17
-
18
- console.log('domain',process.env.HELLO_DOMAIN)
19
- console.log('secret',process.env.HELLO_COOKIE_SECRET)
20
15
 
21
16
  // check if @hellocoop/nextjs is installed
22
17
 
@@ -94,9 +89,16 @@ HELLO_COOKIE_SECRET='${secret}'
94
89
  console.log(`${chalk.greenBright('✓')} Updated ${ENV_FILE} with HELLO_COOKIE_SECRET ${chalk.blueBright(secret)}`)
95
90
  }
96
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--'
97
+ }
98
+
97
99
  const next = async (options) => {
98
- if (!options.provider_hint)
99
- options.provider_hint = 'google github gitlab apple-- email--'
100
+ dotenv.config({ path: './.env.local' })
101
+ options = { ...defaultOptions, ...options }
100
102
  try {
101
103
  await writeConfig(options)
102
104
  await writeHelloCoop()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellocoop/quickstart",
3
- "version": "2.5.4",
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,28 +22,31 @@ if (!process.stdout.isTTY) {
20
22
  }
21
23
 
22
24
  let {
23
- values: { nextjs, provider_hint, suffix, wildcard, integration },
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
  }
@@ -51,24 +56,36 @@ let {
51
56
  import quickstart from './index.js';
52
57
  import dotenv from 'dotenv'
53
58
 
54
- (async () => {
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
68
+
69
+ ;(async () => {
55
70
 
56
71
  if (nextjs) {
57
- await next({ provider_hint, suffix, integration })
72
+ await nextConfig(options)
58
73
  process.exit(0)
59
74
  }
60
75
 
61
- dotenv.config() // .env
76
+ if (express) {
77
+ await expressConfig(options)
78
+ process.exit(0)
79
+ }
80
+
81
+ if (fastify) {
82
+ await fastifyConfig(options)
83
+ process.exit(0)
84
+ }
85
+
86
+ // direct invocation
62
87
 
63
- const options = {}
64
- if (provider_hint)
65
- options.provider_hint = provider_hint
66
- if (suffix)
67
- options.suffix = suffix
68
- if (integration)
69
- options.integration = integration
70
- if (wildcard)
71
- options.wildcard_domain = wildcard
88
+ dotenv.config() // .env
72
89
 
73
90
  const client_id = await quickstart(options)
74
91
  console.log(`client_id=${client_id}`)