-
-
Notifications
You must be signed in to change notification settings - Fork 197
feat: make app_resources's path configurable #3329
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
Changes from all commits
9e60d2b
ce3c173
7b93bb7
9888581
b557596
b9890bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,9 @@ export class ProjectData implements IProjectData { | |
public projectId: string; | ||
public projectName: string; | ||
public appDirectoryPath: string; | ||
public appResourcesDirectoryPath: string; | ||
get appResourcesDirectoryPath(): string { | ||
return this.getAppResourcesDirectoryPath(); | ||
} | ||
public dependencies: any; | ||
public devDependencies: IStringDictionary; | ||
public projectType: string; | ||
|
@@ -69,7 +71,6 @@ export class ProjectData implements IProjectData { | |
this.platformsDir = path.join(projectDir, constants.PLATFORMS_DIR_NAME); | ||
this.projectFilePath = projectFilePath; | ||
this.appDirectoryPath = path.join(projectDir, constants.APP_FOLDER_NAME); | ||
this.appResourcesDirectoryPath = path.join(projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME); | ||
this.projectId = data.id; | ||
this.dependencies = fileContent.dependencies; | ||
this.devDependencies = fileContent.devDependencies; | ||
|
@@ -87,6 +88,34 @@ export class ProjectData implements IProjectData { | |
this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", projectDir || this.$options.path || currentDir); | ||
} | ||
|
||
public getAppResourcesDirectoryPath(projectDir?: string): string { | ||
if (!projectDir) { | ||
projectDir = this.projectDir; | ||
} | ||
|
||
if (!projectDir) { | ||
return null; | ||
} | ||
|
||
const configNSFilePath = path.join(projectDir, constants.CONFIG_NS_FILE_NAME); | ||
let absoluteAppResourcesDirPath: string; | ||
|
||
if (this.$fs.exists(configNSFilePath)) { | ||
const configNS = this.$fs.readJson(configNSFilePath); | ||
|
||
if (configNS && configNS[constants.CONFIG_NS_APP_RESOURCES_ENTRY]) { | ||
const appResourcesDirPath = configNS[constants.CONFIG_NS_APP_RESOURCES_ENTRY]; | ||
|
||
absoluteAppResourcesDirPath = path.resolve(projectDir, appResourcesDirPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it worth checking if this path exists? |
||
|
||
return absoluteAppResourcesDirPath; | ||
} | ||
} | ||
|
||
// if no nsconfig is present default to app/App_Resources | ||
return path.join(projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME); | ||
} | ||
|
||
private getProjectType(): string { | ||
let detectedProjectType = _.find(ProjectData.PROJECT_TYPES, (projectType) => projectType.isDefaultProjectType).type; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ export class PreparePlatformJSService extends PreparePlatformService implements | |
public async preparePlatform(config: IPreparePlatformJSInfo): Promise<void> { | ||
if (!config.changesInfo || config.changesInfo.appFilesChanged || config.changesInfo.changesRequirePrepare) { | ||
await this.copyAppFiles(config); | ||
this.copyAppResourcesFiles(config); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is related to https://github.com/NativeScript/nativescript-cli/pull/3329/files#diff-d7315453ac31262b45d0c2530d69cd94R47 change. Can you describe a little bit more what is the idea |
||
} | ||
|
||
if (config.changesInfo && !config.changesInfo.changesRequirePrepare) { | ||
|
@@ -101,6 +102,13 @@ export class PreparePlatformJSService extends PreparePlatformService implements | |
this.$errors.failWithoutHelp(`Processing node_modules failed. ${error}`); | ||
} | ||
} | ||
|
||
private copyAppResourcesFiles(config: IPreparePlatformJSInfo) { | ||
const appDestinationDirectoryPath = path.join(config.platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); | ||
const appResourcesSourcePath = config.projectData.appResourcesDirectoryPath; | ||
|
||
shell.cp("-Rf", appResourcesSourcePath, appDestinationDirectoryPath); | ||
} | ||
} | ||
|
||
$injector.register("preparePlatformJSService", PreparePlatformJSService); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,11 +29,11 @@ import { Utils } from "../lib/common/utils"; | |
import { CocoaPodsService } from "../lib/services/cocoapods-service"; | ||
import { NpmInstallationManager } from "../lib/npm-installation-manager"; | ||
import { NodePackageManager } from "../lib/node-package-manager"; | ||
import * as constants from "../lib/constants"; | ||
|
||
import { assert } from "chai"; | ||
import { IOSProvisionService } from "../lib/services/ios-provision-service"; | ||
import { SettingsService } from "../lib/common/test/unit-tests/stubs"; | ||
import { ProjectDataStub } from "./stubs"; | ||
import temp = require("temp"); | ||
|
||
temp.track(); | ||
|
@@ -65,12 +65,13 @@ function createTestInjector(projectPath: string, projectName: string): IInjector | |
testInjector.register("iOSEntitlementsService", IOSEntitlementsService); | ||
testInjector.register("logger", LoggerLib.Logger); | ||
testInjector.register("options", OptionsLib.Options); | ||
testInjector.register("projectData", { | ||
const projectData = Object.assign({}, ProjectDataStub, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe you can just mock the required methods, but this is not a merge stopper |
||
platformsDir: path.join(projectPath, "platforms"), | ||
projectName: projectName, | ||
projectPath: projectPath, | ||
projectFilePath: path.join(projectPath, "package.json") | ||
}); | ||
testInjector.register("projectData", projectData); | ||
testInjector.register("projectHelper", {}); | ||
testInjector.register("xcodeSelectService", {}); | ||
testInjector.register("staticConfig", ConfigLib.StaticConfig); | ||
|
@@ -793,11 +794,11 @@ describe("Merge Project XCConfig files", () => { | |
iOSProjectService = testInjector.resolve("iOSProjectService"); | ||
projectData = testInjector.resolve("projectData"); | ||
projectData.projectDir = projectPath; | ||
projectData.appResourcesDirectoryPath = path.join(projectData.projectDir, "app", "App_Resources"); | ||
|
||
iOSEntitlementsService = testInjector.resolve("iOSEntitlementsService"); | ||
|
||
appResourcesXcconfigPath = path.join(projectData.projectDir, constants.APP_FOLDER_NAME, | ||
constants.APP_RESOURCES_FOLDER_NAME, "iOS", "build.xcconfig"); | ||
appResourcesXcconfigPath = path.join(projectData.appResourcesDirectoryPath, "iOS", "build.xcconfig"); | ||
appResourceXCConfigContent = `CODE_SIGN_IDENTITY = iPhone Distribution | ||
// To build for device with XCode 8 you need to specify your development team. More info: https://developer.apple.com/library/prerelease/content/releasenotes/DeveloperTools/RN-Xcode/Introduction.html | ||
// DEVELOPMENT_TEAM = YOUR_TEAM_ID; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
initializeProjectData
has not been called, thethis.projectDir
will also be undefined and the path.join below will fail.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, I am unsure how to tackle this. The need for the additional
projectDir
parameter arose when using the getter during project creation. What would you recommend I check here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just return null here. The caller should decide what to do.