@swell/cli 2.0.1-alpha.16 → 2.0.1-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-command.d.ts +1 -1
- package/dist/app-command.js +8 -8
- package/dist/commands/app/dev.d.ts +18 -0
- package/dist/commands/app/dev.js +31 -0
- package/dist/commands/app/frontend/deploy.d.ts +17 -0
- package/dist/commands/app/frontend/deploy.js +44 -0
- package/dist/commands/app/frontend/dev.d.ts +21 -0
- package/dist/commands/app/frontend/dev.js +111 -0
- package/dist/commands/app/info.js +15 -8
- package/dist/commands/app/init.d.ts +12 -0
- package/dist/commands/app/init.js +34 -0
- package/dist/commands/app/install.d.ts +0 -3
- package/dist/commands/app/install.js +12 -20
- package/dist/commands/app/pull.d.ts +15 -0
- package/dist/commands/app/pull.js +50 -0
- package/dist/commands/app/push.d.ts +10 -13
- package/dist/commands/app/push.js +64 -135
- package/dist/commands/app/release.d.ts +13 -0
- package/dist/commands/app/release.js +150 -0
- package/dist/commands/app/version.d.ts +7 -6
- package/dist/commands/app/version.js +61 -40
- package/dist/commands/app/watch.d.ts +2 -4
- package/dist/commands/app/watch.js +3 -83
- package/dist/commands/create/app.d.ts +35 -11
- package/dist/commands/create/app.js +141 -138
- package/dist/commands/create/frontend.d.ts +12 -0
- package/dist/commands/create/frontend.js +41 -0
- package/dist/commands/create/function.d.ts +2 -2
- package/dist/commands/create/function.js +2 -2
- package/dist/commands/create/notification.d.ts +2 -2
- package/dist/commands/create/notification.js +2 -2
- package/dist/commands/login.js +6 -4
- package/dist/commands/logs.js +0 -1
- package/dist/commands/theme/dev.d.ts +23 -0
- package/dist/commands/theme/dev.js +167 -0
- package/dist/commands/theme/init.d.ts +9 -0
- package/dist/commands/theme/init.js +15 -0
- package/dist/commands/theme/pull.d.ts +20 -0
- package/dist/commands/theme/pull.js +65 -0
- package/dist/commands/theme/push.d.ts +19 -0
- package/dist/commands/theme/push.js +92 -0
- package/dist/create-app-command.d.ts +20 -0
- package/dist/create-app-command.js +254 -0
- package/dist/create-collection-command.d.ts +3 -3
- package/dist/create-collection-command.js +4 -4
- package/dist/{create-command.d.ts → create-config-command.d.ts} +1 -1
- package/dist/{create-command.js → create-config-command.js} +3 -3
- package/dist/lib/api.d.ts +3 -2
- package/dist/lib/api.js +47 -21
- package/dist/lib/app-config.d.ts +12 -5
- package/dist/lib/app-config.js +59 -24
- package/dist/lib/apps/app-config.d.ts +22 -8
- package/dist/lib/apps/app-config.js +202 -68
- package/dist/lib/apps/index.d.ts +93 -13
- package/dist/lib/apps/index.js +150 -50
- package/dist/lib/apps/paths.d.ts +14 -7
- package/dist/lib/apps/paths.js +73 -28
- package/dist/lib/config.d.ts +5 -1
- package/dist/lib/config.js +14 -0
- package/dist/lib/constants.d.ts +5 -0
- package/dist/lib/constants.js +20 -0
- package/dist/lib/create/content.d.ts +1 -1
- package/dist/lib/create/index.js +5 -1
- package/dist/lib/info.js +2 -2
- package/dist/lib/stores.d.ts +1 -1
- package/dist/lib/stores.js +3 -3
- package/dist/lib/style.d.ts +2 -0
- package/dist/lib/style.js +2 -0
- package/dist/push-app-command.d.ts +73 -0
- package/dist/push-app-command.js +765 -0
- package/dist/remote-app-command.d.ts +33 -7
- package/dist/remote-app-command.js +423 -151
- package/oclif.manifest.json +794 -81
- package/package.json +13 -2
- package/dist/commands/app/_pull.d.ts +0 -8
- package/dist/commands/app/_pull.js +0 -45
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateConfigCommand } from './create-config-command.js';
|
|
2
2
|
/**
|
|
3
3
|
* A base class for Swell CLI Create [content|models] command input.
|
|
4
4
|
*
|
|
5
|
-
* This class extends the `
|
|
5
|
+
* This class extends the `CreateConfigCommand` class and adds:
|
|
6
6
|
*
|
|
7
7
|
* - promptCollection: Get collection name and description
|
|
8
8
|
*/
|
|
9
|
-
export declare abstract class CreateCollectionCommand extends
|
|
9
|
+
export declare abstract class CreateCollectionCommand extends CreateConfigCommand {
|
|
10
10
|
static args: {
|
|
11
11
|
collection: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
|
|
12
12
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Separator, input, select } from '@inquirer/prompts';
|
|
2
2
|
import { Args, Flags } from '@oclif/core';
|
|
3
|
-
import {
|
|
3
|
+
import { CreateConfigCommand } from './create-config-command.js';
|
|
4
4
|
import { toCollectionLabel, toCollectionName } from './lib/create/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* A base class for Swell CLI Create [content|models] command input.
|
|
7
7
|
*
|
|
8
|
-
* This class extends the `
|
|
8
|
+
* This class extends the `CreateConfigCommand` class and adds:
|
|
9
9
|
*
|
|
10
10
|
* - promptCollection: Get collection name and description
|
|
11
11
|
*/
|
|
12
|
-
export class CreateCollectionCommand extends
|
|
12
|
+
export class CreateCollectionCommand extends CreateConfigCommand {
|
|
13
13
|
// base flags for all AppCommands
|
|
14
14
|
static args = {
|
|
15
15
|
collection: Args.string({
|
|
@@ -20,7 +20,7 @@ export class CreateCollectionCommand extends CreateCommand {
|
|
|
20
20
|
// needs to be in a ES2021 format: https://github.com/oclif/oclif/issues/1100
|
|
21
21
|
static baseFlags = {
|
|
22
22
|
'app-path': Flags.string({
|
|
23
|
-
description: 'path to
|
|
23
|
+
description: 'path to your app directory',
|
|
24
24
|
}),
|
|
25
25
|
};
|
|
26
26
|
static flags = {
|
|
@@ -9,7 +9,7 @@ import { CreateFileParams } from './lib/create/index.js';
|
|
|
9
9
|
* - createType: Type of Config to generate file path
|
|
10
10
|
* - createFile: File creation, including general prompts
|
|
11
11
|
*/
|
|
12
|
-
export declare abstract class
|
|
12
|
+
export declare abstract class CreateConfigCommand extends AppCommand {
|
|
13
13
|
protected createType: '' | ConfigType;
|
|
14
14
|
protected createFile({ extension, fileBody, fileName }: CreateFileParams, overwrite: boolean, shouldConfirm?: boolean): Promise<boolean | undefined>;
|
|
15
15
|
protected getCollectionOptions(): Promise<any>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { confirm } from '@inquirer/prompts';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { AppCommand } from './app-command.js';
|
|
4
|
-
import { ConfigPaths,
|
|
4
|
+
import { ConfigPaths, filePathExists, writeFile, writeJsonFile, } from './lib/apps/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* A base class for Swell CLI Create commands for file and input handling.
|
|
7
7
|
*
|
|
@@ -10,7 +10,7 @@ import { ConfigPaths, fileExists, writeFile, writeJsonFile, } from './lib/apps/i
|
|
|
10
10
|
* - createType: Type of Config to generate file path
|
|
11
11
|
* - createFile: File creation, including general prompts
|
|
12
12
|
*/
|
|
13
|
-
export class
|
|
13
|
+
export class CreateConfigCommand extends AppCommand {
|
|
14
14
|
createType = '';
|
|
15
15
|
async createFile({ extension = 'json', fileBody, fileName }, overwrite, shouldConfirm = true) {
|
|
16
16
|
const isJson = extension === 'json';
|
|
@@ -18,7 +18,7 @@ export class CreateCommand extends AppCommand {
|
|
|
18
18
|
if (shouldConfirm) {
|
|
19
19
|
this.log(`\nCreating app ${this.createType} in ${filePath}`);
|
|
20
20
|
this.log(`\n${isJson ? JSON.stringify(fileBody, null, 4) : fileBody}\n`);
|
|
21
|
-
if (
|
|
21
|
+
if (filePathExists(filePath) && !overwrite) {
|
|
22
22
|
const continueWrite = await confirm({
|
|
23
23
|
message: `This will overwrite an existing ${this.createType} file. Ok to continue?`,
|
|
24
24
|
});
|
package/dist/lib/api.d.ts
CHANGED
|
@@ -4,11 +4,12 @@ export default class Api {
|
|
|
4
4
|
private storeId;
|
|
5
5
|
constructor(storeId?: string, envId?: string, secretKey?: string);
|
|
6
6
|
api(pathOpts: Api.Paths, options: Api.RequestOptions): Promise<any>;
|
|
7
|
-
delete(pathOpts: Api.Paths, options?: Api.RequestOptions): Promise<any>;
|
|
8
|
-
get(pathOpts: Api.Paths, options?: Api.RequestOptions): Promise<any>;
|
|
9
7
|
isAdmin(): boolean;
|
|
8
|
+
waitForAsyncResponse(response: any, pathOpts: Api.Paths, options?: Api.RequestOptions): Promise<any>;
|
|
9
|
+
get(pathOpts: Api.Paths, options?: Api.RequestOptions): Promise<any>;
|
|
10
10
|
post(pathOpts: Api.Paths, options?: Api.RequestOptions): Promise<any>;
|
|
11
11
|
put(pathOpts: Api.Paths, options?: Api.RequestOptions): Promise<any>;
|
|
12
|
+
delete(pathOpts: Api.Paths, options?: Api.RequestOptions): Promise<any>;
|
|
12
13
|
setStoreEnv(storeId: string, envId?: string): void;
|
|
13
14
|
truncatePath(path: string | undefined): string | undefined;
|
|
14
15
|
}
|
package/dist/lib/api.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
|
+
import qs from 'qs';
|
|
2
3
|
import config from './config.js';
|
|
3
4
|
import { API_BASE_URL, getAdminApiBaseUrl } from './constants.js';
|
|
4
5
|
const defaultHeaders = (opts) => ({
|
|
@@ -50,8 +51,7 @@ export default class Api {
|
|
|
50
51
|
? `${getAdminApiBaseUrl(storeId)}/${this.truncatePath(pathOpts.adminPath)}`
|
|
51
52
|
: `${API_BASE_URL}/${this.truncatePath(pathOpts.backendPath)}`;
|
|
52
53
|
if (options.query) {
|
|
53
|
-
|
|
54
|
-
path += `?${query.toString()}`;
|
|
54
|
+
path += `?${qs.stringify(options.query)}`;
|
|
55
55
|
}
|
|
56
56
|
path = path
|
|
57
57
|
// eslint-disable-next-line no-template-curly-in-string
|
|
@@ -59,38 +59,55 @@ export default class Api {
|
|
|
59
59
|
.replaceAll(/([^:]\/)\/+/g, '$1'); // remove duplicate slashes
|
|
60
60
|
if (!path)
|
|
61
61
|
throw new Error('Operation not supported.');
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
if (!
|
|
62
|
+
const res = await fetch(path, fetchOptions);
|
|
63
|
+
const resData = await res.text();
|
|
64
|
+
if (!res.ok) {
|
|
65
65
|
// Try to parse error message
|
|
66
66
|
let errorJson;
|
|
67
67
|
try {
|
|
68
|
-
errorJson = JSON.parse(
|
|
68
|
+
errorJson = JSON.parse(resData);
|
|
69
69
|
}
|
|
70
70
|
catch {
|
|
71
71
|
// ignore
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
const error = new Error(errorJson?.error?.message || errorJson?.error || resData);
|
|
74
|
+
error.status = res.status;
|
|
75
|
+
throw error;
|
|
74
76
|
}
|
|
75
77
|
try {
|
|
76
|
-
return JSON.parse(
|
|
78
|
+
return JSON.parse(resData);
|
|
77
79
|
}
|
|
78
80
|
catch (error) {
|
|
79
81
|
// respData could be "{}" (length: >=2) but it shouldn't be "{", " " (whitespace - length: 1) or
|
|
80
82
|
// "" (empty response - length: 0) while logging the error.
|
|
81
|
-
if (
|
|
83
|
+
if (resData.length >= 2)
|
|
82
84
|
console.log(error);
|
|
83
85
|
return null;
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
isAdmin() {
|
|
89
|
+
return !this.secretKey;
|
|
90
|
+
}
|
|
91
|
+
async waitForAsyncResponse(response, pathOpts, options = {}) {
|
|
92
|
+
const { onAsyncGetPath, spinner } = options;
|
|
93
|
+
if (!response?.async_progressing || !onAsyncGetPath) {
|
|
94
|
+
return response;
|
|
95
|
+
}
|
|
96
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
97
|
+
const asyncResponse = await this.api(onAsyncGetPath(response), {
|
|
98
|
+
method: 'GET',
|
|
99
|
+
onAsyncGetPath,
|
|
93
100
|
});
|
|
101
|
+
if (asyncResponse?.async_error) {
|
|
102
|
+
throw new Error(asyncResponse.async_error);
|
|
103
|
+
}
|
|
104
|
+
if (!asyncResponse?.async_progressing && spinner) {
|
|
105
|
+
spinner.suffixText = '';
|
|
106
|
+
}
|
|
107
|
+
else if (asyncResponse?.async_progress > 0 && spinner) {
|
|
108
|
+
spinner.suffixText = `${asyncResponse.async_progress}%`;
|
|
109
|
+
}
|
|
110
|
+
return this.waitForAsyncResponse(asyncResponse, pathOpts, options);
|
|
94
111
|
}
|
|
95
112
|
async get(pathOpts, options = {}) {
|
|
96
113
|
return this.api(pathOpts, {
|
|
@@ -98,26 +115,35 @@ export default class Api {
|
|
|
98
115
|
...options,
|
|
99
116
|
});
|
|
100
117
|
}
|
|
101
|
-
isAdmin() {
|
|
102
|
-
return !this.secretKey;
|
|
103
|
-
}
|
|
104
118
|
async post(pathOpts, options = {}) {
|
|
105
119
|
// ensure post body is stringified
|
|
106
120
|
if (options.body)
|
|
107
121
|
options.body = JSON.stringify(options.body);
|
|
108
|
-
|
|
122
|
+
const response = await this.api(pathOpts, {
|
|
109
123
|
method: 'POST',
|
|
110
124
|
...options,
|
|
111
125
|
});
|
|
126
|
+
return this.waitForAsyncResponse(response, pathOpts, options);
|
|
112
127
|
}
|
|
113
128
|
async put(pathOpts, options = {}) {
|
|
114
129
|
// ensure post body is stringified
|
|
115
130
|
if (options.body)
|
|
116
131
|
options.body = JSON.stringify(options.body);
|
|
117
|
-
|
|
132
|
+
const response = await this.api(pathOpts, {
|
|
118
133
|
method: 'PUT',
|
|
119
134
|
...options,
|
|
120
135
|
});
|
|
136
|
+
return this.waitForAsyncResponse(response, pathOpts, options);
|
|
137
|
+
}
|
|
138
|
+
async delete(pathOpts, options = {}) {
|
|
139
|
+
// ensure post body is stringified
|
|
140
|
+
if (options.body)
|
|
141
|
+
options.body = JSON.stringify(options.body);
|
|
142
|
+
const response = await this.api(pathOpts, {
|
|
143
|
+
method: 'DELETE',
|
|
144
|
+
...options,
|
|
145
|
+
});
|
|
146
|
+
return this.waitForAsyncResponse(response, pathOpts, options);
|
|
121
147
|
}
|
|
122
148
|
setStoreEnv(storeId, envId) {
|
|
123
149
|
this.storeId = storeId;
|
package/dist/lib/app-config.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { App } from './apps';
|
|
2
2
|
/**
|
|
3
|
-
* Checks if the
|
|
3
|
+
* Checks if the swell config file exists at the given path, default to cwd.
|
|
4
4
|
*
|
|
5
5
|
* @param configFilePath - the path to the app config file
|
|
6
6
|
* @returns boolean
|
|
7
7
|
* @throws Error
|
|
8
8
|
*/
|
|
9
|
-
declare function
|
|
9
|
+
declare function swellConfigFileExists(configFilePath?: string): boolean;
|
|
10
10
|
declare function writeRcFile(path: string, data: any): Promise<void>;
|
|
11
11
|
declare function readRcFile(path: string): App;
|
|
12
12
|
/**
|
|
13
13
|
* Returns a new configuration instance in the current working directory or
|
|
14
14
|
* a parent directory.
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
16
|
+
* @param configDir - the path to the app config directory. If not provided,
|
|
17
17
|
* the config file will be searched for in the current working directory or
|
|
18
18
|
* a parent directory.
|
|
19
19
|
*
|
|
20
20
|
* @returns Conf
|
|
21
21
|
*/
|
|
22
|
-
declare function config(
|
|
22
|
+
declare function config(configDir?: string): LocalApp;
|
|
23
23
|
/**
|
|
24
24
|
* Returns a new configuration instance in the current working directory only.
|
|
25
25
|
*
|
|
@@ -27,4 +27,11 @@ declare function config(configDirPath?: string): LocalApp;
|
|
|
27
27
|
* @returns Conf
|
|
28
28
|
*/
|
|
29
29
|
declare function newConfig(path?: string): any;
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Returns a new configuration instance at the specified path.
|
|
32
|
+
*
|
|
33
|
+
* @param path Path of the current working directory
|
|
34
|
+
* @returns Conf
|
|
35
|
+
*/
|
|
36
|
+
declare function newConfigAtPath(appPath?: string): any;
|
|
37
|
+
export { swellConfigFileExists, config as default, newConfig, newConfigAtPath, readRcFile, writeRcFile, };
|
package/dist/lib/app-config.js
CHANGED
|
@@ -5,13 +5,15 @@ import Conf from 'conf';
|
|
|
5
5
|
import * as fs from 'node:fs';
|
|
6
6
|
import * as path from 'node:path';
|
|
7
7
|
const schema = {
|
|
8
|
-
description: { type: 'string' },
|
|
9
8
|
id: { type: 'string' },
|
|
10
|
-
integrations: { type: 'array' },
|
|
11
9
|
name: { type: 'string' },
|
|
12
|
-
permissions: { type: 'array' },
|
|
13
10
|
type: { type: 'string' },
|
|
14
11
|
version: { type: 'string' },
|
|
12
|
+
description: { type: 'string' },
|
|
13
|
+
storefront: { type: 'object' },
|
|
14
|
+
theme: { type: 'object' },
|
|
15
|
+
compatibilities: { type: 'object' },
|
|
16
|
+
permissions: { type: 'array' },
|
|
15
17
|
};
|
|
16
18
|
const APP_FILE_NAME = 'swell';
|
|
17
19
|
const APP_FILE_EXT = 'json';
|
|
@@ -22,23 +24,23 @@ const APP_FILE_EXT = 'json';
|
|
|
22
24
|
* @param dir - the directory to use for the config file path
|
|
23
25
|
* @returns string
|
|
24
26
|
*/
|
|
25
|
-
function
|
|
27
|
+
function swellConfigFile(dir = '') {
|
|
26
28
|
if (!dir) {
|
|
27
29
|
dir = process.cwd();
|
|
28
30
|
}
|
|
29
31
|
return path.join(dir, [APP_FILE_NAME, '.', APP_FILE_EXT].join(''));
|
|
30
32
|
}
|
|
31
33
|
/**
|
|
32
|
-
* Checks if the
|
|
34
|
+
* Checks if the swell config file exists at the given path, default to cwd.
|
|
33
35
|
*
|
|
34
36
|
* @param configFilePath - the path to the app config file
|
|
35
37
|
* @returns boolean
|
|
36
38
|
* @throws Error
|
|
37
39
|
*/
|
|
38
|
-
function
|
|
40
|
+
function swellConfigFileExists(configFilePath = '') {
|
|
39
41
|
// if the config file path is not provided, try to find it as the default
|
|
40
42
|
if (!configFilePath) {
|
|
41
|
-
configFilePath =
|
|
43
|
+
configFilePath = swellConfigFile();
|
|
42
44
|
}
|
|
43
45
|
try {
|
|
44
46
|
// eslint-disable-next-line no-bitwise
|
|
@@ -60,9 +62,9 @@ function appConfigFileExists(configFilePath = '') {
|
|
|
60
62
|
* @returns string
|
|
61
63
|
* @throws Error
|
|
62
64
|
*/
|
|
63
|
-
function
|
|
64
|
-
const configFilePath =
|
|
65
|
-
if (
|
|
65
|
+
function swellConfigFilePath(dir = '') {
|
|
66
|
+
const configFilePath = swellConfigFile(dir);
|
|
67
|
+
if (swellConfigFileExists(configFilePath)) {
|
|
66
68
|
return configFilePath;
|
|
67
69
|
}
|
|
68
70
|
// if the file doesn't exist, try to find it in the parent directory
|
|
@@ -70,10 +72,10 @@ function appConfigFilePath(dir = '') {
|
|
|
70
72
|
if (dir && dir === path.parse(dir).root) {
|
|
71
73
|
return '';
|
|
72
74
|
}
|
|
73
|
-
return
|
|
75
|
+
return swellConfigFilePath(path.resolve(dir, '..'));
|
|
74
76
|
}
|
|
75
77
|
async function writeRcFile(path, data) {
|
|
76
|
-
let dataToWrite = '';
|
|
78
|
+
let dataToWrite = '# This file is automatically generated by the Swell CLI\n';
|
|
77
79
|
for (const [key, value] of Object.entries(data)) {
|
|
78
80
|
dataToWrite += `${key}=${value}\n`;
|
|
79
81
|
}
|
|
@@ -84,9 +86,15 @@ function readRcFile(path) {
|
|
|
84
86
|
const dataFromFile = fs.readFileSync(path, 'utf8');
|
|
85
87
|
const lines = dataFromFile.split('\n');
|
|
86
88
|
for (const line of lines) {
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
|
|
89
|
+
const cleanLine = line.trim();
|
|
90
|
+
if (cleanLine.startsWith('#')) {
|
|
91
|
+
// Ignore comments
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const [key, value] = cleanLine.trim().split('=');
|
|
95
|
+
const cleanValue = value && value.trim();
|
|
96
|
+
if (key && cleanValue) {
|
|
97
|
+
data[key] = cleanValue;
|
|
90
98
|
}
|
|
91
99
|
}
|
|
92
100
|
return data;
|
|
@@ -95,19 +103,26 @@ function readRcFile(path) {
|
|
|
95
103
|
* Returns a new configuration instance in the current working directory or
|
|
96
104
|
* a parent directory.
|
|
97
105
|
*
|
|
98
|
-
* @param
|
|
106
|
+
* @param configDir - the path to the app config directory. If not provided,
|
|
99
107
|
* the config file will be searched for in the current working directory or
|
|
100
108
|
* a parent directory.
|
|
101
109
|
*
|
|
102
110
|
* @returns Conf
|
|
103
111
|
*/
|
|
104
|
-
function config(
|
|
105
|
-
const dirPath =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
function config(configDir = '') {
|
|
113
|
+
const dirPath = configDir || path.dirname(swellConfigFilePath());
|
|
114
|
+
let config;
|
|
115
|
+
try {
|
|
116
|
+
config = new Conf({
|
|
117
|
+
configName: APP_FILE_NAME,
|
|
118
|
+
cwd: dirPath,
|
|
119
|
+
schema,
|
|
120
|
+
clearInvalidConfig: true,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
throw new Error(`Error parsing swell.json: ${err.toString()}`);
|
|
125
|
+
}
|
|
111
126
|
// for convenience, we add custom properties to the Conf object
|
|
112
127
|
// we prefix them with "sw" to avoid conflicts with Conf's properties
|
|
113
128
|
config.swDirPath = dirPath;
|
|
@@ -124,6 +139,26 @@ function newConfig(path) {
|
|
|
124
139
|
configName: APP_FILE_NAME,
|
|
125
140
|
cwd: `${process.cwd()}${path ? `/${path}` : ''}`,
|
|
126
141
|
schema,
|
|
142
|
+
serialize,
|
|
143
|
+
clearInvalidConfig: true,
|
|
127
144
|
});
|
|
128
145
|
}
|
|
129
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Returns a new configuration instance at the specified path.
|
|
148
|
+
*
|
|
149
|
+
* @param path Path of the current working directory
|
|
150
|
+
* @returns Conf
|
|
151
|
+
*/
|
|
152
|
+
function newConfigAtPath(appPath) {
|
|
153
|
+
const dirPath = appPath || path.dirname(swellConfigFilePath());
|
|
154
|
+
return new Conf({
|
|
155
|
+
configName: APP_FILE_NAME,
|
|
156
|
+
cwd: dirPath,
|
|
157
|
+
schema,
|
|
158
|
+
serialize,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function serialize(value) {
|
|
162
|
+
return JSON.stringify(value, null, 2);
|
|
163
|
+
}
|
|
164
|
+
export { swellConfigFileExists, config as default, newConfig, newConfigAtPath, readRcFile, writeRcFile, };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { ConfigType } from './index.js';
|
|
2
3
|
declare class IgnoringFileError extends Error {
|
|
3
4
|
constructor(message: string);
|
|
@@ -14,29 +15,42 @@ type AppConfigFile = {
|
|
|
14
15
|
length?: number;
|
|
15
16
|
md5?: string;
|
|
16
17
|
url?: string;
|
|
18
|
+
content_type?: string;
|
|
17
19
|
};
|
|
18
20
|
/**
|
|
19
21
|
* An app configuration as defined by the Swell API. This implies that the
|
|
20
22
|
* app & the configuration are saved to the API.
|
|
21
23
|
*/
|
|
22
24
|
declare abstract class AppConfig {
|
|
23
|
-
date_created?: string;
|
|
24
|
-
file?: AppConfigFile;
|
|
25
|
-
fileData?: string;
|
|
26
25
|
id?: string;
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
version?: string;
|
|
27
|
+
hash?: string;
|
|
28
|
+
fileHash?: string;
|
|
29
|
+
file?: AppConfigFile;
|
|
30
|
+
file_path?: string;
|
|
29
31
|
name?: string;
|
|
30
32
|
parent_id?: string;
|
|
31
33
|
slug?: string;
|
|
32
34
|
values: {
|
|
33
35
|
[key: string]: any;
|
|
34
36
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
date_created?: string;
|
|
38
|
+
date_updated?: string;
|
|
39
|
+
appConfigId?: string;
|
|
40
|
+
filePath: string;
|
|
41
|
+
appPath: string;
|
|
42
|
+
fileData?: Buffer;
|
|
43
|
+
fileContent?: string;
|
|
44
|
+
byteSize?: number;
|
|
45
|
+
mbSize?: number;
|
|
38
46
|
/** build the JSON used when making requests (usually push) to the API */
|
|
39
47
|
protected abstract preparePostData(postData: any): Promise<any>;
|
|
40
48
|
abstract type: ConfigType;
|
|
49
|
+
abstract hasValues: boolean;
|
|
50
|
+
constructor(attrs?: Partial<AppConfig>);
|
|
51
|
+
static create(attrs?: Partial<AppConfig>): AppConfig;
|
|
52
|
+
postData(): Promise<any>;
|
|
53
|
+
prepareFileData(): any;
|
|
54
|
+
isRootConfig(configDir: string): boolean;
|
|
41
55
|
}
|
|
42
56
|
export { AppConfig, FunctionProcessingError, IgnoringFileError };
|