Skip to content

Commit de55fb7

Browse files
committed
refactor(integrations): clearer enabling & disabling
1 parent 024ef43 commit de55fb7

6 files changed

Lines changed: 71 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ the CHANGELOG files within CLI packages. For specific commit-level changes, see
77

88
## Versions
99

10+
<a name="3.8.0"></a>
11+
### 3.8.0 (PENDING)
12+
13+
* :trumpet: All functionality provided by the
14+
`@ionic/cli-plugin-ionic-angular`, `@ionic/cli-plugin-ionic1`,
15+
`@ionic/cli-plugin-cordova`, and `@ionic/cli-plugin-gulp` plugins has been
16+
moved into the core `ionic` package. The listed CLI plugins have been marked
17+
as deprecated. For the former two, project type is now detected and handled
18+
appropriately during `ionic build`, `ionic serve`, etc. For the latter two,
19+
integrations such as Cordova and Gulp are now detected and enabled
20+
automatically. See
21+
[README.md#integrations](https://github.com/ionic-team/ionic-cli/blob/master/README.md#integrations).
22+
The `@ionic/cli-plugin-proxy` plugin is unchanged. You are encouraged to
23+
uninstall the deprecated CLI plugins upon updating, as they are no longer
24+
needed and will not be loaded.
25+
* Fixed `ionic cordova prepare` such that it no longer errors when platforms
26+
are not detected, it just does nothing, as there is nothing to do.
27+
1028
<a name="3.7.0"></a>
1129
### 3.7.0 (2017-08-02)
1230

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ reports and feature requests.
2222
* [Getting Started](#getting-started)
2323
* [Using Cordova](#using-cordova)
2424
* [Requirements](#requirements-1)
25+
* [Integrations](#integrations)
2526
* [Environment Variables](#environment-variables)
2627
* [CLI Flags](#cli-flags)
2728
* [CLI Config](#cli-config)
@@ -47,7 +48,7 @@ prefix with `sudo` or can setup [proper file permissions for
4748
npm](https://docs.npmjs.com/getting-started/fixing-npm-permissions).*
4849

4950
:memo: *Note: Running `ionic` will first look to see if you're in an Ionic
50-
project. If you are, it runs the locally installed CLI.*
51+
project. If you are, it runs the locally installed CLI, if installed.*
5152

5253
<a name="ionic-1"></a>
5354
<a name="ionic-v1"></a>
@@ -98,6 +99,21 @@ $ ionic cordova --help
9899
$ ionic cordova run ios
99100
```
100101

102+
## Integrations
103+
104+
As of CLI 3.8, the `@ionic/cli-plugin-cordova` and `@ionic/cli-plugin-gulp`
105+
have been deprecated in favor of *integrations*. Integrations are automatically
106+
detected and enabled, but can be easily disabled.
107+
108+
Integrations hook into CLI events. For example, when the Cordova integration is
109+
enabled, `ionic cordova prepare` will run after `ionic build` runs. See [CLI
110+
Hooks](#cli-hooks).
111+
112+
| integration | enabled when... | disabled with... |
113+
| ------------|-----------------------------------------------------------|-------------------------------------------------------|
114+
| Cordova | `ionic cordova` commands are run | `ionic config set integrations.cordova.enabled false` |
115+
| Gulp | `gulp` exists in `devDependencies` of your `package.json` | `ionic config set integrations.gulp.enabled false` |
116+
101117
## Environment Variables
102118

103119
The CLI will look for the following environment variables:

packages/@ionic/cli-utils/src/definitions.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,21 @@ export interface ProjectFileProxy {
7878

7979
export type ProjectType = 'ionic-angular' | 'ionic1';
8080

81+
export interface ProjectIntegration {
82+
enabled?: boolean;
83+
}
84+
85+
export interface ProjectIntegrationGulp extends ProjectIntegration {
86+
file?: string; // gulpfile.js location, because some people use Gulpfile.js
87+
}
88+
8189
export interface ProjectFile {
8290
name: string;
8391
type: ProjectType;
8492
app_id: string;
8593
integrations: {
86-
cordova?: Object;
87-
gulp?: {
88-
file?: string; // gulpfile.js location, because some people use Gulpfile.js
89-
};
94+
cordova?: ProjectIntegration;
95+
gulp?: ProjectIntegrationGulp;
9096
};
9197
documentRoot?: string; // www folder location (TODO: use this everywhere)
9298
watchPatterns?: string[];

packages/@ionic/cli-utils/src/lib/gulp.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export async function loadGulp(env: IonicEnvironment): Promise<typeof gulpType>
1616

1717
const project = await env.project.load();
1818

19-
const gulpFilePath = path.join(env.project.directory, project.integrations.gulp && project.integrations.gulp.file ? project.integrations.gulp.file : 'gulpfile.js');
19+
if (typeof project.integrations.gulp === 'undefined' || project.integrations.gulp.enabled === false) {
20+
throw new FatalException('Not attempting to load gulp from a project with gulp integration disabled.');
21+
}
22+
23+
const gulpFilePath = path.join(env.project.directory, project.integrations.gulp.file ? project.integrations.gulp.file : 'gulpfile.js');
2024
const gulpPath = path.join(env.project.directory, 'node_modules', 'gulp');
2125

2226
try {
@@ -67,14 +71,19 @@ export async function getGulpVersion(): Promise<string | undefined> {
6771
return gulpVersion;
6872
}
6973

70-
export async function runTask(env: IonicEnvironment, name: string): Promise<void> {
74+
export async function checkGulp(env: IonicEnvironment) {
7175
const project = await env.project.load();
7276

73-
if (typeof project.integrations.gulp === 'undefined') {
74-
project.integrations.gulp = {};
77+
if (!project.integrations.gulp) {
78+
env.log.info('Enabling Gulp integration.');
79+
await env.runcmd(['config', 'set', 'integrations.gulp', '{}', '--json', '--force']);
7580
}
81+
}
7682

77-
if (project.integrations.gulp) {
83+
export async function runTask(env: IonicEnvironment, name: string): Promise<void> {
84+
const project = await env.project.load();
85+
86+
if (project.integrations.gulp && project.integrations.gulp.enabled !== false) {
7887
const gulp = await loadGulp(env);
7988
const gulpStart = promisify<void, string>(gulp.start.bind(gulp));
8089

@@ -93,11 +102,7 @@ export async function runTask(env: IonicEnvironment, name: string): Promise<void
93102
export async function registerWatchEvents(env: IonicEnvironment) {
94103
const project = await env.project.load();
95104

96-
if (typeof project.integrations.gulp === 'undefined') {
97-
project.integrations.gulp = {};
98-
}
99-
100-
if (project.integrations.gulp) {
105+
if (project.integrations.gulp && project.integrations.gulp.enabled !== false) {
101106
if (!project.watchPatterns) {
102107
project.watchPatterns = [];
103108
}

packages/ionic/src/commands/cordova/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ export class CordovaCommand extends Command {
116116
const project = await this.env.project.load();
117117

118118
if (!project.integrations.cordova) {
119-
project.integrations.cordova = {};
119+
this.env.log.info('Enabling Cordova integration.');
120+
await this.runcmd(['config', 'set', 'integrations.cordova', '{}', '--json', '--force']);
120121
}
121122

122123
// Check for www folder

packages/ionic/src/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export function registerHooks(hooks: IHookEngine) {
3737
}
3838

3939
if (packageJson.devDependencies && packageJson.devDependencies['gulp']) {
40-
const { runTask } = await import('@ionic/cli-utils/lib/gulp');
40+
const { checkGulp, runTask } = await import('@ionic/cli-utils/lib/gulp');
41+
await checkGulp(env);
4142
await runTask(env, BUILD_BEFORE_SCRIPT);
4243
}
4344
});
@@ -51,11 +52,12 @@ export function registerHooks(hooks: IHookEngine) {
5152
}
5253

5354
if (packageJson.devDependencies && packageJson.devDependencies['gulp']) {
54-
const { runTask } = await import('@ionic/cli-utils/lib/gulp');
55+
const { checkGulp, runTask } = await import('@ionic/cli-utils/lib/gulp');
56+
await checkGulp(env);
5557
await runTask(env, BUILD_AFTER_SCRIPT);
5658
}
5759

58-
if (project.integrations.cordova) {
60+
if (project.integrations.cordova && project.integrations.cordova.enabled !== false) {
5961
await env.runcmd(['cordova', 'prepare']);
6062
}
6163
});
@@ -69,7 +71,8 @@ export function registerHooks(hooks: IHookEngine) {
6971
}
7072

7173
if (packageJson.devDependencies && packageJson.devDependencies['gulp']) {
72-
const { registerWatchEvents, runTask } = await import('@ionic/cli-utils/lib/gulp');
74+
const { checkGulp, registerWatchEvents, runTask } = await import('@ionic/cli-utils/lib/gulp');
75+
await checkGulp(env);
7376
await registerWatchEvents(env);
7477
await runTask(env, WATCH_BEFORE_SCRIPT);
7578
}
@@ -105,7 +108,7 @@ export function registerHooks(hooks: IHookEngine) {
105108
info.push({ type: 'local-packages', name: '@ionic/app-scripts', version: appScriptsVersion ? appScriptsVersion : 'not installed' });
106109
}
107110

108-
if (project.integrations.cordova) {
111+
if (project.integrations.cordova && project.integrations.cordova.enabled !== false) {
109112
const { getAndroidSdkToolsVersion } = await import('@ionic/cli-utils/lib/android');
110113
const { getCordovaCLIVersion, getCordovaPlatformVersions } = await import('@ionic/cli-utils/lib/cordova/utils');
111114

@@ -145,7 +148,7 @@ export function registerHooks(hooks: IHookEngine) {
145148
}
146149
}
147150

148-
if (project.integrations.gulp) {
151+
if (project.integrations.gulp && project.integrations.gulp.enabled !== false) {
149152
const { getGulpVersion } = await import('@ionic/cli-utils/lib/gulp');
150153
const gulpVersion = await getGulpVersion();
151154
info.push({ type: 'global-packages', name: 'Gulp CLI', version: gulpVersion || 'not installed globally' });

0 commit comments

Comments
 (0)