@heartheyouth/create-tool 0.0.0-stage → 0.1.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/index.js +52 -0
- package/package.json +23 -4
- package/template/.env.example +2 -0
- package/template/app/layout.jsx +16 -0
- package/template/app/page.jsx +5 -0
- package/template/gitignore +4 -0
- package/template/middleware.js +5 -0
- package/template/next.config.mjs +5 -0
- package/template/package.json +10 -0
- package/template/pnpm-workspace.yaml +4 -0
- package/README.md +0 -3
package/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `pnpm create @heartheyouth/tool my-tool` (or npm/yarn/bun): copies template/ into a new folder and
|
|
3
|
+
// installs the latest packages with the package manager it was started with
|
|
4
|
+
import { cpSync, existsSync, readdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { basename, join, resolve } from 'node:path'
|
|
6
|
+
import { spawnSync } from 'node:child_process'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
|
|
9
|
+
const DEPS = ['next@^15', 'react@^19', 'react-dom@^19', '@heartheyouth/brandbook-toolkit']
|
|
10
|
+
const DEV_DEPS = ['sass']
|
|
11
|
+
|
|
12
|
+
const dir = process.argv[2]
|
|
13
|
+
if (!dir) {
|
|
14
|
+
console.error('Give the tool a folder name: pnpm create @heartheyouth/tool my-tool')
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const target = resolve(dir)
|
|
19
|
+
if (existsSync(target) && readdirSync(target).length > 0) {
|
|
20
|
+
console.error(`${dir} already exists and isn't empty.`)
|
|
21
|
+
process.exit(1)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const name = basename(target).toLowerCase().replace(/[^a-z0-9-]+/g, '-')
|
|
25
|
+
|
|
26
|
+
// npm drops .gitignore from published packages, so the template has it without the dot
|
|
27
|
+
cpSync(fileURLToPath(new URL('template', import.meta.url)), target, { recursive: true })
|
|
28
|
+
renameSync(join(target, 'gitignore'), join(target, '.gitignore'))
|
|
29
|
+
|
|
30
|
+
const pkgPath = join(target, 'package.json')
|
|
31
|
+
writeFileSync(pkgPath, readFileSync(pkgPath, 'utf8').replace('"my-tool"', JSON.stringify(name)))
|
|
32
|
+
|
|
33
|
+
const pm = (process.env.npm_config_user_agent ?? 'npm').split('/')[0]
|
|
34
|
+
const add = pm === 'npm' ? 'install' : 'add'
|
|
35
|
+
|
|
36
|
+
function run(args) {
|
|
37
|
+
console.log(`\n> ${pm} ${args.join(' ')}`)
|
|
38
|
+
const { status } = spawnSync(pm, args, { cwd: target, stdio: 'inherit', shell: process.platform === 'win32' })
|
|
39
|
+
if (status !== 0) process.exit(status ?? 1)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log(`Creating ${name} in ${target}`)
|
|
43
|
+
run([add, ...DEPS])
|
|
44
|
+
run([add, '-D', ...DEV_DEPS])
|
|
45
|
+
|
|
46
|
+
console.log(`
|
|
47
|
+
Done. Next:
|
|
48
|
+
|
|
49
|
+
cd ${dir}
|
|
50
|
+
cp .env.example .env.local # add your dev token, see https://brandbook.heartheyouth.com/dev-token
|
|
51
|
+
${pm} run dev
|
|
52
|
+
`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heartheyouth/create-tool",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a Hear The Youth brand book tool from the starter: pnpm create @heartheyouth/tool my-tool",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/HearTheYouth/dev-hty-tool-components.git",
|
|
9
|
+
"directory": "packages/create-tool"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"bin": {
|
|
16
|
+
"create-tool": "index.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js",
|
|
20
|
+
"template"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import '@heartheyouth/brandbook-toolkit/styles.css'
|
|
2
|
+
import { BrandbookProvider, BrowserCheck } from '@heartheyouth/brandbook-toolkit'
|
|
3
|
+
|
|
4
|
+
export const metadata = { title: 'My tool' }
|
|
5
|
+
|
|
6
|
+
export default function RootLayout({ children }) {
|
|
7
|
+
return (
|
|
8
|
+
<html lang="en">
|
|
9
|
+
<body>
|
|
10
|
+
<BrandbookProvider devToken={process.env.NEXT_PUBLIC_BB_DEV_TOKEN}>
|
|
11
|
+
<BrowserCheck>{children}</BrowserCheck>
|
|
12
|
+
</BrandbookProvider>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { brandbookMiddleware } from '@heartheyouth/brandbook-toolkit/middleware'
|
|
2
|
+
|
|
3
|
+
// Direct visits get a blocked page, and only the brand book may embed the tool. Does nothing on localhost
|
|
4
|
+
export const middleware = brandbookMiddleware()
|
|
5
|
+
export const config = { matcher: ['/((?!_next/|favicon.ico|.*\\..*).*)'] }
|
package/README.md
DELETED