Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
115 lines (103 loc) · 4.2 KB

File metadata and controls

115 lines (103 loc) · 4.2 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const projectName = process.argv[2];
const projectVersion = process.argv[3];
const projectDescription = process.argv[4];
const repoURL = process.argv[5];
const outFolder = process.argv[6];
if (!projectName || !projectVersion || !projectDescription || !repoURL || !outFolder) {
console.log('Usage: node ./createProject.js <projectName> <projectVersion> <projectDescription> <GitHUB repo URL> <outputFolder>');
process.exit(1);
}
const fs = require('fs');
const ncp = require('ncp').ncp;
const mkdirp = require('mkdirp');
const initGit = () => {
console.log('Creating git repo...');
const git = require('simple-git')( outFolder );
git.init(function() {
git.submoduleAdd('https://github.com/geosolutions-it/MapStore2.git', 'MapStore2', function() {
console.log('git repo OK...');
});
});
};
const copyTemplates = (level, path, callback) => {
console.log('Copying templated files...');
fs.readdir('./project' + path, function(err, files) {
if (err) {
return console.log(err);
}
files.forEach(function(file, index) {
fs.stat('./project' + path + '/' + file, function(err, stats) {
if (err) {
return console.log(err);
}
if (stats.isFile()) {
fs.readFile('./project' + path + '/' + file, 'UTF-8', function(err, data) {
data = data.replace(/__PROJECTNAME__/g, projectName);
data = data.replace(/__PROJECTDESCRIPTION__/g, projectDescription);
data = data.replace(/__REPOURL__/g, repoURL);
mkdirp(outFolder + path, function(err) {
if (err) console.error(err);
else {
fs.writeFile(outFolder + path + '/' + file, data, 'UTF-8', function(err) {
if (err) {
return console.log(err);
}
console.log('Copied ' + file);
if (level === 0 && index === files.length - 1) {
initGit();
} else if (index === files.length - 1 && callback) {
callback.call();
}
});
}
});
});
} else if (stats.isDirectory()) {
if (file !== 'static') {
copyTemplates(level + 1, path + '/' + file, function() {
if (level === 0 && index === files.length - 1) {
initGit();
} else if (index === files.length - 1 && callback) {
callback.call();
}
});
}
}
});
});
});
};
const copyStaticFiles = () => {
console.log('Copying static files...');
let copied = 0;
['.editorconfig', '.eslintrc', '.eslintignore', 'LICENSE.txt', '.babelrc'].map(function(fileName) {
const toWrite = fs.createWriteStream(outFolder + '/' + fileName);
fs.createReadStream(fileName).pipe(toWrite);
console.log('Copied ' + fileName);
return toWrite;
}).forEach(function(stream) {
stream.on('finish', function() {
copied++;
if (copied === 4) {
ncp('./project/static', outFolder, function(err) {
if (err) {
return console.log(err);
}
copyTemplates(0, '');
});
}
});
});
};
function createPackageJSON() {
console.log('Creating package.json...');
const packageJSON = require('./package.json');
packageJSON.name = projectName;
packageJSON.version = projectVersion;
packageJSON.description = projectDescription;
packageJSON.repository = repoURL;
packageJSON.scripts = require('./projectScripts.json');
fs.writeFile(outFolder + '/package.json', JSON.stringify(packageJSON, null, 4), copyStaticFiles);
console.log('package.json OK');
}
createPackageJSON();
Morty Proxy This is a proxified and sanitized view of the page, visit original site.