From 360b3271d2f0031a12bc1ba2eba292690073bed3 Mon Sep 17 00:00:00 2001 From: Gavin Owens Date: Fri, 1 Jul 2016 13:34:35 -0700 Subject: [PATCH] do a better a job at finding the ios project name --- .../Scripts/deco-tool/index.js | 15 +++++- .../deco-tool/util/findXcodeProject.js | 54 +++++++++++++++++++ desktop/src/handlers/processHandler.js | 2 +- desktop/src/handlers/projectHandler.js | 17 +++++- desktop/src/process/utils/findXcodeProject.js | 2 +- 5 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 desktop/deco_unpack_lib/Scripts/deco-tool/util/findXcodeProject.js diff --git a/desktop/deco_unpack_lib/Scripts/deco-tool/index.js b/desktop/deco_unpack_lib/Scripts/deco-tool/index.js index 687d56d..a2bb858 100755 --- a/desktop/deco_unpack_lib/Scripts/deco-tool/index.js +++ b/desktop/deco_unpack_lib/Scripts/deco-tool/index.js @@ -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 @@ -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' @@ -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) { diff --git a/desktop/deco_unpack_lib/Scripts/deco-tool/util/findXcodeProject.js b/desktop/deco_unpack_lib/Scripts/deco-tool/util/findXcodeProject.js new file mode 100644 index 0000000..e112c54 --- /dev/null +++ b/desktop/deco_unpack_lib/Scripts/deco-tool/util/findXcodeProject.js @@ -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 . + * + */ + +/** + * 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 diff --git a/desktop/src/handlers/processHandler.js b/desktop/src/handlers/processHandler.js index dc23bb2..4c26ea9 100644 --- a/desktop/src/handlers/processHandler.js +++ b/desktop/src/handlers/processHandler.js @@ -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) { diff --git a/desktop/src/handlers/projectHandler.js b/desktop/src/handlers/projectHandler.js index 8c39160..6b1527b 100644 --- a/desktop/src/handlers/projectHandler.js +++ b/desktop/src/handlers/projectHandler.js @@ -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 = {} @@ -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), { diff --git a/desktop/src/process/utils/findXcodeProject.js b/desktop/src/process/utils/findXcodeProject.js index aa759ce..e112c54 100644 --- a/desktop/src/process/utils/findXcodeProject.js +++ b/desktop/src/process/utils/findXcodeProject.js @@ -36,7 +36,7 @@ function findXcodeProject(files) { if (ext === '.xcworkspace') { return { - name: fileName, + name: fileName, isWorkspace: true, } }