-
Notifications
You must be signed in to change notification settings - Fork 1
/
setupScript.js
90 lines (76 loc) · 2.68 KB
/
setupScript.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
const fs = require('fs-extra');
const path = require('path');
/**
*
* This setup script clones all boilerplate to a parent project.
* It is to be run inside of a project that was just created.
* It means it must be run within a subfolder of the root project.
* if you're in parent-app, then you clone this repo and run this script.
*
* For example:
* create-next-app my-app
* cd my-app
* git clone https://github.com/ianmiller347/the-posting-platform.git
* cd the-posting-platform
* yarn run setup-script
*
* now, the parent application is where we want to copy folders to.
*
* the function is called when this file is called by node, but also exported
* so that other files can pass in pathPrefix if we create in subdirectory
* when global npm module is installed by a user
*
*/
// Function to copy files from source directory to destination directory
async function copyDirectories(directories, destinationPrefix) {
try {
for (const directory of directories) {
// const source = directory;
const source = path.resolve(__dirname, directory);
const destination = path.join(destinationPrefix, directory);
await fs.copy(source, destination, { recursive: true });
console.log(`Copied ${source} to ${destination}`);
}
} catch (error) {
console.error('Error copying directories:', error);
}
}
// Define the source directory in your npm package containing the files to copy
// const sourceDirectory = path.resolve(__dirname, 'source');
// Copy files from the source directory to the project directory
// await copyFiles(sourceDirectory, projectDirectory);
// function to copy folders over
const copyFoldersOver = async (destinationPathPrefix = '..', options = {}) => {
// copy the directories over first
const defaultSourceDirectories = [
'components',
'helpers',
'hooks',
'pages',
'state',
'styles',
'types',
];
const direcoriesToCopy = options.direcoriesToCopy || defaultSourceDirectories;
await copyDirectories(direcoriesToCopy, destinationPathPrefix);
console.log('Folders copied successfully.');
// Next we will copy the config files that are in the current root over to the new project
// Array of files to copy
const defaultFilesToCopy = [
'tsconfig.json',
'.prettierrc',
'tailwind.config.js',
'.lintstagedrc.js',
'.eslintrc.json',
'platform.config.js',
];
const filesToCopy = options.filesToCopy || defaultFilesToCopy;
// Copy each file to the parent directory
filesToCopy.forEach((file) => {
fs.copySync(file, `${destinationPathPrefix}/${file}`);
});
console.log('All files copied successfully.');
};
copyFoldersOver();
module.exports = copyFoldersOver;