From 6090362966c4a303107e18c9bef197d4c26d2563 Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 5 Jun 2019 11:55:10 +0300 Subject: [PATCH] feat: remove init command --- docs/man_pages/project/creation/init.md | 25 ----- lib/bootstrap.ts | 3 - lib/commands/init.ts | 12 --- lib/declarations.d.ts | 4 - lib/services/project-init-service.ts | 134 ------------------------ 5 files changed, 178 deletions(-) delete mode 100644 docs/man_pages/project/creation/init.md delete mode 100644 lib/commands/init.ts delete mode 100644 lib/services/project-init-service.ts diff --git a/docs/man_pages/project/creation/init.md b/docs/man_pages/project/creation/init.md deleted file mode 100644 index bb5a0ebc1d..0000000000 --- a/docs/man_pages/project/creation/init.md +++ /dev/null @@ -1,25 +0,0 @@ -<% if (isJekyll) { %>--- -title: tns init -position: 2 ----<% } %> -# tns init - - -Usage | Synopsis ----|--- -General | `$ tns init [--path ] [--force]` - -Initializes a project for development. The command prompts you to provide your project configuration interactively and uses the information to create a new `package.json` file or update the existing one. - -### Options -* `--path` - Specifies the directory where you want to initialize the project, if different from the current directory. The directory must be empty. -* `--force` - If set, applies the default project configuration and does not show the interactive prompt. The default project configuration targets the latest official runtimes and sets `org.nativescript.` for application identifier. - -<% if(isHtml) { %> -### Related Commands - -Command | Description -----------|---------- -[create](create.html) | Creates a new project for native development with NativeScript from the default template or from an existing NativeScript project. -[install](/lib-management/install.html) | Installs all platforms and dependencies described in the `package.json` file in the current directory. -<% } %> \ No newline at end of file diff --git a/lib/bootstrap.ts b/lib/bootstrap.ts index 167bb6f21d..ccc3349544 100644 --- a/lib/bootstrap.ts +++ b/lib/bootstrap.ts @@ -131,9 +131,6 @@ $injector.require("xcprojService", "./services/xcproj-service"); $injector.require("versionsService", "./services/versions-service"); $injector.requireCommand("install", "./commands/install"); -$injector.require("projectInitService", "./services/project-init-service"); -$injector.requireCommand("init", "./commands/init"); - $injector.require("infoService", "./services/info-service"); $injector.requireCommand("info", "./commands/info"); diff --git a/lib/commands/init.ts b/lib/commands/init.ts deleted file mode 100644 index 36984c0dd6..0000000000 --- a/lib/commands/init.ts +++ /dev/null @@ -1,12 +0,0 @@ -export class ProjectInitCommand implements ICommand { - public allowedParameters: ICommandParameter[] = []; - public enableHooks = false; - - constructor(private $projectInitService: IProjectInitService) { } - - public async execute(args: string[]): Promise { - return this.$projectInitService.initialize(); - } -} - -$injector.registerCommand("init", ProjectInitCommand); diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index 1372cda3ff..688c1aca76 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -586,10 +586,6 @@ interface IUpdatePlatformOptions { canUpdate: boolean; } -interface IProjectInitService { - initialize(): Promise; -} - interface IInfoService { printComponentsInfo(): Promise; } diff --git a/lib/services/project-init-service.ts b/lib/services/project-init-service.ts deleted file mode 100644 index 81ee369093..0000000000 --- a/lib/services/project-init-service.ts +++ /dev/null @@ -1,134 +0,0 @@ -import * as constants from "../constants"; -import * as helpers from "../common/helpers"; -import * as path from "path"; -import * as semver from "semver"; - -export class ProjectInitService implements IProjectInitService { - private static MIN_SUPPORTED_FRAMEWORK_VERSIONS: IStringDictionary = { - "tns-ios": "1.1.0", - "tns-android": "1.1.0", - "tns-core-modules": "1.2.0" - }; - - private static VERSION_KEY_NAME = "version"; - - private _projectFilePath: string; - - constructor(private $fs: IFileSystem, - private $logger: ILogger, - private $options: IOptions, - private $injector: IInjector, - private $staticConfig: IStaticConfig, - private $projectHelper: IProjectHelper, - private $prompter: IPrompter, - private $packageManager: INodePackageManager, - private $packageInstallationManager: IPackageInstallationManager) { } - - public async initialize(): Promise { - let projectData: any = {}; - - if (this.$fs.exists(this.projectFilePath)) { - projectData = this.$fs.readJson(this.projectFilePath); - } - - const projectDataBackup = _.extend({}, projectData); - - if (!projectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE]) { - projectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE] = {}; - this.$fs.writeJson(this.projectFilePath, projectData); // We need to create package.json file here in order to prevent "No project found at or above and neither was a --path specified." when resolving platformsDataService - } - - try { - projectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE]["id"] = await this.getProjectId(); - - if (this.$options.frameworkName && this.$options.frameworkVersion) { - const currentPlatformData = projectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE][this.$options.frameworkName] || {}; - - projectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE][this.$options.frameworkName] = _.extend(currentPlatformData, this.buildVersionData(this.$options.frameworkVersion)); - } else { - const $mobileHelper: Mobile.IMobileHelper = this.$injector.resolve("mobileHelper"); - const $platformsDataService = this.$injector.resolve("platformsDataService"); - const $projectData = this.$injector.resolve("projectData"); - $projectData.initializeProjectData(path.dirname(this.projectFilePath)); - for (const platform of $mobileHelper.platformNames) { - const platformData: IPlatformData = $platformsDataService.getPlatformData(platform, $projectData); - if (!platformData.targetedOS || (platformData.targetedOS && _.includes(platformData.targetedOS, process.platform))) { - const currentPlatformData = projectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE][platformData.frameworkPackageName] || {}; - - projectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE][platformData.frameworkPackageName] = _.extend(currentPlatformData, await this.getVersionData(platformData.frameworkPackageName)); - } - } - } - - const dependencies = projectData.dependencies; - if (!dependencies) { - projectData.dependencies = Object.create(null); - } - - // In case console is interactive and --force is not specified, do not read the version from package.json, show all available versions to the user. - const tnsCoreModulesVersionInPackageJson = this.useDefaultValue ? projectData.dependencies[constants.TNS_CORE_MODULES_NAME] : null; - projectData.dependencies[constants.TNS_CORE_MODULES_NAME] = tnsCoreModulesVersionInPackageJson || (await this.getVersionData(constants.TNS_CORE_MODULES_NAME))["version"]; - - this.$fs.writeJson(this.projectFilePath, projectData); - } catch (err) { - this.$fs.writeJson(this.projectFilePath, projectDataBackup); - throw err; - } - - this.$logger.info("Project successfully initialized."); - } - - private get projectFilePath(): string { - if (!this._projectFilePath) { - const projectDir = path.resolve(this.$options.path || "."); - this._projectFilePath = path.join(projectDir, constants.PACKAGE_JSON_FILE_NAME); - } - - return this._projectFilePath; - } - - private async getProjectId(): Promise { - if (this.$options.appid) { - return this.$options.appid; - } - - const defaultAppId = this.$projectHelper.generateDefaultAppId(path.basename(path.dirname(this.projectFilePath)), constants.DEFAULT_APP_IDENTIFIER_PREFIX); - if (this.useDefaultValue) { - return defaultAppId; - } - - return await this.$prompter.getString("Id:", { defaultAction: () => defaultAppId }); - } - - private async getVersionData(packageName: string): Promise { - const latestVersion = await this.$packageInstallationManager.getLatestCompatibleVersion(packageName); - - if (this.useDefaultValue) { - return this.buildVersionData(latestVersion); - } - - const allVersions: any = await this.$packageManager.view(packageName, { "versions": true }); - const versions = _.filter(allVersions, (v: string) => semver.gte(v, ProjectInitService.MIN_SUPPORTED_FRAMEWORK_VERSIONS[packageName])); - if (versions.length === 1) { - this.$logger.info(`Only ${versions[0]} version is available for ${packageName}.`); - return this.buildVersionData(versions[0]); - } - const sortedVersions = versions.sort(helpers.versionCompare).reverse(); - //TODO: plamen5kov: don't offer versions from next (they are not available) - const version = await this.$prompter.promptForChoice(`${packageName} version:`, sortedVersions); - return this.buildVersionData(version); - } - - private buildVersionData(version: string): IStringDictionary { - const result: IStringDictionary = {}; - - result[ProjectInitService.VERSION_KEY_NAME] = version; - - return result; - } - - private get useDefaultValue(): boolean { - return !helpers.isInteractive() || this.$options.force; - } -} -$injector.register("projectInitService", ProjectInitService);