1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const os_1 = tslib_1.__importDefault(require("os"));
|
5 | const path_1 = tslib_1.__importDefault(require("path"));
|
6 | const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
7 | const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
8 | const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
9 | const uuid = tslib_1.__importStar(require("uuid"));
|
10 | const buildTargets_1 = tslib_1.__importDefault(require("./buildTargets"));
|
11 | const ProjectConfiguration_1 = require("./ProjectConfiguration");
|
12 | const sdkVersion_1 = tslib_1.__importDefault(require("./sdkVersion"));
|
13 | function scaffoldDirectory(scaffold, sourceScaffoldOverride = scaffold) {
|
14 | const scaffoldPath = path_1.default.join(__dirname, '..', 'scaffold', sourceScaffoldOverride);
|
15 | fs_extra_1.default.copySync(scaffoldPath, scaffold);
|
16 | }
|
17 | async function newProject() {
|
18 | const packageJSONPath = 'package.json';
|
19 | const packageJSON = fs_extra_1.default.readJSONSync(packageJSONPath);
|
20 | const config = ProjectConfiguration_1.normalizeProjectConfig(packageJSON);
|
21 | const packageName = packageJSON.name;
|
22 | const defaultDisplayName = typeof packageName === 'string' ? lodash_1.default.startCase(packageName) : undefined;
|
23 | const { appType, appDisplayName, withCompanion, withSettings, enabledBuildTargets, } = await inquirer_1.default.prompt([
|
24 | {
|
25 | name: 'appType',
|
26 | type: 'list',
|
27 | choices: Object.values(ProjectConfiguration_1.AppType),
|
28 | message: 'What type of application should be created?',
|
29 | },
|
30 | {
|
31 | name: 'appDisplayName',
|
32 | message: 'What should the name of this application be?',
|
33 | default: defaultDisplayName,
|
34 | validate: ProjectConfiguration_1.validateDisplayName,
|
35 | },
|
36 | {
|
37 | name: 'withCompanion',
|
38 | type: 'confirm',
|
39 | message: 'Should this application contain a companion component?',
|
40 | },
|
41 | {
|
42 | name: 'withSettings',
|
43 | type: 'confirm',
|
44 | when: (args) => args.withCompanion,
|
45 | message: 'Should this application contain a settings component?',
|
46 | },
|
47 | {
|
48 | name: 'enabledBuildTargets',
|
49 | type: 'checkbox',
|
50 | choices: Object.keys(buildTargets_1.default).map((platform) => ({
|
51 | name: buildTargets_1.default[platform].displayName,
|
52 | value: platform,
|
53 | })),
|
54 | default: Object.keys(buildTargets_1.default),
|
55 | message: 'Which platforms should this application be built for?',
|
56 | },
|
57 | ]);
|
58 | console.log('Creating device component');
|
59 | scaffoldDirectory('app');
|
60 | scaffoldDirectory('resources', sdkVersion_1.default().major < 5 ? 'resources_4.x' : undefined);
|
61 | scaffoldDirectory('tsconfig.json');
|
62 | if (withCompanion) {
|
63 | console.log('Creating companion component');
|
64 | scaffoldDirectory('companion');
|
65 | }
|
66 | if (withSettings) {
|
67 | console.log('Creating settings component');
|
68 | scaffoldDirectory('settings');
|
69 | }
|
70 | packageJSON.fitbit = Object.assign(Object.assign({}, config), { appType,
|
71 | appDisplayName, appUUID: uuid.v4(), buildTargets: enabledBuildTargets, wipeColor: '#ffffff' });
|
72 | packageJSON.scripts = {
|
73 | build: 'fitbit-build',
|
74 | debug: 'fitbit',
|
75 | };
|
76 | fs_extra_1.default.writeJSONSync(packageJSONPath, packageJSON, {
|
77 | spaces: 2,
|
78 | EOL: os_1.default.EOL,
|
79 | });
|
80 | }
|
81 | exports.default = newProject;
|