Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions packages/cli-ui/public/icons/rnk-loader.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 58 additions & 62 deletions packages/cli-ui/server/connectors/folders.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,76 @@
const fs = require('fs')


class FolderApi {

constructor(client) {
this.client = client
}
constructor (client) {
this.client = client
}

/**
/**
* Get list folders
* @param {string} url URL folder
* @param {boolian} hidden Hidden folder with dot
*/
getFolders(url, hidden) {
try {

const data = {
folder: url || '/',
isHidden: hidden || false,
projects: []
getFolders (url, hidden) {
try {
const data = {
folder: url || '/',
isHidden: hidden || false,
projects: []
}

fs.readdir(data.folder, (err, files) => {
if (err) {
this.client.emit('erro', {
message: 'Ошибка работы с файловой системой',
error: err
})
}

if (files) {
files.forEach(file => {
if (data.isHidden && !file.match(/\.[0-9a-z]{1,5}$/)) {
return data.projects.push(file)
} else if (!file.startsWith('.') && !file.match(/\.[0-9a-z]{1,5}$/)) {
return data.projects.push(file)
}

fs.readdir(data.folder, (err, files) => {

if (err) {
this.client.emit('erro', {
message: 'Ошибка работы с файловой системой',
error: err
})
}

if(files){
files.forEach(file => {
if (data.isHidden && !file.match(/\.[0-9a-z]{1,5}$/)) {
return data.projects.push(file)
} else if (!file.startsWith('.') && !file.match(/\.[0-9a-z]{1,5}$/)) {
return data.projects.push(file)
}
})
}

this.client.emit('folders', {
data: data.projects
})
})
} catch (error) {
this.client.emit('erro', {
message: 'Что-то пошло не так, попробуйте снова',
error
})
}
})
}

this.client.emit('folders', {
data: data.projects
})
})
} catch (error) {
this.client.emit('erro', {
message: 'Что-то пошло не так, попробуйте снова',
error
})
}
}

/**
/**
* Create new folder
* @param {string} dir URL for new folder
*/
async createFolder(dir) {
try {
if (dir && !fs.existsSync(dir)) {
await fs.mkdirSync(dir, { recursive: true })
this.client.emit("notification",{
message: 'Folder successfully create'
})
} else {
this.client.emit("notification",{
message: 'Folder already exists'
})
}
} catch (error) {
this.client.emit('erro', {
message: 'Что-то пошло не так, попробуйте снова',
error
})
}
async createFolder (dir) {
try {
if (dir && !fs.existsSync(dir)) {
await fs.mkdirSync(dir, { recursive: true })
this.client.emit('notification', {
message: 'Folder successfully create'
})
} else {
this.client.emit('notification', {
message: 'Folder already exists'
})
}
} catch (error) {
this.client.emit('erro', {
message: 'Что-то пошло не так, попробуйте снова',
error
})
}
}
}

module.exports = FolderApi
79 changes: 45 additions & 34 deletions packages/cli-ui/server/connectors/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,45 +52,56 @@ class ProjectApi {
* @param {string} manager Manager new project (npm/yarn)
* @param {string} preset Preset new project (create-react-app/other...)
*/
async createProject (name, pathProject, manager, preset) {
let subprocess
if (manager === 'npm') {
subprocess = craNpm(pathProject, name)
} else {
subprocess = craYarn(pathProject, name)
}
createProject (name, pathProject, manager, preset) {
fs.readdir(path.join('/', ...pathProject, name), async (err, files) => {
if (err) {
let subprocess
if (manager === 'npm') {
subprocess = craNpm(pathProject, name)
} else {
subprocess = craYarn(pathProject, name)
}

try {
subprocess.stdout.pipe(process.stdout)
try {
subprocess.stdout.pipe(process.stdout)

subprocess.stdout.on('data', data => {
this.client.emit('check', {
message: data.toString('utf8')
})
})
subprocess.stdout.on('data', data => {
this.client.emit('check', {
message: data.toString('utf8')
})
})

const { stdout } = await subprocess

// add db project
if (stdout) {
db.get('projects').push({
id: db.get('projects').value().length + 1,
name,
path: pathProject,
manager,
preset,
favorite: false
}).write()
const { stdout } = await subprocess

// add db project
if (stdout) {
db.get('projects').push({
id: db.get('projects').value().length + 1,
name,
path: pathProject,
manager,
preset,
favorite: false
}).write()
}

this.client.emit('notification', {
message: 'Project successfully create'
})
} catch (error) {
this.client.emit('erro', {
message: 'Что-то пошло не так, попробуйте снова'
})
}
}

this.client.emit('notification', {
message: 'Project successfully create'
})
} catch (error) {
this.client.emit('erro', {
message: 'Что-то пошло не так, попробуйте снова'
})
}
if (files) {
this.client.emit('erro', {
title: 'Ошибка создания проекта',
message: `Директория ${name} - уже существует`
})
}
})
}

/**
Expand Down
Loading