Skip to content

Commit 360b327

Browse files
committed
do a better a job at finding the ios project name
1 parent 74f4410 commit 360b327

File tree

5 files changed

+86
-4
lines changed

5 files changed

+86
-4
lines changed

desktop/deco_unpack_lib/Scripts/deco-tool/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const fs = require('fs')
2121
const path = require('path')
2222
const clinput = require('minimist')(process.argv.slice(2))
2323
const stripComments = require('./util/stripComments')
24+
const findXcodeProject = require('./util/findXcodeProject')
2425

2526
let RUNNING_DEFAULT = false
2627

@@ -198,6 +199,18 @@ if (clinput.r) {
198199
process.chdir(clinput.r)
199200
}
200201

202+
const guessProjectName = (rootPath) => {
203+
const defaultPath = path.join(rootPath, 'ios')
204+
try {
205+
fs.statSync(defaultPath)
206+
const files = fs.readdirSync(defaultPath)
207+
const projectFile = findXcodeProject(files).name
208+
return path.basename(projectFile, path.extname(projectFile))
209+
} catch (e) {
210+
return path.basename(rootPath)
211+
}
212+
}
213+
201214
var CONFIG_FILE_NAME = 'configure.deco.js'
202215
var METADATA_DIR = '.deco'
203216
var SETTINGS_FILE_NAME = '.settings'
@@ -212,7 +225,7 @@ try {
212225
} catch (e) {
213226
try {
214227
const getDefaults = require(path.join(moduleWorkingDir, 'default.settings.js'))
215-
const projectName = path.basename(process.cwd())
228+
const projectName = guessProjectName(process.cwd())
216229
PROJECT_SETTING = getDefaults(projectName)
217230
} catch (e) {
218231

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright (C) 2015 Deco Software Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License, version 3,
6+
* as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU Affero General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU Affero General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*
16+
*/
17+
18+
/**
19+
* Copyright (c) 2015-present, Facebook, Inc.
20+
* All rights reserved.
21+
*
22+
* This source code is licensed under the BSD-style license found in the
23+
* LICENSE file in the root directory of this source tree. An additional grant
24+
* of patent rights can be found in the PATENTS file in the same directory.
25+
*
26+
*/
27+
'use strict'
28+
29+
const path = require('path')
30+
31+
function findXcodeProject(files) {
32+
const sortedFiles = files.sort()
33+
for (let i = sortedFiles.length - 1; i >= 0; i--) {
34+
const fileName = files[i]
35+
const ext = path.extname(fileName)
36+
37+
if (ext === '.xcworkspace') {
38+
return {
39+
name: fileName,
40+
isWorkspace: true,
41+
}
42+
}
43+
if (ext === '.xcodeproj') {
44+
return {
45+
name: fileName,
46+
isWorkspace: false,
47+
}
48+
}
49+
}
50+
51+
return null
52+
}
53+
54+
module.exports = findXcodeProject

desktop/src/handlers/processHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class ProcessHandler {
199199
onResumeSimulator(payload, respond) {
200200
// Only relaunches simulator if the Simulator.app is running and the controller's state has been preserved
201201
if (SimulatorController.isSimulatorRunning() && SimulatorController.lastUsedArgs() != null) {
202-
try {
202+
try {
203203
SimulatorController.runSimulator()
204204
respond(onSuccess(RESUME_SIMULATOR))
205205
} catch (e) {

desktop/src/handlers/projectHandler.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import {
5050
import SimulatorController from '../process/simulatorController'
5151
import PackagerController from '../process/packagerController'
5252

53+
import findXcodeProject from '../process/utils/findXcodeProject'
54+
5355
import Logger from '../log/logger'
5456

5557
let unsavedMap = {}
@@ -191,16 +193,29 @@ class ProjectHandler {
191193
}
192194
}
193195

196+
_guessProjectName(rootPath) {
197+
const defaultPath = path.join(rootPath, 'ios')
198+
try {
199+
fs.statSync(defaultPath)
200+
const files = fs.readdirSync(defaultPath)
201+
const projectFile = findXcodeProject(files).name
202+
return path.basename(projectFile, path.extname(projectFile))
203+
} catch (e) {
204+
return path.basename(rootPath)
205+
}
206+
}
207+
194208
createProjectSettingsTemplate(rootPath) {
195209
return new Promise((resolve, reject) => {
196210
const metadataPath = path.join(rootPath, '.deco')
197211
const settingsFilePath = path.join(metadataPath, '.settings')
198-
const assumedProjectName = path.basename(rootPath)
212+
const assumedProjectName = this._guessProjectName(rootPath)
199213
try {
200214
fs.statSync(settingsFilePath)
201215
resolve(settingsFilePath)
202216
} catch (e) {
203217
if (e && e.code == 'ENOENT') {
218+
204219
mkdirp(metadataPath, () => {
205220
try {
206221
fs.writeFileSync(settingsFilePath, PROJECT_SETTINGS_TEMPLATE(assumedProjectName), {

desktop/src/process/utils/findXcodeProject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function findXcodeProject(files) {
3636

3737
if (ext === '.xcworkspace') {
3838
return {
39-
name: fileName,
39+
name: fileName,
4040
isWorkspace: true,
4141
}
4242
}

0 commit comments

Comments
 (0)