-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·60 lines (46 loc) · 1.84 KB
/
index.js
File metadata and controls
executable file
·60 lines (46 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bun
import { execSync } from 'node:child_process'
import { cpSync, existsSync, lstatSync, mkdirSync, renameSync, rmdirSync, unlinkSync } from 'node:fs'
import { dirname, join } from 'node:path'
import customize from './customize.js'
import names from './names.js'
const args = process.argv
if (args.length < 3) {
console.error('Please provide a name for your plugin.')
process.exit()
}
const name = names(args[2])
if (existsSync(name.regular)) {
console.warn(`A folder or file named ${name.regular} already exists in ${process.cwd()}.`)
process.exit()
}
if (existsSync(name.regular)) {
if (lstatSync(name.regular).isDirectory()) {
rmdirSync(name.regular, { recursive: true })
} else {
unlinkSync(name.regular)
}
}
mkdirSync(name.regular)
const packagePath = dirname(new URL(import.meta.url).pathname)
const templateDirectory = join(packagePath, 'template')
const destinationDirectory = join(process.cwd(), name.regular)
cpSync(templateDirectory, destinationDirectory, { recursive: true })
const npmIgnorePath = join(destinationDirectory, '.npmignore')
if (existsSync(npmIgnorePath)) {
// npm will apparently rename .gitignore outside a repo to prevent accidentially publishing.
// Since this template specifies "files" in package.json that doesn't happen.
renameSync(npmIgnorePath, join(destinationDirectory, '.gitignore'))
}
customize(name, destinationDirectory)
console.log('Installing dependencies...')
execSync('bun install', {
cwd: destinationDirectory,
stdio: 'inherit',
})
console.log('')
console.log(`😃 Created new plugin called ${name.regular} in ${destinationDirectory}.`)
console.log('🛠️ Start coding in the file ./index.tsx.')
console.log('🛠️ To preview the plugin edit app/App.tsx and create a React Native installation with:')
console.log(`🐚 cd ${name.regular}`)
console.log('🐚 bun app')