@hellocoop/quickstart 1.1.0 → 2.0.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.
Files changed (3) hide show
  1. package/index.js +2 -2
  2. package/package.json +7 -3
  3. package/quickstart.mjs +122 -3
package/index.js CHANGED
@@ -66,8 +66,8 @@ const quickstart = async function (params) {
66
66
  const hellooDomain = process.env.HELLO_DOMAIN || 'hello.coop'
67
67
  const quickstartURL = `https://quickstart.${hellooDomain}/?${queryString}`
68
68
  server.listen(port, host, () => {
69
- console.log('Obtaining a client_id from Hellō Quickstart using:')
70
- console.log(quickstartURL)
69
+ console.log('Obtaining a client_id with Hellō Quickstart')
70
+ // console.log(quickstartURL)
71
71
  const rl = readline.createInterface({
72
72
  input: process.stdin,
73
73
  output: process.stdout
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellocoop/quickstart",
3
- "version": "1.1.0",
3
+ "version": "2.0.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": {
@@ -36,7 +36,11 @@
36
36
  "dependencies": {
37
37
  "dotenv": "^16.3.1",
38
38
  "get-port": "^7.0.0",
39
- "open": "^9.1.0"
39
+ "open": "^9.1.0",
40
+ "semver": "^7.5.4"
40
41
  },
41
- "type": "module"
42
+ "type": "module",
43
+ "engines": {
44
+ "node": ">=18.3"
45
+ }
42
46
  }
package/quickstart.mjs CHANGED
@@ -1,6 +1,125 @@
1
1
  #!/usr/bin/env node
2
+ import semver from 'semver';
3
+ import * as fs from 'fs'
4
+
5
+ const requiredVersion = '>=18.3.0';
6
+
7
+ if (!semver.satisfies(process.versions.node, requiredVersion)) {
8
+ console.error(`This script requires Node.js version ${requiredVersion}`);
9
+ process.exit(1);
10
+ }
11
+
12
+ // following are in Nodejs 18+
13
+ import { parseArgs } from "node:util";
14
+ import { randomBytes } from 'crypto'
15
+
16
+ if (!process.stdout.isTTY) {
17
+ const error = new Error('Not running on interactive terminal. Exiting Hellō Quickstart.')
18
+ console.error(error)
19
+ process.exit(1);
20
+ }
21
+
22
+ const {
23
+ values: { provider_hint, suffix, file, secret, wildcard, integration, debug },
24
+ } = parseArgs({
25
+ options: {
26
+ provider_hint: {
27
+ type: "string",
28
+ short: "p",
29
+ default: '',
30
+ },
31
+ suffix: {
32
+ type: "string",
33
+ short: "x",
34
+ default: '',
35
+ },
36
+ integration: {
37
+ type: "string",
38
+ short: "i",
39
+ default: ''
40
+ },
41
+ file: {
42
+ type: "string",
43
+ short: "f",
44
+ },
45
+ secret: {
46
+ type: "boolean",
47
+ short: "s",
48
+ },
49
+ wildcard: {
50
+ type: "boolean",
51
+ short: "w",
52
+ },
53
+ debug: {
54
+ type: "boolean",
55
+ short: "d",
56
+ },
57
+ },
58
+ });
59
+
2
60
  import 'dotenv/config'
3
- import qs from './index.js';
61
+ import quickstart from './index.js';
62
+
63
+ const existingClientId = process.env.HELLO_CLIENT_ID_DEFAULT
64
+ if (existingClientId) {
65
+ console.error(`HELLO_CLIENT_ID_DEFAULT already set to ${existingClientId}`)
66
+ process.exit(0);
67
+ }
68
+
69
+ if (debug) {
70
+ console.log('Hellō Quickstart parameters:')
71
+ if (provider_hint)
72
+ console.log(` provider_hint="${provider_hint}"`)
73
+ if (suffix)
74
+ console.log(` suffix="${suffix}"`)
75
+ if (integration)
76
+ console.log(` integration="${integration}"`)
77
+ if (file)
78
+ console.log(` writing output to "${file}"`)
79
+ console.log(` generate secret=${secret}`)
80
+ console.log(` enable wildcard=${wildcard}\n`);
81
+ }
82
+
83
+ (async () => {
84
+
85
+ const options = {
86
+ suffix,
87
+ provider_hint,
88
+ wildcard_domain: wildcard,
89
+ integration
90
+ }
91
+
92
+ const output = {}
93
+ try {
94
+ output.client_id = await quickstart(options)
95
+ } catch(err) {
96
+ console.error(err)
97
+ process.exit(1)
98
+ }
99
+ if (secret)
100
+ output.secret = randomBytes(32).toString('hex')
101
+
102
+ if (file) {
103
+ let helloConfig = `
104
+ # added by @hellocoop/quickstart-nextjs on ${(new Date()).toISOString()}
105
+ HELLO_CLIENT_ID_DEFAULT='${output.client_id}'`
106
+ if (secret) {
107
+ helloConfig +=`
108
+ HELLO_COOKIE_SECRET_DEFAULT='${output.secret}'
109
+ `
110
+ }
111
+ const outputFile = process.cwd()+'/'+file
112
+
113
+ try {
114
+ const err = fs.appendFileSync(outputFile,helloConfig)
115
+ } catch(err) {
116
+ console.err(err)
117
+ process.exit(1)
118
+ }
119
+ console.log(`\nUpdated ${outputFile} with:`)
120
+ console.log(helloConfig+'\n')
121
+ } else {
122
+ console.log(JSON.stringify(output,null,4))
123
+ }
4
124
 
5
- const client_id = await qs();
6
- console.log({ client_id });
125
+ })();