forked from tiago-cristiano-inovan-do/adonis-crud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstructions.ts
76 lines (63 loc) · 2.54 KB
/
instructions.ts
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
67
68
69
70
71
72
73
74
75
76
import fs from 'fs'
import path from 'path'
const packageBasePath = path.resolve(`${__dirname}/templates`)
const copyFolderToProjetct = ({ pathDestiny, folder, noCaptlize = false }) => {
const capitalizedFolder = noCaptlize ? folder : folder[0].toUpperCase() + folder.slice(1)
if (!fs.existsSync(pathDestiny)) {
fs.mkdirSync(pathDestiny, { recursive: true })
}
console.log(`Coping to${folder} to project folder...`)
fs.readdirSync(`${packageBasePath}/${capitalizedFolder}`).forEach((file) => {
const [fileName, extension] = file.split('.')
fs.copyFileSync(
`${packageBasePath}/${capitalizedFolder}/${fileName}.${extension}`,
`${pathDestiny}/${fileName}.ts`,
fs.constants.COPYFILE_FICLONE
)
})
}
export default async function instructions(projectRoot: string) {
console.log('Coping Transformers')
const transformerPath = `${projectRoot}/app/Transformers`
copyFolderToProjetct({ pathDestiny: transformerPath, folder: 'Transformers' })
console.log('Coping Repository')
const RepositoryPath = `${projectRoot}/app/Repositories`
copyFolderToProjetct({ pathDestiny: RepositoryPath, folder: 'Repositories' })
console.log('Coping Models')
const modelPath = `${projectRoot}/app/Models`
copyFolderToProjetct({ pathDestiny: modelPath, folder: 'Models' })
console.log('Coping Controller')
const controllerPath = `${projectRoot}/app/Controllers/Http`
copyFolderToProjetct({ pathDestiny: controllerPath, folder: 'Controllers' })
console.log('Coping Providers')
const providersPath = `${projectRoot}/providers`
copyFolderToProjetct({ pathDestiny: providersPath, folder: 'providers', noCaptlize: true })
console.log('Coping DatabaseFiles (Migrations)')
const dataBasePath = `${projectRoot}/database/migrations`
copyFolderToProjetct({
pathDestiny: dataBasePath,
folder: 'database/migrations',
noCaptlize: true,
})
console.log('Coping DatabaseFiles (seeds)')
const dataBaseSeedsPath = `${projectRoot}/database/seeders`
copyFolderToProjetct({
pathDestiny: dataBaseSeedsPath,
folder: 'database/seeders',
noCaptlize: true,
})
console.log('Coping DatabaseFiles (factories)')
const dataBaseFactoriesPath = `${projectRoot}/database/factories`
copyFolderToProjetct({
pathDestiny: dataBaseFactoriesPath,
folder: 'database/factories',
noCaptlize: true,
})
console.log('Coping code-templates')
const codeTemplatesPath = `${projectRoot}/code-templates`
copyFolderToProjetct({
pathDestiny: codeTemplatesPath,
folder: 'code-templates',
noCaptlize: true,
})
}