@hellocoop/quickstart 2.5.4 → 2.6.1
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 +89 -0
- package/fastify.mjs +14 -0
- package/index.js +2 -0
- package/next.mjs +11 -10
- package/package.json +1 -1
- package/quickstart.mjs +35 -18
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
package/next.mjs
CHANGED
|
@@ -7,16 +7,11 @@ import fs from 'fs-extra'
|
|
|
7
7
|
import quickstart from './index.js';
|
|
8
8
|
import { randomBytes } from 'crypto'
|
|
9
9
|
|
|
10
|
-
const HELLO_CONFIG_FILE = 'hello.config.
|
|
11
|
-
const HELLO_COOP_FILE = 'pages/api/hellocoop.
|
|
10
|
+
const HELLO_CONFIG_FILE = 'hello.config.js'
|
|
11
|
+
const HELLO_COOP_FILE = 'pages/api/hellocoop.js'
|
|
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
|
|
|
@@ -41,7 +36,6 @@ config.client_id = '${client_id}'
|
|
|
41
36
|
}
|
|
42
37
|
const config =`// ${HELLO_CONFIG_FILE}
|
|
43
38
|
// see https://hello.dev/docs/sdks/nextjs/#configuration for details
|
|
44
|
-
import type { Config } from '@hellocoop/nextjs'
|
|
45
39
|
|
|
46
40
|
const config = {
|
|
47
41
|
client_id: '${client_id}',
|
|
@@ -94,9 +88,16 @@ HELLO_COOKIE_SECRET='${secret}'
|
|
|
94
88
|
console.log(`${chalk.greenBright('✓')} Updated ${ENV_FILE} with HELLO_COOKIE_SECRET ${chalk.blueBright(secret)}`)
|
|
95
89
|
}
|
|
96
90
|
|
|
91
|
+
const defaultOptions = {
|
|
92
|
+
integration: 'quickstart-nextjs',
|
|
93
|
+
suffix: 'Next.js App',
|
|
94
|
+
wildcard_domain: true,
|
|
95
|
+
provider_hint: 'google github gitlab apple-- email--'
|
|
96
|
+
}
|
|
97
|
+
|
|
97
98
|
const next = async (options) => {
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
dotenv.config({ path: './.env.local' })
|
|
100
|
+
options = { ...defaultOptions, ...options }
|
|
100
101
|
try {
|
|
101
102
|
await writeConfig(options)
|
|
102
103
|
await writeHelloCoop()
|
package/package.json
CHANGED
package/quickstart.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import semver from 'semver';
|
|
4
|
-
import
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
72
|
+
await nextConfig(options)
|
|
58
73
|
process.exit(0)
|
|
59
74
|
}
|
|
60
75
|
|
|
61
|
-
|
|
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
|
-
|
|
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}`)
|