From 2f8a11ce6302976017e04c548a2bcae36859051a Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 10 Apr 2019 11:01:00 +0300 Subject: [PATCH] chore: remove the code related to js prepare as webpack overrides prepareJS method with own logic --- lib/definitions/platform.d.ts | 1 - lib/definitions/plugins.d.ts | 2 - lib/services/plugins-service.ts | 35 - lib/services/prepare-platform-js-service.ts | 53 +- .../node-modules/node-modules-builder.ts | 40 +- .../node-modules/node-modules-dest-copy.ts | 173 +-- test/platform-service.ts | 1107 ++++++++--------- test/plugin-prepare.ts | 59 - test/plugins-service.ts | 2 +- 9 files changed, 535 insertions(+), 937 deletions(-) delete mode 100644 test/plugin-prepare.ts diff --git a/lib/definitions/platform.d.ts b/lib/definitions/platform.d.ts index 6a02997efc..3462e437e1 100644 --- a/lib/definitions/platform.d.ts +++ b/lib/definitions/platform.d.ts @@ -283,7 +283,6 @@ interface INodeModulesBuilderData { interface INodeModulesBuilder { prepareNodeModules(opts: INodeModulesBuilderData): Promise; - prepareJSNodeModules(opts: INodeModulesBuilderData): Promise; } interface INodeModulesDependenciesBuilder { diff --git a/lib/definitions/plugins.d.ts b/lib/definitions/plugins.d.ts index 2f0d775666..8fce2600ba 100644 --- a/lib/definitions/plugins.d.ts +++ b/lib/definitions/plugins.d.ts @@ -1,10 +1,8 @@ interface IPluginsService { add(plugin: string, projectData: IProjectData): Promise; // adds plugin by name, github url, local path and et. remove(pluginName: string, projectData: IProjectData): Promise; // removes plugin only by name - prepare(pluginData: IDependencyData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise; getAllInstalledPlugins(projectData: IProjectData): Promise; ensureAllDependenciesAreInstalled(projectData: IProjectData): Promise; - preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): void /** * Returns all dependencies and devDependencies from pacakge.json file. diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index f18a9e8e7f..143da2d6d8 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -18,9 +18,6 @@ export class PluginsService implements IPluginsService { private get $projectDataService(): IProjectDataService { return this.$injector.resolve("projectDataService"); } - private get $projectFilesManager(): IProjectFilesManager { - return this.$injector.resolve("projectFilesManager"); - } private get npmInstallOptions(): INodePackageManagerInstallOptions { return _.merge({ @@ -108,38 +105,6 @@ export class PluginsService implements IPluginsService { return await platformData.platformProjectService.validatePlugins(projectData); } - public async prepare(dependencyData: IDependencyData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise { - platform = platform.toLowerCase(); - const platformData = this.$platformsData.getPlatformData(platform, projectData); - const pluginData = this.convertToPluginData(dependencyData, projectData.projectDir); - - const appFolderExists = this.$fs.exists(path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME)); - if (appFolderExists) { - this.preparePluginScripts(pluginData, platform, projectData, projectFilesConfig); - await this.preparePluginNativeCode(pluginData, platform, projectData); - - // Show message - this.$logger.out(`Successfully prepared plugin ${pluginData.name} for ${platform}.`); - } - } - - public preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): void { - const platformData = this.$platformsData.getPlatformData(platform, projectData); - const pluginScriptsDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, "tns_modules"); - const scriptsDestinationExists = this.$fs.exists(pluginScriptsDestinationPath); - if (!scriptsDestinationExists) { - //tns_modules/ doesn't exist. Assuming we're running a bundled prepare. - return; - } - - if (!this.isPluginDataValidForPlatform(pluginData, platform, projectData)) { - return; - } - - //prepare platform speciffic files, .map and .ts files - this.$projectFilesManager.processPlatformSpecificFiles(pluginScriptsDestinationPath, platform, projectFilesConfig); - } - public async preparePluginNativeCode(pluginData: IPluginData, platform: string, projectData: IProjectData): Promise { const platformData = this.$platformsData.getPlatformData(platform, projectData); pluginData.pluginPlatformsFolderPath = (_platform: string) => path.join(pluginData.fullPath, "platforms", _platform.toLowerCase()); diff --git a/lib/services/prepare-platform-js-service.ts b/lib/services/prepare-platform-js-service.ts index 6b74a4e262..f4675cbf93 100644 --- a/lib/services/prepare-platform-js-service.ts +++ b/lib/services/prepare-platform-js-service.ts @@ -1,6 +1,5 @@ import * as constants from "../constants"; import * as path from "path"; -import * as shell from "shelljs"; import * as temp from "temp"; import { hook } from "../common/helpers"; import { PreparePlatformService } from "./prepare-platform-service"; @@ -16,7 +15,6 @@ export class PreparePlatformJSService extends PreparePlatformService implements private $errors: IErrors, private $logger: ILogger, private $projectDataService: IProjectDataService, - private $nodeModulesBuilder: INodeModulesBuilder, private $packageManager: INodePackageManager) { super($fs, $hooksService, $xmlValidator); } @@ -36,23 +34,7 @@ export class PreparePlatformJSService extends PreparePlatformService implements @performanceLog() @hook('prepareJSApp') public async preparePlatform(config: IPreparePlatformJSInfo): Promise { - if (!config.changesInfo || config.changesInfo.appFilesChanged || config.changesInfo.changesRequirePrepare) { - await this.copyAppFiles(config); - this.copyAppResourcesFiles(config); - } - - if (config.changesInfo && !config.changesInfo.changesRequirePrepare) { - // remove the App_Resources folder from the app/assets as here we're applying other files changes. - const appDestinationDirectoryPath = path.join(config.platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); - const appResourcesDirectoryPath = path.join(appDestinationDirectoryPath, path.basename(config.projectData.appResourcesDirectoryPath)); - if (this.$fs.exists(appResourcesDirectoryPath)) { - this.$fs.deleteDirectory(appResourcesDirectoryPath); - } - } - - if (!config.changesInfo || config.changesInfo.modulesChanged) { - await this.copyTnsModules(config.platform, config.platformData, config.projectData, config.appFilesUpdaterOptions, config.projectFilesConfig); - } + // intentionally left blank, keep the support for before-prepareJSApp and after-prepareJSApp hooks } private async getPathToPlatformTemplate(selectedTemplate: string, frameworkPackageName: string, projectDir: string): Promise<{ selectedTemplate: string, pathToTemplate: string }> { @@ -82,39 +64,6 @@ export class PreparePlatformJSService extends PreparePlatformService implements return null; } - - private async copyTnsModules(platform: string, platformData: IPlatformData, projectData: IProjectData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectFilesConfig?: IProjectFilesConfig): Promise { - const appDestinationDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); - const lastModifiedTime = this.$fs.exists(appDestinationDirectoryPath) ? this.$fs.getFsStats(appDestinationDirectoryPath).mtime : null; - - try { - const absoluteOutputPath = path.join(appDestinationDirectoryPath, constants.TNS_MODULES_FOLDER_NAME); - // Process node_modules folder - await this.$nodeModulesBuilder.prepareJSNodeModules({ - nodeModulesData: { - absoluteOutputPath, - platform, - lastModifiedTime, - projectData, - appFilesUpdaterOptions, - projectFilesConfig - }, - release: appFilesUpdaterOptions.release, - copyNodeModules: true - }); - } catch (error) { - this.$logger.debug(error); - shell.rm("-rf", appDestinationDirectoryPath); - this.$errors.failWithoutHelp(`Processing node_modules failed. ${error}`); - } - } - - private copyAppResourcesFiles(config: IPreparePlatformJSInfo): void { - const appDestinationDirectoryPath = path.join(config.platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); - const appResourcesSourcePath = config.projectData.appResourcesDirectoryPath; - - shell.cp("-Rf", appResourcesSourcePath, path.join(appDestinationDirectoryPath, constants.APP_RESOURCES_FOLDER_NAME)); - } } $injector.register("preparePlatformJSService", PreparePlatformJSService); diff --git a/lib/tools/node-modules/node-modules-builder.ts b/lib/tools/node-modules/node-modules-builder.ts index 17f1c27317..c9af8361fd 100644 --- a/lib/tools/node-modules/node-modules-builder.ts +++ b/lib/tools/node-modules/node-modules-builder.ts @@ -1,47 +1,15 @@ -import { TnsModulesCopy, NpmPluginPrepare } from "./node-modules-dest-copy"; +import { NpmPluginPrepare } from "./node-modules-dest-copy"; export class NodeModulesBuilder implements INodeModulesBuilder { - constructor(private $fs: IFileSystem, + constructor( private $injector: IInjector, private $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder ) { } public async prepareNodeModules(opts: INodeModulesBuilderData): Promise { - const productionDependencies = this.intialPrepareNodeModulesIfRequired(opts); + const productionDependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(opts.nodeModulesData.projectData.projectDir); const npmPluginPrepare: NpmPluginPrepare = this.$injector.resolve(NpmPluginPrepare); - await npmPluginPrepare.preparePlugins(productionDependencies, opts.nodeModulesData.platform, opts.nodeModulesData.projectData, opts.nodeModulesData.projectFilesConfig); - } - - public async prepareJSNodeModules(opts: INodeModulesBuilderData): Promise { - const productionDependencies = this.intialPrepareNodeModulesIfRequired(opts); - const npmPluginPrepare: NpmPluginPrepare = this.$injector.resolve(NpmPluginPrepare); - await npmPluginPrepare.prepareJSPlugins(productionDependencies, opts.nodeModulesData.platform, opts.nodeModulesData.projectData, opts.nodeModulesData.projectFilesConfig); - } - - private intialPrepareNodeModulesIfRequired(opts: INodeModulesBuilderData): IDependencyData[] { - const { nodeModulesData } = opts; - const productionDependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(nodeModulesData.projectData.projectDir); - - if (opts.copyNodeModules && !nodeModulesData.appFilesUpdaterOptions.bundle) { - this.initialPrepareNodeModules(opts, productionDependencies); - } - - return productionDependencies; - } - - private initialPrepareNodeModules(opts: INodeModulesBuilderData, productionDependencies: IDependencyData[]): void { - const { nodeModulesData, release } = opts; - - if (!this.$fs.exists(nodeModulesData.absoluteOutputPath)) { - // Force copying if the destination doesn't exist. - nodeModulesData.lastModifiedTime = null; - } - - const tnsModulesCopy: TnsModulesCopy = this.$injector.resolve(TnsModulesCopy, { - outputRoot: nodeModulesData.absoluteOutputPath - }); - - tnsModulesCopy.copyModules({ dependencies: productionDependencies, release }); + await npmPluginPrepare.preparePlugins(productionDependencies, opts.nodeModulesData.platform, opts.nodeModulesData.projectData); } } diff --git a/lib/tools/node-modules/node-modules-dest-copy.ts b/lib/tools/node-modules/node-modules-dest-copy.ts index 55bcaaedc4..45af036501 100644 --- a/lib/tools/node-modules/node-modules-dest-copy.ts +++ b/lib/tools/node-modules/node-modules-dest-copy.ts @@ -1,155 +1,10 @@ -import * as path from "path"; -import * as shelljs from "shelljs"; -import * as constants from "../../constants"; -import * as minimatch from "minimatch"; - -export interface ILocalDependencyData extends IDependencyData { - directory: string; -} - -export class TnsModulesCopy { - constructor( - private outputRoot: string, - private $fs: IFileSystem, - private $pluginsService: IPluginsService - ) { - } - - public copyModules(opts: { dependencies: IDependencyData[], release: boolean }): void { - const filePatternsToDelete = opts.release ? "**/*.ts" : "**/*.d.ts"; - for (const entry in opts.dependencies) { - const dependency = opts.dependencies[entry]; - - this.copyDependencyDir(dependency, filePatternsToDelete); - } - } - - private copyDependencyDir(dependency: IDependencyData, filePatternsToDelete: string): void { - if (dependency.depth === 0) { - const targetPackageDir = path.join(this.outputRoot, dependency.name); - - shelljs.mkdir("-p", targetPackageDir); - - const isScoped = dependency.name.indexOf("@") === 0; - const destinationPath = isScoped ? path.join(this.outputRoot, dependency.name.substring(0, dependency.name.indexOf("/"))) : this.outputRoot; - shelljs.cp("-RfL", dependency.directory, destinationPath); - - // remove platform-specific files (processed separately by plugin services) - shelljs.rm("-rf", path.join(targetPackageDir, "platforms")); - - this.removeNonProductionDependencies(dependency, targetPackageDir); - this.removeDependenciesPlatformsDirs(targetPackageDir); - const allFiles = this.$fs.enumerateFilesInDirectorySync(targetPackageDir); - allFiles.filter(file => minimatch(file, filePatternsToDelete, { nocase: true })).map(file => this.$fs.deleteFile(file)); - } - } - - private removeDependenciesPlatformsDirs(dependencyDir: string): void { - const dependenciesFolder = path.join(dependencyDir, constants.NODE_MODULES_FOLDER_NAME); - - if (this.$fs.exists(dependenciesFolder)) { - const dependencies = this.getDependencies(dependenciesFolder); - - dependencies - .forEach(d => { - const pathToDependency = path.join(dependenciesFolder, d); - const pathToPackageJson = path.join(pathToDependency, constants.PACKAGE_JSON_FILE_NAME); - - if (this.$pluginsService.isNativeScriptPlugin(pathToPackageJson)) { - this.$fs.deleteDirectory(path.join(pathToDependency, constants.PLATFORMS_DIR_NAME)); - } - - this.removeDependenciesPlatformsDirs(pathToDependency); - }); - } - } - - private removeNonProductionDependencies(dependency: IDependencyData, targetPackageDir: string): void { - const packageJsonFilePath = path.join(dependency.directory, constants.PACKAGE_JSON_FILE_NAME); - if (!this.$fs.exists(packageJsonFilePath)) { - return; - } - - const packageJsonContent = this.$fs.readJson(packageJsonFilePath); - const productionDependencies = packageJsonContent.dependencies; - - const dependenciesFolder = path.join(targetPackageDir, constants.NODE_MODULES_FOLDER_NAME); - if (this.$fs.exists(dependenciesFolder)) { - const dependencies = this.getDependencies(dependenciesFolder); - - dependencies.filter(dir => !productionDependencies || !productionDependencies.hasOwnProperty(dir)) - .forEach(dir => shelljs.rm("-rf", path.join(dependenciesFolder, dir))); - } - } - - private getDependencies(dependenciesFolder: string): string[] { - const dependencies = _.flatten(this.$fs.readDirectory(dependenciesFolder) - .map(dir => { - if (_.startsWith(dir, "@")) { - const pathToDir = path.join(dependenciesFolder, dir); - const contents = this.$fs.readDirectory(pathToDir); - return _.map(contents, subDir => `${dir}/${subDir}`); - } - - return dir; - })); - - return dependencies; - } -} - export class NpmPluginPrepare { constructor( - private $fs: IFileSystem, private $pluginsService: IPluginsService, private $platformsData: IPlatformsData, - private $logger: ILogger - ) { - } - - protected async afterPrepare(dependencies: IDependencyData[], platform: string, projectData: IProjectData): Promise { - const prepareData: IDictionary = {}; - _.each(dependencies, d => { - prepareData[d.name] = true; - }); - this.$fs.createDirectory(this.preparedPlatformsDir(platform, projectData)); - this.$fs.writeJson(this.preparedPlatformsFile(platform, projectData), prepareData, " ", "utf8"); - } - - private preparedPlatformsDir(platform: string, projectData: IProjectData): string { - const platformRoot = this.$platformsData.getPlatformData(platform, projectData).projectRoot; - if (/android/i.test(platform)) { - return path.join(platformRoot, "build", "intermediates"); - } else if (/ios/i.test(platform)) { - return path.join(platformRoot, "build"); - } else { - throw new Error("Invalid platform: " + platform); - } - } - - private preparedPlatformsFile(platform: string, projectData: IProjectData): string { - return path.join(this.preparedPlatformsDir(platform, projectData), "prepared-platforms.json"); - } - - protected getPreviouslyPreparedDependencies(platform: string, projectData: IProjectData): IDictionary { - if (!this.$fs.exists(this.preparedPlatformsFile(platform, projectData))) { - return {}; - } - return this.$fs.readJson(this.preparedPlatformsFile(platform, projectData), "utf8"); - } + ) { } - private allPrepared(dependencies: IDependencyData[], platform: string, projectData: IProjectData): boolean { - let result = true; - const previouslyPrepared = this.getPreviouslyPreparedDependencies(platform, projectData); - _.each(dependencies, d => { - if (!previouslyPrepared[d.name]) { - result = false; - } - }); - return result; - } - - public async preparePlugins(dependencies: IDependencyData[], platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise { + public async preparePlugins(dependencies: IDependencyData[], platform: string, projectData: IProjectData): Promise { if (_.isEmpty(dependencies)) { return; } @@ -164,29 +19,5 @@ export class NpmPluginPrepare { await this.$pluginsService.preparePluginNativeCode(pluginData, platform, projectData); } } - - await this.afterPrepare(dependencies, platform, projectData); - } - - public async prepareJSPlugins(dependencies: IDependencyData[], platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise { - if (_.isEmpty(dependencies) || this.allPrepared(dependencies, platform, projectData)) { - return; - } - - for (const dependencyKey in dependencies) { - const dependency = dependencies[dependencyKey]; - const isPlugin = !!dependency.nativescript; - if (isPlugin) { - platform = platform.toLowerCase(); - const pluginData = this.$pluginsService.convertToPluginData(dependency, projectData.projectDir); - const platformData = this.$platformsData.getPlatformData(platform, projectData); - const appFolderExists = this.$fs.exists(path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME)); - if (appFolderExists) { - this.$pluginsService.preparePluginScripts(pluginData, platform, projectData, projectFilesConfig); - // Show message - this.$logger.out(`Successfully prepared plugin ${pluginData.name} for ${platform}.`); - } - } - } } } diff --git a/test/platform-service.ts b/test/platform-service.ts index 8503a71a06..47c578fb85 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -21,7 +21,6 @@ import * as ChildProcessLib from "../lib/common/child-process"; import ProjectChangesLib = require("../lib/services/project-changes-service"); import { Messages } from "../lib/common/messages/messages"; import { SettingsService } from "../lib/common/test/unit-tests/stubs"; -import { INFO_PLIST_FILE_NAME, MANIFEST_FILE_NAME } from "../lib/constants"; import { mkdir } from "shelljs"; import * as constants from "../lib/constants"; @@ -125,59 +124,6 @@ function createTestInjector() { return testInjector; } -class CreatedTestData { - files: string[]; - - resources: { - ios: string[], - android: string[] - }; - - testDirData: { - tempFolder: string, - appFolderPath: string, - app1FolderPath: string, - appDestFolderPath: string, - appResourcesFolderPath: string - }; - - constructor() { - this.files = []; - this.resources = { - ios: [], - android: [] - }; - - this.testDirData = { - tempFolder: "", - appFolderPath: "", - app1FolderPath: "", - appDestFolderPath: "", - appResourcesFolderPath: "" - }; - } -} - -class DestinationFolderVerifier { - static verify(data: any, fs: IFileSystem) { - _.forOwn(data, (folder, folderRoot) => { - _.each(folder.filesWithContent || [], (file) => { - const filePath = path.join(folderRoot, file.name); - assert.isTrue(fs.exists(filePath), `Expected file ${filePath} to be present.`); - assert.equal(fs.readFile(filePath).toString(), file.content, `File content for ${filePath} doesn't match.`); - }); - - _.each(folder.missingFiles || [], (file) => { - assert.isFalse(fs.exists(path.join(folderRoot, file)), `Expected file ${file} to be missing.`); - }); - - _.each(folder.presentFiles || [], (file) => { - assert.isTrue(fs.exists(path.join(folderRoot, file)), `Expected file ${file} to be present.`); - }); - }); - } -} - describe('Platform Service Tests', () => { let platformService: IPlatformService, testInjector: IInjector; const config: IPlatformOptions = { @@ -425,548 +371,549 @@ describe('Platform Service Tests', () => { }); }); - describe("prepare platform unit tests", () => { - let fs: IFileSystem; - - beforeEach(() => { - testInjector = createTestInjector(); - testInjector.register("fs", fsLib.FileSystem); - fs = testInjector.resolve("fs"); - testInjector.resolve("projectData").initializeProjectData(); - }); - - function prepareDirStructure() { - const tempFolder = temp.mkdirSync("prepare_platform"); - - const appFolderPath = path.join(tempFolder, "app"); - fs.createDirectory(appFolderPath); - - const nodeModulesPath = path.join(tempFolder, "node_modules"); - fs.createDirectory(nodeModulesPath); - - const testsFolderPath = path.join(appFolderPath, "tests"); - fs.createDirectory(testsFolderPath); - - const app1FolderPath = path.join(tempFolder, "app1"); - fs.createDirectory(app1FolderPath); - - const appDestFolderPath = path.join(tempFolder, "appDest"); - const appResourcesFolderPath = path.join(appDestFolderPath, "App_Resources"); - const appResourcesPath = path.join(appFolderPath, "App_Resources/Android"); - fs.createDirectory(appResourcesPath); - fs.writeFile(path.join(appResourcesPath, "test.txt"), "test"); - fs.writeJson(path.join(tempFolder, "package.json"), { - name: "testname", - nativescript: { - id: "org.nativescript.testname" - } - }); - - return { tempFolder, appFolderPath, app1FolderPath, appDestFolderPath, appResourcesFolderPath }; - } - - async function execPreparePlatform(platformToTest: string, testDirData: any, - release?: boolean) { - const platformsData = testInjector.resolve("platformsData"); - platformsData.platformsNames = ["ios", "android"]; - platformsData.getPlatformData = (platform: string) => { - return { - appDestinationDirectoryPath: testDirData.appDestFolderPath, - appResourcesDestinationDirectoryPath: testDirData.appResourcesFolderPath, - normalizedPlatformName: platformToTest, - configurationFileName: platformToTest === "ios" ? INFO_PLIST_FILE_NAME : MANIFEST_FILE_NAME, - projectRoot: testDirData.tempFolder, - platformProjectService: { - prepareProject: (): any => null, - validate: () => Promise.resolve(), - createProject: (projectRoot: string, frameworkDir: string) => Promise.resolve(), - interpolateData: (projectRoot: string) => Promise.resolve(), - afterCreateProject: (projectRoot: string): any => null, - getAppResourcesDestinationDirectoryPath: (pData: IProjectData, frameworkVersion?: string): string => { - if (platform.toLowerCase() === "ios") { - const dirPath = path.join(testDirData.appDestFolderPath, "Resources"); - fs.ensureDirectoryExists(dirPath); - return dirPath; - } else { - const dirPath = path.join(testDirData.appDestFolderPath, "src", "main", "res"); - fs.ensureDirectoryExists(dirPath); - return dirPath; - } - }, - processConfigurationFilesFromAppResources: () => Promise.resolve(), - handleNativeDependenciesChange: () => Promise.resolve(), - ensureConfigurationFileInAppResources: (): any => null, - interpolateConfigurationFile: (): void => undefined, - isPlatformPrepared: (projectRoot: string) => false, - prepareAppResources: (appResourcesDirectoryPath: string, pData: IProjectData): void => undefined, - checkForChanges: () => { /* */ } - } - }; - }; - - const projectData = testInjector.resolve("projectData"); - projectData.projectDir = testDirData.tempFolder; - projectData.projectName = "app"; - projectData.appDirectoryPath = testDirData.appFolderPath; - projectData.appResourcesDirectoryPath = path.join(testDirData.appFolderPath, "App_Resources"); - - platformService = testInjector.resolve("platformService"); - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: release, useHotModuleReload: false }; - await platformService.preparePlatform({ - platform: platformToTest, - appFilesUpdaterOptions, - platformTemplate: "", - projectData, - config: { provision: null, teamId: null, sdk: null, frameworkPath: null, ignoreScripts: false }, - env: {} - }); - } - - async function testPreparePlatform(platformToTest: string, release?: boolean): Promise { - const testDirData = prepareDirStructure(); - const created: CreatedTestData = new CreatedTestData(); - created.testDirData = testDirData; - - // Add platform specific files to app and app1 folders - const platformSpecificFiles = [ - "test1.ios.js", "test1-ios-js", "test2.android.js", "test2-android-js", - "main.js" - ]; - - const destinationDirectories = [testDirData.appFolderPath, testDirData.app1FolderPath]; - - _.each(destinationDirectories, directoryPath => { - _.each(platformSpecificFiles, filePath => { - const fileFullPath = path.join(directoryPath, filePath); - fs.writeFile(fileFullPath, "testData"); - - created.files.push(fileFullPath); - }); - }); - - // Add App_Resources file to app and app1 folders - _.each(destinationDirectories, directoryPath => { - const iosIconFullPath = path.join(directoryPath, "App_Resources/iOS/icon.png"); - fs.writeFile(iosIconFullPath, "test-image"); - created.resources.ios.push(iosIconFullPath); - - const androidFullPath = path.join(directoryPath, "App_Resources/Android/icon.png"); - fs.writeFile(androidFullPath, "test-image"); - created.resources.android.push(androidFullPath); - }); - - await execPreparePlatform(platformToTest, testDirData, release); - - const test1FileName = platformToTest.toLowerCase() === "ios" ? "test1.js" : "test2.js"; - const test2FileName = platformToTest.toLowerCase() === "ios" ? "test2.js" : "test1.js"; - - // Asserts that the files in app folder are process as platform specific - assert.isTrue(fs.exists(path.join(testDirData.appDestFolderPath, "app", test1FileName))); - assert.isFalse(fs.exists(path.join(testDirData.appDestFolderPath, "app", "test1-js"))); - - assert.isFalse(fs.exists(path.join(testDirData.appDestFolderPath, "app", test2FileName))); - assert.isFalse(fs.exists(path.join(testDirData.appDestFolderPath, "app", "test2-js"))); - - // Asserts that the files in app1 folder aren't process as platform specific - assert.isFalse(fs.exists(path.join(testDirData.appDestFolderPath, "app1")), "Asserts that the files in app1 folder aren't process as platform specific"); - - if (release) { - // Asserts that the files in tests folder aren't copied - assert.isFalse(fs.exists(path.join(testDirData.appDestFolderPath, "tests")), "Asserts that the files in tests folder aren't copied"); - } - - return created; - } - - function updateFile(files: string[], fileName: string, content: string) { - const fileToUpdate = _.find(files, (f) => f.indexOf(fileName) !== -1); - fs.writeFile(fileToUpdate, content); - } - - it("should process only files in app folder when preparing for iOS platform", async () => { - await testPreparePlatform("iOS"); - }); - - it("should process only files in app folder when preparing for Android platform", async () => { - await testPreparePlatform("Android"); - }); - - it("should process only files in app folder when preparing for iOS platform", async () => { - await testPreparePlatform("iOS", true); - }); - - it("should process only files in app folder when preparing for Android platform", async () => { - await testPreparePlatform("Android", true); - }); - - function getDefaultFolderVerificationData(platform: string, appDestFolderPath: string) { - const data: any = {}; - if (platform.toLowerCase() === "ios") { - data[path.join(appDestFolderPath, "app")] = { - missingFiles: ["test1.ios.js", "test2.android.js", "test2.js"], - presentFiles: ["test1.js", "test2-android-js", "test1-ios-js", "main.js"] - }; - - data[appDestFolderPath] = { - filesWithContent: [ - { - name: "Resources/icon.png", - content: "test-image" - } - ] - }; - } else { - data[path.join(appDestFolderPath, "app")] = { - missingFiles: ["test1.android.js", "test2.ios.js", "test1.js"], - presentFiles: ["test2.js", "test2-android-js", "test1-ios-js"] - }; - - data[appDestFolderPath] = { - filesWithContent: [ - { - name: "src/main/res/icon.png", - content: "test-image" - } - ] - }; - } - - return data; - } - - function mergeModifications(def: any, mod: any) { - // custom merge to reflect changes - const merged: any = _.cloneDeep(def); - _.forOwn(mod, (modFolder, folderRoot) => { - // whole folder not present in Default - if (!def.hasOwnProperty(folderRoot)) { - merged[folderRoot] = _.cloneDeep(modFolder[folderRoot]); - } else { - const defFolder = def[folderRoot]; - merged[folderRoot].filesWithContent = _.merge(defFolder.filesWithContent || [], modFolder.filesWithContent || []); - merged[folderRoot].missingFiles = (defFolder.missingFiles || []).concat(modFolder.missingFiles || []); - merged[folderRoot].presentFiles = (defFolder.presentFiles || []).concat(modFolder.presentFiles || []); - - // remove the missingFiles from the presentFiles if they were initially there - if (modFolder.missingFiles) { - merged[folderRoot].presentFiles = _.difference(defFolder.presentFiles, modFolder.missingFiles); - } - - // remove the presentFiles from the missingFiles if they were initially there. - if (modFolder.presentFiles) { - merged[folderRoot].missingFiles = _.difference(defFolder.presentFiles, modFolder.presentFiles); - } - } - }); - - return merged; - } - - // Executes a changes test case: - // 1. Executes Prepare Platform for the Platform - // 2. Applies some changes to the App. Persists the expected Modifications - // 3. Executes again Prepare Platform for the Platform - // 4. Gets the Default Destination App Structure and merges it with the Modifications - // 5. Asserts the Destination App matches our expectations - async function testChangesApplied(platform: string, applyChangesFn: (createdTestData: CreatedTestData) => any) { - const createdTestData = await testPreparePlatform(platform); - - const modifications = applyChangesFn(createdTestData); - - await execPreparePlatform(platform, createdTestData.testDirData); - - const defaultStructure = getDefaultFolderVerificationData(platform, createdTestData.testDirData.appDestFolderPath); - - const merged = mergeModifications(defaultStructure, modifications); - - DestinationFolderVerifier.verify(merged, fs); - } - - it("should sync only changed files, without special folders (iOS)", async () => { - const applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - const expectedFileContent = "updated-content-ios"; - updateFile(createdTestData.files, "test1.ios.js", expectedFileContent); - - // construct the folder modifications data - const modifications: any = {}; - modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { - filesWithContent: [ - { - name: "test1.js", - content: expectedFileContent - } - ] - }; - return modifications; - }; - await testChangesApplied("iOS", applyChangesFn); - }); - - it("should sync only changed files, without special folders (Android) #2697", async () => { - const applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - const expectedFileContent = "updated-content-android"; - updateFile(createdTestData.files, "test2.android.js", expectedFileContent); - - // construct the folder modifications data - const modifications: any = {}; - modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { - filesWithContent: [ - { - name: "test2.js", - content: expectedFileContent - } - ] - }; - return modifications; - }; - await testChangesApplied("Android", applyChangesFn); - }); - - it("Ensure App_Resources get reloaded after change in the app folder (iOS) #2560", async () => { - const applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - const expectedFileContent = "updated-icon-content"; - const iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/iOS/icon.png"); - fs.writeFile(iconPngPath, expectedFileContent); - - // construct the folder modifications data - const modifications: any = {}; - modifications[createdTestData.testDirData.appDestFolderPath] = { - filesWithContent: [ - { - name: "Resources/icon.png", - content: expectedFileContent - } - ] - }; + // TODO: check this tests with QAs + // describe("prepare platform unit tests", () => { + // let fs: IFileSystem; - return modifications; - }; - await testChangesApplied("iOS", applyChangesFn); - }); - - it("Ensure App_Resources get reloaded after change in the app folder (Android) #2560", async () => { - const applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - const expectedFileContent = "updated-icon-content"; - const iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/Android/icon.png"); - fs.writeFile(iconPngPath, expectedFileContent); - - // construct the folder modifications data - const modifications: any = {}; - modifications[createdTestData.testDirData.appDestFolderPath] = { - filesWithContent: [ - { - name: "src/main/res/icon.png", - content: expectedFileContent - } - ] - }; - - return modifications; - }; - await testChangesApplied("Android", applyChangesFn); - }); - - it("Ensure App_Resources get reloaded after a new file appears in the app folder (iOS) #2560", async () => { - const applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - const expectedFileContent = "new-file-content"; - const iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/iOS/new-file.png"); - fs.writeFile(iconPngPath, expectedFileContent); - - // construct the folder modifications data - const modifications: any = {}; - modifications[createdTestData.testDirData.appDestFolderPath] = { - filesWithContent: [ - { - name: "Resources/new-file.png", - content: expectedFileContent - } - ] - }; - - return modifications; - }; - await testChangesApplied("iOS", applyChangesFn); - }); - - it("Ensure App_Resources get reloaded after a new file appears in the app folder (Android) #2560", async () => { - const applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - const expectedFileContent = "new-file-content"; - const iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/Android/new-file.png"); - fs.writeFile(iconPngPath, expectedFileContent); - - // construct the folder modifications data - const modifications: any = {}; - modifications[createdTestData.testDirData.appDestFolderPath] = { - filesWithContent: [ - { - name: "src/main/res/new-file.png", - content: expectedFileContent - } - ] - }; + // beforeEach(() => { + // testInjector = createTestInjector(); + // testInjector.register("fs", fsLib.FileSystem); + // fs = testInjector.resolve("fs"); + // testInjector.resolve("projectData").initializeProjectData(); + // }); - return modifications; - }; - await testChangesApplied("Android", applyChangesFn); - }); + // function prepareDirStructure() { + // const tempFolder = temp.mkdirSync("prepare_platform"); + + // const appFolderPath = path.join(tempFolder, "app"); + // fs.createDirectory(appFolderPath); + + // const nodeModulesPath = path.join(tempFolder, "node_modules"); + // fs.createDirectory(nodeModulesPath); + + // const testsFolderPath = path.join(appFolderPath, "tests"); + // fs.createDirectory(testsFolderPath); + + // const app1FolderPath = path.join(tempFolder, "app1"); + // fs.createDirectory(app1FolderPath); + + // const appDestFolderPath = path.join(tempFolder, "appDest"); + // const appResourcesFolderPath = path.join(appDestFolderPath, "App_Resources"); + // const appResourcesPath = path.join(appFolderPath, "App_Resources/Android"); + // fs.createDirectory(appResourcesPath); + // fs.writeFile(path.join(appResourcesPath, "test.txt"), "test"); + // fs.writeJson(path.join(tempFolder, "package.json"), { + // name: "testname", + // nativescript: { + // id: "org.nativescript.testname" + // } + // }); + + // return { tempFolder, appFolderPath, app1FolderPath, appDestFolderPath, appResourcesFolderPath }; + // } + + // async function execPreparePlatform(platformToTest: string, testDirData: any, + // release?: boolean) { + // const platformsData = testInjector.resolve("platformsData"); + // platformsData.platformsNames = ["ios", "android"]; + // platformsData.getPlatformData = (platform: string) => { + // return { + // appDestinationDirectoryPath: testDirData.appDestFolderPath, + // appResourcesDestinationDirectoryPath: testDirData.appResourcesFolderPath, + // normalizedPlatformName: platformToTest, + // configurationFileName: platformToTest === "ios" ? INFO_PLIST_FILE_NAME : MANIFEST_FILE_NAME, + // projectRoot: testDirData.tempFolder, + // platformProjectService: { + // prepareProject: (): any => null, + // validate: () => Promise.resolve(), + // createProject: (projectRoot: string, frameworkDir: string) => Promise.resolve(), + // interpolateData: (projectRoot: string) => Promise.resolve(), + // afterCreateProject: (projectRoot: string): any => null, + // getAppResourcesDestinationDirectoryPath: (pData: IProjectData, frameworkVersion?: string): string => { + // if (platform.toLowerCase() === "ios") { + // const dirPath = path.join(testDirData.appDestFolderPath, "Resources"); + // fs.ensureDirectoryExists(dirPath); + // return dirPath; + // } else { + // const dirPath = path.join(testDirData.appDestFolderPath, "src", "main", "res"); + // fs.ensureDirectoryExists(dirPath); + // return dirPath; + // } + // }, + // processConfigurationFilesFromAppResources: () => Promise.resolve(), + // handleNativeDependenciesChange: () => Promise.resolve(), + // ensureConfigurationFileInAppResources: (): any => null, + // interpolateConfigurationFile: (): void => undefined, + // isPlatformPrepared: (projectRoot: string) => false, + // prepareAppResources: (appResourcesDirectoryPath: string, pData: IProjectData): void => undefined, + // checkForChanges: () => { /* */ } + // } + // }; + // }; + + // const projectData = testInjector.resolve("projectData"); + // projectData.projectDir = testDirData.tempFolder; + // projectData.projectName = "app"; + // projectData.appDirectoryPath = testDirData.appFolderPath; + // projectData.appResourcesDirectoryPath = path.join(testDirData.appFolderPath, "App_Resources"); + + // platformService = testInjector.resolve("platformService"); + // const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: release, useHotModuleReload: false }; + // await platformService.preparePlatform({ + // platform: platformToTest, + // appFilesUpdaterOptions, + // platformTemplate: "", + // projectData, + // config: { provision: null, teamId: null, sdk: null, frameworkPath: null, ignoreScripts: false }, + // env: {} + // }); + // } + + // async function testPreparePlatform(platformToTest: string, release?: boolean): Promise { + // const testDirData = prepareDirStructure(); + // const created: CreatedTestData = new CreatedTestData(); + // created.testDirData = testDirData; + + // // Add platform specific files to app and app1 folders + // const platformSpecificFiles = [ + // "test1.ios.js", "test1-ios-js", "test2.android.js", "test2-android-js", + // "main.js" + // ]; + + // const destinationDirectories = [testDirData.appFolderPath, testDirData.app1FolderPath]; + + // _.each(destinationDirectories, directoryPath => { + // _.each(platformSpecificFiles, filePath => { + // const fileFullPath = path.join(directoryPath, filePath); + // fs.writeFile(fileFullPath, "testData"); + + // created.files.push(fileFullPath); + // }); + // }); + + // // Add App_Resources file to app and app1 folders + // _.each(destinationDirectories, directoryPath => { + // const iosIconFullPath = path.join(directoryPath, "App_Resources/iOS/icon.png"); + // fs.writeFile(iosIconFullPath, "test-image"); + // created.resources.ios.push(iosIconFullPath); + + // const androidFullPath = path.join(directoryPath, "App_Resources/Android/icon.png"); + // fs.writeFile(androidFullPath, "test-image"); + // created.resources.android.push(androidFullPath); + // }); + + // await execPreparePlatform(platformToTest, testDirData, release); + + // const test1FileName = platformToTest.toLowerCase() === "ios" ? "test1.js" : "test2.js"; + // const test2FileName = platformToTest.toLowerCase() === "ios" ? "test2.js" : "test1.js"; + + // // Asserts that the files in app folder are process as platform specific + // assert.isTrue(fs.exists(path.join(testDirData.appDestFolderPath, "app", test1FileName))); + // assert.isFalse(fs.exists(path.join(testDirData.appDestFolderPath, "app", "test1-js"))); + + // assert.isFalse(fs.exists(path.join(testDirData.appDestFolderPath, "app", test2FileName))); + // assert.isFalse(fs.exists(path.join(testDirData.appDestFolderPath, "app", "test2-js"))); + + // // Asserts that the files in app1 folder aren't process as platform specific + // assert.isFalse(fs.exists(path.join(testDirData.appDestFolderPath, "app1")), "Asserts that the files in app1 folder aren't process as platform specific"); + + // if (release) { + // // Asserts that the files in tests folder aren't copied + // assert.isFalse(fs.exists(path.join(testDirData.appDestFolderPath, "tests")), "Asserts that the files in tests folder aren't copied"); + // } + + // return created; + // } + + // function updateFile(files: string[], fileName: string, content: string) { + // const fileToUpdate = _.find(files, (f) => f.indexOf(fileName) !== -1); + // fs.writeFile(fileToUpdate, content); + // } + + // it("should process only files in app folder when preparing for iOS platform", async () => { + // await testPreparePlatform("iOS"); + // }); - it("should sync new platform specific files (iOS)", async () => { - const applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - const expectedFileContent = "new-content-ios"; - fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.ios.js"), expectedFileContent); - - // construct the folder modifications data - const modifications: any = {}; - modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { - filesWithContent: [ - { - name: "test3.js", - content: expectedFileContent - } - ] - }; + // it("should process only files in app folder when preparing for Android platform", async () => { + // await testPreparePlatform("Android"); + // }); - return modifications; - }; - await testChangesApplied("iOS", applyChangesFn); - }); + // it("should process only files in app folder when preparing for iOS platform", async () => { + // await testPreparePlatform("iOS", true); + // }); - it("should sync new platform specific files (Android)", async () => { - const applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - const expectedFileContent = "new-content-android"; - fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.android.js"), expectedFileContent); - - // construct the folder modifications data - const modifications: any = {}; - modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { - filesWithContent: [ - { - name: "test3.js", - content: expectedFileContent - } - ] - }; + // it("should process only files in app folder when preparing for Android platform", async () => { + // await testPreparePlatform("Android", true); + // }); - return modifications; - }; - await testChangesApplied("Android", applyChangesFn); - }); + // function getDefaultFolderVerificationData(platform: string, appDestFolderPath: string) { + // const data: any = {}; + // if (platform.toLowerCase() === "ios") { + // data[path.join(appDestFolderPath, "app")] = { + // missingFiles: ["test1.ios.js", "test2.android.js", "test2.js"], + // presentFiles: ["test1.js", "test2-android-js", "test1-ios-js", "main.js"] + // }; + + // data[appDestFolderPath] = { + // filesWithContent: [ + // { + // name: "Resources/icon.png", + // content: "test-image" + // } + // ] + // }; + // } else { + // data[path.join(appDestFolderPath, "app")] = { + // missingFiles: ["test1.android.js", "test2.ios.js", "test1.js"], + // presentFiles: ["test2.js", "test2-android-js", "test1-ios-js"] + // }; + + // data[appDestFolderPath] = { + // filesWithContent: [ + // { + // name: "src/main/res/icon.png", + // content: "test-image" + // } + // ] + // }; + // } + + // return data; + // } + + // function mergeModifications(def: any, mod: any) { + // // custom merge to reflect changes + // const merged: any = _.cloneDeep(def); + // _.forOwn(mod, (modFolder, folderRoot) => { + // // whole folder not present in Default + // if (!def.hasOwnProperty(folderRoot)) { + // merged[folderRoot] = _.cloneDeep(modFolder[folderRoot]); + // } else { + // const defFolder = def[folderRoot]; + // merged[folderRoot].filesWithContent = _.merge(defFolder.filesWithContent || [], modFolder.filesWithContent || []); + // merged[folderRoot].missingFiles = (defFolder.missingFiles || []).concat(modFolder.missingFiles || []); + // merged[folderRoot].presentFiles = (defFolder.presentFiles || []).concat(modFolder.presentFiles || []); + + // // remove the missingFiles from the presentFiles if they were initially there + // if (modFolder.missingFiles) { + // merged[folderRoot].presentFiles = _.difference(defFolder.presentFiles, modFolder.missingFiles); + // } + + // // remove the presentFiles from the missingFiles if they were initially there. + // if (modFolder.presentFiles) { + // merged[folderRoot].missingFiles = _.difference(defFolder.presentFiles, modFolder.presentFiles); + // } + // } + // }); + + // return merged; + // } + + // // Executes a changes test case: + // // 1. Executes Prepare Platform for the Platform + // // 2. Applies some changes to the App. Persists the expected Modifications + // // 3. Executes again Prepare Platform for the Platform + // // 4. Gets the Default Destination App Structure and merges it with the Modifications + // // 5. Asserts the Destination App matches our expectations + // async function testChangesApplied(platform: string, applyChangesFn: (createdTestData: CreatedTestData) => any) { + // const createdTestData = await testPreparePlatform(platform); + + // const modifications = applyChangesFn(createdTestData); + + // await execPreparePlatform(platform, createdTestData.testDirData); + + // const defaultStructure = getDefaultFolderVerificationData(platform, createdTestData.testDirData.appDestFolderPath); + + // const merged = mergeModifications(defaultStructure, modifications); + + // DestinationFolderVerifier.verify(merged, fs); + // } + + // it("should sync only changed files, without special folders (iOS)", async () => { + // const applyChangesFn = (createdTestData: CreatedTestData) => { + // // apply changes + // const expectedFileContent = "updated-content-ios"; + // updateFile(createdTestData.files, "test1.ios.js", expectedFileContent); + + // // construct the folder modifications data + // const modifications: any = {}; + // modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + // filesWithContent: [ + // { + // name: "test1.js", + // content: expectedFileContent + // } + // ] + // }; + // return modifications; + // }; + // await testChangesApplied("iOS", applyChangesFn); + // }); - it("should sync new common files (iOS)", async () => { - const applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - const expectedFileContent = "new-content-ios"; - fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.js"), expectedFileContent); - - // construct the folder modifications data - const modifications: any = {}; - modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { - filesWithContent: [ - { - name: "test3.js", - content: expectedFileContent - } - ] - }; + // it("should sync only changed files, without special folders (Android) #2697", async () => { + // const applyChangesFn = (createdTestData: CreatedTestData) => { + // // apply changes + // const expectedFileContent = "updated-content-android"; + // updateFile(createdTestData.files, "test2.android.js", expectedFileContent); + + // // construct the folder modifications data + // const modifications: any = {}; + // modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + // filesWithContent: [ + // { + // name: "test2.js", + // content: expectedFileContent + // } + // ] + // }; + // return modifications; + // }; + // await testChangesApplied("Android", applyChangesFn); + // }); - return modifications; - }; - await testChangesApplied("iOS", applyChangesFn); - }); + // it("Ensure App_Resources get reloaded after change in the app folder (iOS) #2560", async () => { + // const applyChangesFn = (createdTestData: CreatedTestData) => { + // // apply changes + // const expectedFileContent = "updated-icon-content"; + // const iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/iOS/icon.png"); + // fs.writeFile(iconPngPath, expectedFileContent); + + // // construct the folder modifications data + // const modifications: any = {}; + // modifications[createdTestData.testDirData.appDestFolderPath] = { + // filesWithContent: [ + // { + // name: "Resources/icon.png", + // content: expectedFileContent + // } + // ] + // }; + + // return modifications; + // }; + // await testChangesApplied("iOS", applyChangesFn); + // }); - it("should sync new common file (Android)", async () => { - const applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - const expectedFileContent = "new-content-android"; - fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.js"), expectedFileContent); - - // construct the folder modifications data - const modifications: any = {}; - modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { - filesWithContent: [ - { - name: "test3.js", - content: expectedFileContent - } - ] - }; + // it("Ensure App_Resources get reloaded after change in the app folder (Android) #2560", async () => { + // const applyChangesFn = (createdTestData: CreatedTestData) => { + // // apply changes + // const expectedFileContent = "updated-icon-content"; + // const iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/Android/icon.png"); + // fs.writeFile(iconPngPath, expectedFileContent); + + // // construct the folder modifications data + // const modifications: any = {}; + // modifications[createdTestData.testDirData.appDestFolderPath] = { + // filesWithContent: [ + // { + // name: "src/main/res/icon.png", + // content: expectedFileContent + // } + // ] + // }; + + // return modifications; + // }; + // await testChangesApplied("Android", applyChangesFn); + // }); - return modifications; - }; - await testChangesApplied("Android", applyChangesFn); - }); + // it("Ensure App_Resources get reloaded after a new file appears in the app folder (iOS) #2560", async () => { + // const applyChangesFn = (createdTestData: CreatedTestData) => { + // // apply changes + // const expectedFileContent = "new-file-content"; + // const iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/iOS/new-file.png"); + // fs.writeFile(iconPngPath, expectedFileContent); + + // // construct the folder modifications data + // const modifications: any = {}; + // modifications[createdTestData.testDirData.appDestFolderPath] = { + // filesWithContent: [ + // { + // name: "Resources/new-file.png", + // content: expectedFileContent + // } + // ] + // }; + + // return modifications; + // }; + // await testChangesApplied("iOS", applyChangesFn); + // }); - it("invalid xml is caught", async () => { - require("colors"); - const testDirData = prepareDirStructure(); + // it("Ensure App_Resources get reloaded after a new file appears in the app folder (Android) #2560", async () => { + // const applyChangesFn = (createdTestData: CreatedTestData) => { + // // apply changes + // const expectedFileContent = "new-file-content"; + // const iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/Android/new-file.png"); + // fs.writeFile(iconPngPath, expectedFileContent); + + // // construct the folder modifications data + // const modifications: any = {}; + // modifications[createdTestData.testDirData.appDestFolderPath] = { + // filesWithContent: [ + // { + // name: "src/main/res/new-file.png", + // content: expectedFileContent + // } + // ] + // }; + + // return modifications; + // }; + // await testChangesApplied("Android", applyChangesFn); + // }); - // generate invalid xml - const fileFullPath = path.join(testDirData.appFolderPath, "file.xml"); - fs.writeFile(fileFullPath, ""); + // it("should sync new platform specific files (iOS)", async () => { + // const applyChangesFn = (createdTestData: CreatedTestData) => { + // // apply changes + // const expectedFileContent = "new-content-ios"; + // fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.ios.js"), expectedFileContent); + + // // construct the folder modifications data + // const modifications: any = {}; + // modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + // filesWithContent: [ + // { + // name: "test3.js", + // content: expectedFileContent + // } + // ] + // }; + + // return modifications; + // }; + // await testChangesApplied("iOS", applyChangesFn); + // }); - const platformsData = testInjector.resolve("platformsData"); - platformsData.platformsNames = ["android"]; - platformsData.getPlatformData = (platform: string) => { - return { - appDestinationDirectoryPath: testDirData.appDestFolderPath, - appResourcesDestinationDirectoryPath: testDirData.appResourcesFolderPath, - normalizedPlatformName: "Android", - projectRoot: testDirData.tempFolder, - configurationFileName: "configFileName", - platformProjectService: { - prepareProject: (): any => null, - prepareAppResources: (): any => null, - validate: () => Promise.resolve(), - createProject: (projectRoot: string, frameworkDir: string) => Promise.resolve(), - interpolateData: (projectRoot: string) => Promise.resolve(), - afterCreateProject: (projectRoot: string): any => null, - getAppResourcesDestinationDirectoryPath: () => testDirData.appResourcesFolderPath, - processConfigurationFilesFromAppResources: () => Promise.resolve(), - handleNativeDependenciesChange: () => Promise.resolve(), - ensureConfigurationFileInAppResources: (): any => null, - interpolateConfigurationFile: (): void => undefined, - isPlatformPrepared: (projectRoot: string) => false, - checkForChanges: () => { /* */ } - }, - frameworkPackageName: "tns-ios" - }; - }; + // it("should sync new platform specific files (Android)", async () => { + // const applyChangesFn = (createdTestData: CreatedTestData) => { + // // apply changes + // const expectedFileContent = "new-content-android"; + // fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.android.js"), expectedFileContent); + + // // construct the folder modifications data + // const modifications: any = {}; + // modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + // filesWithContent: [ + // { + // name: "test3.js", + // content: expectedFileContent + // } + // ] + // }; + + // return modifications; + // }; + // await testChangesApplied("Android", applyChangesFn); + // }); - const projectData = testInjector.resolve("projectData"); - projectData.projectDir = testDirData.tempFolder; - projectData.appDirectoryPath = projectData.getAppDirectoryPath(); - projectData.appResourcesDirectoryPath = projectData.getAppResourcesDirectoryPath(); + // it("should sync new common files (iOS)", async () => { + // const applyChangesFn = (createdTestData: CreatedTestData) => { + // // apply changes + // const expectedFileContent = "new-content-ios"; + // fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.js"), expectedFileContent); + + // // construct the folder modifications data + // const modifications: any = {}; + // modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + // filesWithContent: [ + // { + // name: "test3.js", + // content: expectedFileContent + // } + // ] + // }; + + // return modifications; + // }; + // await testChangesApplied("iOS", applyChangesFn); + // }); - platformService = testInjector.resolve("platformService"); - const oldLoggerWarner = testInjector.resolve("$logger").warn; - let warnings: string = ""; - try { - testInjector.resolve("$logger").warn = (text: string) => warnings += text; - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: false, useHotModuleReload: false }; - await platformService.preparePlatform({ - platform: "android", - appFilesUpdaterOptions, - platformTemplate: "", - projectData, - config: { provision: null, teamId: null, sdk: null, frameworkPath: null, ignoreScripts: false }, - env: {} - }); - } finally { - testInjector.resolve("$logger").warn = oldLoggerWarner; - } + // it("should sync new common file (Android)", async () => { + // const applyChangesFn = (createdTestData: CreatedTestData) => { + // // apply changes + // const expectedFileContent = "new-content-android"; + // fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.js"), expectedFileContent); + + // // construct the folder modifications data + // const modifications: any = {}; + // modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + // filesWithContent: [ + // { + // name: "test3.js", + // content: expectedFileContent + // } + // ] + // }; + + // return modifications; + // }; + // await testChangesApplied("Android", applyChangesFn); + // }); - // Asserts that prepare has caught invalid xml - assert.isFalse(warnings.indexOf("has errors") !== -1); - }); - }); + // it("invalid xml is caught", async () => { + // require("colors"); + // const testDirData = prepareDirStructure(); + + // // generate invalid xml + // const fileFullPath = path.join(testDirData.appFolderPath, "file.xml"); + // fs.writeFile(fileFullPath, ""); + + // const platformsData = testInjector.resolve("platformsData"); + // platformsData.platformsNames = ["android"]; + // platformsData.getPlatformData = (platform: string) => { + // return { + // appDestinationDirectoryPath: testDirData.appDestFolderPath, + // appResourcesDestinationDirectoryPath: testDirData.appResourcesFolderPath, + // normalizedPlatformName: "Android", + // projectRoot: testDirData.tempFolder, + // configurationFileName: "configFileName", + // platformProjectService: { + // prepareProject: (): any => null, + // prepareAppResources: (): any => null, + // validate: () => Promise.resolve(), + // createProject: (projectRoot: string, frameworkDir: string) => Promise.resolve(), + // interpolateData: (projectRoot: string) => Promise.resolve(), + // afterCreateProject: (projectRoot: string): any => null, + // getAppResourcesDestinationDirectoryPath: () => testDirData.appResourcesFolderPath, + // processConfigurationFilesFromAppResources: () => Promise.resolve(), + // handleNativeDependenciesChange: () => Promise.resolve(), + // ensureConfigurationFileInAppResources: (): any => null, + // interpolateConfigurationFile: (): void => undefined, + // isPlatformPrepared: (projectRoot: string) => false, + // checkForChanges: () => { /* */ } + // }, + // frameworkPackageName: "tns-ios" + // }; + // }; + + // const projectData = testInjector.resolve("projectData"); + // projectData.projectDir = testDirData.tempFolder; + // projectData.appDirectoryPath = projectData.getAppDirectoryPath(); + // projectData.appResourcesDirectoryPath = projectData.getAppResourcesDirectoryPath(); + + // platformService = testInjector.resolve("platformService"); + // const oldLoggerWarner = testInjector.resolve("$logger").warn; + // let warnings: string = ""; + // try { + // testInjector.resolve("$logger").warn = (text: string) => warnings += text; + // const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: false, useHotModuleReload: false }; + // await platformService.preparePlatform({ + // platform: "android", + // appFilesUpdaterOptions, + // platformTemplate: "", + // projectData, + // config: { provision: null, teamId: null, sdk: null, frameworkPath: null, ignoreScripts: false }, + // env: {} + // }); + // } finally { + // testInjector.resolve("$logger").warn = oldLoggerWarner; + // } + + // // Asserts that prepare has caught invalid xml + // assert.isFalse(warnings.indexOf("has errors") !== -1); + // }); + // }); describe("build", () => { function mockData(buildOutput: string[], projectName: string): void { diff --git a/test/plugin-prepare.ts b/test/plugin-prepare.ts deleted file mode 100644 index 00dd7b04b1..0000000000 --- a/test/plugin-prepare.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { assert } from "chai"; -import { NpmPluginPrepare } from "../lib/tools/node-modules/node-modules-dest-copy"; - -require("should"); - -class TestNpmPluginPrepare extends NpmPluginPrepare { - public preparedDependencies: IDictionary = {}; - - constructor(private previouslyPrepared: IDictionary) { - super(null, null, { - getPlatformData: () => { - return { - platformProjectService: { - beforePrepareAllPlugins: () => Promise.resolve() - } - }; - } - }, null); - } - - protected getPreviouslyPreparedDependencies(platform: string): IDictionary { - return this.previouslyPrepared; - } - - protected async afterPrepare(dependencies: IDependencyData[], platform: string): Promise { - _.each(dependencies, d => { - this.preparedDependencies[d.name] = true; - }); - } -} - -describe("Plugin preparation", () => { - it("skips prepare if no plugins", async () => { - const pluginPrepare = new TestNpmPluginPrepare({}); - await pluginPrepare.preparePlugins([], "android", null, {}); - assert.deepEqual({}, pluginPrepare.preparedDependencies); - }); - - it("saves prepared plugins after preparation", async () => { - const pluginPrepare = new TestNpmPluginPrepare({ "tns-core-modules-widgets": true }); - const testDependencies: IDependencyData[] = [ - { - name: "tns-core-modules-widgets", - depth: 0, - directory: "some dir", - nativescript: null, - }, - { - name: "nativescript-calendar", - depth: 0, - directory: "some dir", - nativescript: null, - } - ]; - await pluginPrepare.preparePlugins(testDependencies, "android", null, {}); - const prepareData = { "tns-core-modules-widgets": true, "nativescript-calendar": true }; - assert.deepEqual(prepareData, pluginPrepare.preparedDependencies); - }); -}); diff --git a/test/plugins-service.ts b/test/plugins-service.ts index f2530b2e73..c4b0f9f874 100644 --- a/test/plugins-service.ts +++ b/test/plugins-service.ts @@ -569,7 +569,7 @@ describe("Plugins service", () => { `\n@#[line:1,col:39].` + `\n@#[line:1,col:39].`; mockBeginCommand(testInjector, expectedErrorMessage); - await pluginsService.prepare(pluginJsonData, "android", projectData, {}); + await pluginsService.preparePluginNativeCode(pluginsService.convertToPluginData(pluginJsonData, projectData.projectDir), "android", projectData); }); });