Skip to content

Commit

Permalink
do a better a job at finding the ios project name
Browse files Browse the repository at this point in the history
  • Loading branch information
gdowens committed Jul 1, 2016
1 parent 74f4410 commit 360b327
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
15 changes: 14 additions & 1 deletion desktop/deco_unpack_lib/Scripts/deco-tool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const fs = require('fs')
const path = require('path')
const clinput = require('minimist')(process.argv.slice(2))
const stripComments = require('./util/stripComments')
const findXcodeProject = require('./util/findXcodeProject')

let RUNNING_DEFAULT = false

Expand Down Expand Up @@ -198,6 +199,18 @@ if (clinput.r) {
process.chdir(clinput.r)
}

const guessProjectName = (rootPath) => {
const defaultPath = path.join(rootPath, 'ios')
try {
fs.statSync(defaultPath)
const files = fs.readdirSync(defaultPath)
const projectFile = findXcodeProject(files).name
return path.basename(projectFile, path.extname(projectFile))
} catch (e) {
return path.basename(rootPath)
}
}

var CONFIG_FILE_NAME = 'configure.deco.js'
var METADATA_DIR = '.deco'
var SETTINGS_FILE_NAME = '.settings'
Expand All @@ -212,7 +225,7 @@ try {
} catch (e) {
try {
const getDefaults = require(path.join(moduleWorkingDir, 'default.settings.js'))
const projectName = path.basename(process.cwd())
const projectName = guessProjectName(process.cwd())
PROJECT_SETTING = getDefaults(projectName)
} catch (e) {

Expand Down
54 changes: 54 additions & 0 deletions desktop/deco_unpack_lib/Scripts/deco-tool/util/findXcodeProject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* 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/>.
*
*/

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict'

const path = require('path')

function findXcodeProject(files) {
const sortedFiles = files.sort()
for (let i = sortedFiles.length - 1; i >= 0; i--) {
const fileName = files[i]
const ext = path.extname(fileName)

if (ext === '.xcworkspace') {
return {
name: fileName,
isWorkspace: true,
}
}
if (ext === '.xcodeproj') {
return {
name: fileName,
isWorkspace: false,
}
}
}

return null
}

module.exports = findXcodeProject
2 changes: 1 addition & 1 deletion desktop/src/handlers/processHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class ProcessHandler {
onResumeSimulator(payload, respond) {
// Only relaunches simulator if the Simulator.app is running and the controller's state has been preserved
if (SimulatorController.isSimulatorRunning() && SimulatorController.lastUsedArgs() != null) {
try {
try {
SimulatorController.runSimulator()
respond(onSuccess(RESUME_SIMULATOR))
} catch (e) {
Expand Down
17 changes: 16 additions & 1 deletion desktop/src/handlers/projectHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import {
import SimulatorController from '../process/simulatorController'
import PackagerController from '../process/packagerController'

import findXcodeProject from '../process/utils/findXcodeProject'

import Logger from '../log/logger'

let unsavedMap = {}
Expand Down Expand Up @@ -191,16 +193,29 @@ class ProjectHandler {
}
}

_guessProjectName(rootPath) {
const defaultPath = path.join(rootPath, 'ios')
try {
fs.statSync(defaultPath)
const files = fs.readdirSync(defaultPath)
const projectFile = findXcodeProject(files).name
return path.basename(projectFile, path.extname(projectFile))
} catch (e) {
return path.basename(rootPath)
}
}

createProjectSettingsTemplate(rootPath) {
return new Promise((resolve, reject) => {
const metadataPath = path.join(rootPath, '.deco')
const settingsFilePath = path.join(metadataPath, '.settings')
const assumedProjectName = path.basename(rootPath)
const assumedProjectName = this._guessProjectName(rootPath)
try {
fs.statSync(settingsFilePath)
resolve(settingsFilePath)
} catch (e) {
if (e && e.code == 'ENOENT') {

mkdirp(metadataPath, () => {
try {
fs.writeFileSync(settingsFilePath, PROJECT_SETTINGS_TEMPLATE(assumedProjectName), {
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/process/utils/findXcodeProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function findXcodeProject(files) {

if (ext === '.xcworkspace') {
return {
name: fileName,
name: fileName,
isWorkspace: true,
}
}
Expand Down

0 comments on commit 360b327

Please sign in to comment.