-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset.js
More file actions
66 lines (50 loc) · 1.73 KB
/
Copy pathreset.js
File metadata and controls
66 lines (50 loc) · 1.73 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
61
62
63
64
65
66
import readline from 'readline'
import fs from 'fs'
import shell from 'shelljs'
import chalk from 'chalk'
const jsonFilePath = './manifest.json'
function askQuestion(query) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
return new Promise((resolve) =>
rl.question(query, (ans) => {
rl.close()
resolve(ans)
})
)
}
async function modifyJson() {
let data = fs.readFileSync(jsonFilePath, 'utf8')
let jsonFile = JSON.parse(data)
let randomNumber = Math.floor(Math.random() * 90000) + 10000
jsonFile.id = randomNumber.toString()
let pluginName = await askQuestion('What is the plugin name? ')
if (pluginName.trim() !== '') {
jsonFile.name = pluginName
// read the package.json
let packageData = fs.readFileSync('./package.json', 'utf8')
let packageJson = JSON.parse(packageData)
// convert pluginName to lowercase and replace spaces with hyphens
let packageName = pluginName.toLowerCase().replace(/\s+/g, '-')
// update the package name
packageJson.name = packageName
// write the package.json back to file
fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2), 'utf8')
}
fs.writeFileSync(jsonFilePath, JSON.stringify(jsonFile, null, 2), 'utf8')
return
}
function resetGit() {
shell.rm('-rf', '.git')
shell.exec('git init > /dev/null 2>&1')
shell.exec('git add . > /dev/null 2>&1')
shell.exec('git commit -m "Initial commit" > /dev/null 2>&1')
}
async function main() {
await modifyJson()
resetGit()
console.log(chalk.green('You are ready to start developing Figma plugin'))
}
main()