Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exponent templates #263

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/app
/dist
/desktop/tests/integration/snapshot/tmp

tools/.hyperinstall-state.json
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,11 @@ Linux is not supported at this time.
Windows is not supported at this time.

### Clone and Install Dependencies

```
$ git clone git@github.com:decosoftware/deco-ide
$ cd ./deco-ide/web
$ npm install
$ bundle install
$ cd ../desktop
$ npm install
$ npm run copy-libs
$ cd ../shared
$ npm install
$ cd ../desktop/libs/Scripts/sync-service
$ npm install
npm i -g hyperinstall
git clone git@github.com:decosoftware/deco-ide
./deco-ide/tools/install-dependencies
```

### Development
Expand Down
2 changes: 1 addition & 1 deletion desktop/gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ gulp.task('dist', ['modify-plist'], (callback) => {
})

gulp.task('rebuild-native-modules', () => {
const modules = ['git-utils', 'nodobjc', 'ffi', 'ref', 'ref-struct']
const modules = ['git-utils', 'nodobjc', 'ffi', 'ref', 'ref-struct', 'dtrace-provider']

modules.forEach(module => {
console.log('Building native module', module, 'for version', NODE_MODULES_VERSION)
Expand Down
39 changes: 27 additions & 12 deletions desktop/libs/Scripts/deco-tool/configure.deco.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ const checkEnvironmentOK = () => {
return true
}

const checkIsExponent = () => {
try {
fs.statSync(path.join(process.cwd(), 'exp.json'));
return true;
} catch(e) {
return false;
}
}

const checkGenymotionOK = () => {
if (!process.env.GENYMOTION_APP) {
const defaultGenymotionPath = `/Applications/Genymotion.app`
Expand Down Expand Up @@ -133,18 +142,20 @@ DECO.on('list-ios-sim', function(args) {
})
}

const targetAppPath = path.join(process.cwd(), path.dirname(PROJECT_SETTING.iosTarget))
try {
fs.statSync(targetAppPath)
} catch (e) {
if (e.code == 'ENOENT') {
return Promise.reject({
payload: [
'iOS simulator cannot launch without building your project.',
'Please hit cmd + B or Tools > Build Native Modules to build your project.',
'If you have a custom build outside of Deco, go to Deco > Project Settings and change the "iosTarget" to your .app file location'
]
})
if (!checkIsExponent()) {
const targetAppPath = path.join(process.cwd(), path.dirname(PROJECT_SETTING.iosTarget))
try {
fs.statSync(targetAppPath)
} catch (e) {
if (e.code == 'ENOENT') {
return Promise.reject({
payload: [
'iOS simulator cannot launch without building your project.',
'Please hit cmd + B or Tools > Build Native Modules to build your project.',
'If you have a custom build outside of Deco, go to Deco > Project Settings and change the "iosTarget" to your .app file location'
]
})
}
}
}

Expand Down Expand Up @@ -436,3 +447,7 @@ DECO.on('init-template', function (args) {
.pipe(fs.createWriteStream(path.join(process.cwd(), 'configure.deco.js')))
return Promise.resolve()
})

if (checkIsExponent()) {
require('./exponent.configure.deco.js')
}
92 changes: 92 additions & 0 deletions desktop/libs/Scripts/deco-tool/exponent.configure.deco.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright (C) 2015 Deco Software Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
'use strict'

const projectRoot = process.cwd()

const child_process = require('child_process')
const path = require('path')
const DECO = require('deco-tool')

DECO.on('run-packager', function(args) {
return new Promise((resolve, reject) => {
let exponentPackagerPath = path.resolve(
projectRoot,
'node_modules/@exponent/minimal-packager/cli.js'
)

var child = child_process.spawn(exponentPackagerPath, [], {
env: process.env,
cwd: process.cwd(),
stdio: 'inherit',
})

resolve({ child })
})
})

DECO.on('build-ios', function (args) {
// noop
})

DECO.on('build-android', function (args) {
// noop
})

DECO.on('sim-android', function(args) {
return openAppOnAndroid()
})

DECO.on('reload-android-app', function(args) {
return openAppOnAndroid()
})

DECO.on('sim-ios', function(args) {
return openAppOnIOS()
})

DECO.on('reload-ios-app', function(args) {
return openAppOnIOS()
})

function openAppOnAndroid() {
return new Promise((resolve, reject) => {
const xdl = require(`${projectRoot}/node_modules/xdl`)

xdl.Android.openProjectAsync(projectRoot).then(() => {
resolve('Opened project on Android')
}).catch(e => {
reject(`Error opening project on Android: ${e.message}`)
})
})
}

function openAppOnIOS() {
return new Promise((resolve, reject) => {
const xdl = require(`${projectRoot}/node_modules/xdl`)

xdl.Project.getUrlAsync(projectRoot).then(url => {
xdl.Simulator.openUrlInSimulatorSafeAsync(url).then(() => {
resolve('Opened project in iOS simulator')
}).catch(e => {
reject(`Error opening project in iOS simulator: ${e.message}`)
})
}).catch(e => {
reject(`Error opening project in iOS simulator: ${e.message}`)
})
})
}
2 changes: 1 addition & 1 deletion desktop/libs/Scripts/deco-tool/template.configure.deco.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const packagerPort = Deco.setting.packagerPort

/**
*
* HOW TO USE THIS FILE (https://github.com/decosoftware/deco-ide/blob/master/desktop/CONFIGURE.MD)
* HOW TO USE THIS FILE (https://github.com/decosoftware/deco-ide/blob/master/desktop/CONFIGURE.md)
*
* Runs a registered function in an isolated NodeJS environment when that function's corresponding
* command is triggered from within the Deco application or when run from shell as a 'deco-tool' command
Expand Down
6 changes: 3 additions & 3 deletions desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"image-diff": "^1.6.3",
"jest": "^15.1.1",
"mocha": "^3.0.2",
"node-inspector": "^0.12.8",
"node-pre-gyp": "^0.6.29",
"plist": "^1.2.0",
"rimraf": "^2.5.4",
Expand All @@ -43,7 +42,7 @@
"babel-core": "^6.4.0",
"babel-runtime": "^6.11.6",
"deco-simulacra": "1.0.0",
"electron-prebuilt": "1.4.3",
"electron-prebuilt": "^1.4.3",
"file-tree-server": "0.0.8",
"file-tree-server-git": "0.0.8",
"file-tree-server-transport-electron": "0.0.1",
Expand All @@ -62,6 +61,7 @@
"once": "^1.3.3",
"raven": "^0.10.0",
"sane": "^1.3.3",
"winston": "^2.1.1"
"winston": "^2.1.1",
"xdl": "^0.25.0"
}
}
82 changes: 1 addition & 81 deletions desktop/src/handlers/moduleHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,20 @@
*/

import _ from 'lodash'
import fs from 'fs'
import path from 'path'
import jsonfile from 'jsonfile'
import dir from 'node-dir'

import Logger from '../log/logger'
import npm from '../process/npmController'
import bridge from '../bridge'
import { onSuccess, onError } from '../actions/genericActions'
import { startProgressBar, updateProgressBar, endProgressBar } from '../actions/uiActions'
import { foundRegistries } from '../actions/moduleActions'
import ModuleConstants from 'shared/constants/ipc/ModuleConstants'

class ModuleHandler {

register() {
bridge.on(ModuleConstants.IMPORT_MODULE, this.importModule.bind(this))
bridge.on(ModuleConstants.SCAN_PROJECT_FOR_REGISTRIES, this.scanPathForRegistries.bind(this))
}

readPackageJSON(projectPath) {
const packagePath = path.join(projectPath, 'package.json')
return new Promise((resolve, reject) => {
try {
jsonfile.readFile(packagePath, (err, obj) => {
if (err && err.code !== 'ENOENT') {
Logger.info('Failed to read package.json')
Logger.error(err)
reject(err)
} else {
resolve(obj)
}
})
} catch (e) {
Logger.error(e)
reject(e)
}
})
}

/**
* Return a map of {filepath => package.json contents}
* @param {String} dirname Directory to scan
Expand Down Expand Up @@ -154,60 +128,6 @@ class ModuleHandler {
respond(foundRegistries(registryMap))
})
}

importModule(options, respond) {

options.version = options.version || 'latest'

const {name, version, path: installPath } = options

this.readPackageJSON(options.path).then((packageJSON = {}) => {
const {dependencies} = packageJSON

// If the dependency exists, and the version is compatible
if (dependencies && dependencies[name] &&
(version === '*' || version === dependencies[name])) {
Logger.info(`npm: dependency ${name}@${version} already installed`)
respond(onSuccess(ModuleConstants.IMPORT_MODULE))
} else {
const progressCallback = _.throttle((percent) => {
bridge.send(updateProgressBar(name, percent * 100))
}, 250)

bridge.send(startProgressBar(name, 0))

try {
const command = [
'install', '-S', `${name}@${version}`,
...options.registry && ['--registry', options.registry]
]

Logger.info(`npm ${command.join(' ')}`)

npm.run(command, {cwd: installPath}, (err) => {

// Ensure a trailing throttled call doesn't fire
progressCallback.cancel()

bridge.send(endProgressBar(name, 100))

if (err) {
Logger.info(`npm: dependency ${name}@${version} failed to install`)
respond(onError(ModuleConstants.IMPORT_MODULE))
} else {
Logger.info(`npm: dependency ${name}@${version} installed successfully`)
respond(onSuccess(ModuleConstants.IMPORT_MODULE))
}
}, progressCallback)
} catch(e) {
Logger.error(e)
respond(onError(ModuleConstants.IMPORT_MODULE))
}
}
})

}

}

export default new ModuleHandler()
module.exports = new ModuleHandler()
1 change: 0 additions & 1 deletion desktop/src/handlers/windowHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class WindowHandler {
bridge.on(SAVE_AS_DIALOG, this.saveAsDialog.bind(this))
bridge.on(RESIZE, this.resizeWindow.bind(this))
bridge.on(OPEN_PATH_CHOOSER_DIALOG, this.openPathChooserDialog.bind(this))
bridge.on(OPEN_PATH_CHOOSER_DIALOG, this.openPathChooserDialog.bind(this))
bridge.on(CONFIRM_DELETE_DIALOG, this.showDeleteDialog.bind(this))
}

Expand Down
17 changes: 6 additions & 11 deletions desktop/src/menu/menuHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,13 @@ const Menu = require('electron').Menu
const TemplateBuilder = require('./templateBuilder.js')

class MenuHandler {
instantiateTemplate() {
var template = new TemplateBuilder(process.platform).makeTemplate()
this._template = template
this._menu = Menu.buildFromTemplate(this._template)
Menu.setApplicationMenu(this._menu)
}
instantiateTemplate(options = {}) {
const builder = new TemplateBuilder({platform: process.platform, ...options})
const template = builder.makeTemplate()
const menu = Menu.buildFromTemplate(template)

get menu() {
return this._menu
Menu.setApplicationMenu(menu)
}
}

const handler = new MenuHandler()

module.exports = handler
module.exports = new MenuHandler()
Loading