Skip to content

Commit

Permalink
only create default projects if it does not exist #3
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Oct 16, 2021
1 parent c1ace0a commit b638291
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/phoenix/init_vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ function _setupVFS(Phoenix, fsLib, pathLib){
cb();
});
},
exists: function (path, cb) {
fs.stat(path, function (err, stats){
if (stats && !err) {
cb(true);
} else {
cb(false);
}
});
},
fs: fsLib,
path: pathLib,
getFsEncoding: _getFsEncoding
Expand Down Expand Up @@ -126,12 +135,16 @@ const _SAMPLE_HTML = `<!DOCTYPE html>
const _createDefaultProject = function (vfs) {
// Create phoenix app dirs
// Create Phoenix default project if it doesnt exist
vfs.ensureExistsDir(vfs.getDefaultProjectDir(), errorCb);
let projectDir = vfs.getDefaultProjectDir();
let indexFile = vfs.path.normalize(`${projectDir}/index.html`);
vfs.fs.stat(indexFile, function (err){
if (err && err.code === 'ENOENT') {
fs.writeFile(indexFile, _SAMPLE_HTML, 'utf8', errorCb);
vfs.exists(vfs.getDefaultProjectDir(), (exists)=>{
if(!exists){
vfs.ensureExistsDir(vfs.getDefaultProjectDir(), errorCb);
let projectDir = vfs.getDefaultProjectDir();
let indexFile = vfs.path.normalize(`${projectDir}/index.html`);
vfs.fs.stat(indexFile, function (err){
if (err && err.code === 'ENOENT') {
fs.writeFile(indexFile, _SAMPLE_HTML, 'utf8', errorCb);
}
});
}
});
};
Expand Down

0 comments on commit b638291

Please sign in to comment.