๐Ÿ“ฆ ionic-team / ionic-cli

๐Ÿ“„ index.ts ยท 81 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81import * as chalk from 'chalk';
import * as Debug from 'debug';
import * as lodash from 'lodash';
import * as path from 'path';

import { Project } from '../';
import { InfoItem } from '../../../definitions';
import { RunnerNotFoundException } from '../../errors';

const debug = Debug('ionic:lib:project:vue');

export class VueViteProject extends Project {
  readonly type: 'vue' = 'vue';

  async getInfo(): Promise<InfoItem[]> {
    const [
      [ionicVuePkg, ionicVuePkgPath],
    ] = await Promise.all([
      this.getPackageJson('@ionic/vue'),
    ]);

    return [
      ...(await super.getInfo()),
      {
        group: 'ionic',
        name: 'Ionic Framework',
        key: 'framework',
        value: ionicVuePkg ? `@ionic/vue ${ionicVuePkg.version}` : 'not installed',
        path: ionicVuePkgPath,
      },
    ];
  }

  /**
   * We can't detect Vue project types. We don't know what they look like!
   */
  async detected() {
    try {
      const pkg = await this.requirePackageJson();
      const deps = lodash.assign({}, pkg.dependencies, pkg.devDependencies);

      if (typeof deps['@ionic/vue'] === 'string') {
        debug(`${chalk.bold('@ionic/vue')} detected in ${chalk.bold('package.json')}`);
        return true;
      }
    } catch (e) {
      // ignore
    }

    return false;
  }

  async getDefaultDistDir(): Promise<string> {
    return 'dist';
  }

  async requireBuildRunner(): Promise<import('./build').VueViteBuildRunner> {
    const { VueViteBuildRunner } = await import('./build');
    const deps = { ...this.e, project: this };
    return new VueViteBuildRunner(deps);
  }

  async requireServeRunner(): Promise<import('./serve').VueServeRunner> {
    const { VueServeRunner } = await import('./serve');
    const deps = { ...this.e, project: this };
    return new VueServeRunner(deps);
  }

  async requireGenerateRunner(): Promise<never> {
    throw new RunnerNotFoundException(
      `Cannot perform generate for Vue projects.\n` +
      `Since you're using the ${chalk.bold('Vue')} project type, this command won't work. The Ionic CLI doesn't know how to generate framework components for Vue projects.`
    );
  }

  setPrimaryTheme(themeColor: string): Promise<void> {
    const themePath = path.join(this.directory, 'src', 'theme', 'variables.css');
    return this.writeThemeColor(themePath, themeColor);
  }
}