Skip to content

Commit

Permalink
Wrap up create project
Browse files Browse the repository at this point in the history
  • Loading branch information
mglaman committed Oct 24, 2016
1 parent e042478 commit 2e10831
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 20 deletions.
40 changes: 37 additions & 3 deletions css/conductor.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion css/conductor.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function createMainWindow() {
function createProjectWindow(folder) {
try {
activeProject = new Project(folder);
mainWindow.close();
projectWindow = new BrowserWindow({width: 800, height: 600});
projectWindow.loadURL(`file://${__dirname}/windows/project/project.html`);
// projectWindow.webContents.openDevTools();
Expand All @@ -51,6 +50,7 @@ function createProjectWindow(folder) {
createMainWindow();
});
} catch (e) {
console.error(e);
dialog.showMessageBox({
'type': 'error',
'buttons': [],
Expand Down Expand Up @@ -79,14 +79,14 @@ function createPackageWindow(packageName) {

function createCreateWindow() {
mainWindow.close();
createWindow = new BrowserWindow({width: 500, height: 250});
createWindow = new BrowserWindow({width: 500, height: 450});
createWindow.loadURL(`file://${__dirname}/windows/create/create.html`);
// packageWindow.webContents.openDevTools();
createWindow.on('closed', () => {
activeProject = null;
projectWindow = null;
createMainWindow();
createWindow = null;
createMainWindow();
});
}

Expand All @@ -108,6 +108,14 @@ app.on('activate', function () {
}
});

exports.fromNewProject = function (folder) {
var composerJson = require(folder + '/composer.json');
var projectsJson = require(userData + '/projects.json');
projectsJson[folder] = composerJson.name;
fs.writeFile(userData + '/projects.json', JSON.stringify(projectsJson));
// createProjectWindow(folder);
};

const openDirectory = function () {
var folder = dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory'],
Expand Down
33 changes: 32 additions & 1 deletion scss/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ h1, h2, h3, h4, h5, h6,
p {
margin-top: 0;
}
input {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
font-size: 1rem;
padding: 0.5rem;
margin: 0.25rem;
border-radius: 0.25rem;
border: 1px solid #d5d5d5;
}

details {
padding: 0 1rem;
Expand Down Expand Up @@ -111,7 +119,7 @@ button {
}
}
}
.project__actions {
.button__actions {
//flex: 1;
//align-items: flex-end;
button {
Expand Down Expand Up @@ -153,3 +161,26 @@ button {
.project__dependencies-list li {
cursor: pointer;
}

.window__create-project {
.button__actions {
margin-top: 1rem;
}
button {
display: block;
padding: 0.35rem;
background-image: linear-gradient(#fcfcfc, #eee);
border: 1px solid #d5d5d5;
border-radius: 3px;
&:focus {
outline: 0;
border: 1px solid #aaa;
}
&:hover {
background: darken($dark-gray, .75);
}
}
#project-destination {
cursor: pointer;
}
}
3 changes: 3 additions & 0 deletions utils/Composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ let Composer = function(projectPath, appPath) {
this.remove = (dependency, opts, callback) => {
this._runCommand(bin + ' remove ' + dependency, opts, callback);
};
this.createProject = (project, destination, opts, callback) => {
this._runCommand(bin + ' create-project ' + project + ' ' + destination + ' --stability dev', opts, callback)
};
this._runCommand = (command, opts, callback) => {
opts['cwd'] = this.path;
console.log(command);
Expand Down
28 changes: 18 additions & 10 deletions windows/create/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@
<meta charset="UTF-8">
<title>Conductor - the Composer UI</title>
<link href="../../node_modules/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css" />
<link href="../../css/composer-gui.css" rel="stylesheet" type="text/css"/>
<link href="../../css/conductor.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="flex flex--column flex--grow" style="padding: 2rem;">
<div class="flex flex--column flex--grow window__create-project" style="padding: 1rem;">
<div class="flex flex--row">
<label for="packageName"><span>Project name:</span></label>
<input type="text" name="packageName" id="packageName" />
<label for="packageName" class="sr-only"><span>Project name:</span></label>
<input type="text" name="packageName" id="packageName" placeholder="vendor/package" style="flex: 1;"/>
</div>
<div class="flex flex--row">
<label for="destination"><span>Destination:</span></label>
<div>
<input type="text" name="destination" id="destination" />
<button class="button"><i class="fa fa-search"></i>Browse</button>
</div>
<label for="packageName" class="sr-only"><span>Project name:</span></label>
<input type="text" name="projectName" id="projectName" placeholder="some-dir" style="flex: 1;"/>
</div>
<div class="flex flex--row">
<button>Create project!</button>
<label for="destination" class="sr-only"><span>Destination:</span></label>
<div class="flex flex--row" style="flex: 1;" id="project-destination">
<input type="text" name="destination" id="destination" placeholder="Destination" style="flex: 1;" disabled/>
<button class="button">Browse <i class="fa fa-search"></i></button>
</div>
</div>
<div class="flex flex--row button__actions">
<button class="flex" id="project-create">Create project! <i class="fa fa-spin fa-circle-o-notch hidden"></i></button>
</div>
<textarea title="Composer output" class="project__output" id="composer-output" disabled></textarea>
</div>
<script>
require('./createWindow')
</script>
</body>
</html>
60 changes: 60 additions & 0 deletions windows/create/createWindow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const fs = require('fs');
const electron = require('electron');
const remote = electron.remote;
const dialog = remote.dialog;
const thisWindow = remote.getCurrentWindow();
const mainProcess = remote.require('./main');

const Composer = require('../../utils/Composer');
let composer = new Composer(electron.remote.app.getAppPath(), electron.remote.app.getAppPath());
let elDestDir = document.getElementById('destination');
let elPackageName = document.getElementById('packageName');
let elProjectName = document.getElementById('projectName');
let elOutput = document.getElementById('composer-output');

let composerOutputHandler = (ex, stdout, stderr) => {
if (ex !== null) {
elOutput.value = composer.cleanUpOutput(ex);
} else {
if (stdout.length > 0) {
elOutput.value += composer.cleanUpOutput(stdout);
}
if (stderr.length > 0) {
elOutput.value += composer.cleanUpOutput(stderr);
}
}
};

document.getElementById('project-destination').addEventListener('click', projectDestinationBrowse);
document.getElementById('project-destination').addEventListener('onfocus', projectDestinationBrowse);

function projectDestinationBrowse() {
var folder = dialog.showOpenDialog(thisWindow, {
properties: ['openDirectory'],
});
if (!folder) {
elDestDir.value = '';
}
elDestDir.value = folder;
}

document.getElementById('project-create').addEventListener('click', (e) => {
let packageName = elPackageName.value;
let projectDest = elDestDir.value + '/' + elProjectName.value;

let opts = ['--no-interaction'];

elOutput.value = '';
var el = /** @type {Element} */ e.srcElement;
var elIcon = el.childNodes[1];

elIcon.classList.remove('hidden');
composer.createProject(packageName, projectDest, opts, (ex, stdout, stderr) => {
composerOutputHandler(ex, stdout, stderr);
elIcon.classList.add('hidden');
if (fs.existsSync(projectDest + '/composer.json')) {
mainProcess.fromNewProject(projectDest);
thisWindow.close();
}
});
});
2 changes: 1 addition & 1 deletion windows/package/package.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1 id="package-name"></h1>
<span class="package__details--value" id="package-description"></span>
</li>
</ul>
<div class="flex flex--row project__actions">
<div class="flex flex--row button__actions">
<button class="flex" id="action-composer-update">Update <i class="fa fa-spin fa-circle-o-notch hidden"></i></button>
<button class="flex" id="action-composer-remove">Remove <i class="fa fa-spin fa-circle-o-notch hidden"></i></button>
<button class="flex" id="action-composer-show">Show <i class="fa fa-spin fa-circle-o-notch hidden"></i></button>
Expand Down
2 changes: 1 addition & 1 deletion windows/project/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1 id="project-name"></h1>
</div>
<p id="project-description"></p>
<p id="project-url"></p>
<div class="flex flex--row project__actions">
<div class="flex flex--row button__actions">
<button class="flex" id="action-composer-install">Install <i class="fa fa-spin fa-circle-o-notch hidden"></i></button>
<button class="flex" id="action-composer-update">Update <i class="fa fa-spin fa-circle-o-notch hidden"></i></button>
<button class="flex" id="action-composer-validate">Validate <i class="fa fa-spin fa-circle-o-notch hidden"></i></button>
Expand Down

0 comments on commit 2e10831

Please sign in to comment.