@contentstack/cli-cm-seed 1.1.4 → 1.1.6
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/README.md +1 -1
- package/lib/commands/cm/stacks/seed.js +2 -0
- package/lib/seed/contentstack/client.js +2 -2
- package/lib/seed/github/client.d.ts +1 -0
- package/lib/seed/github/client.js +25 -4
- package/lib/seed/index.d.ts +2 -0
- package/lib/seed/index.js +4 -1
- package/lib/seed/interactive.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +8 -12
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ OPTIONS
|
|
|
26
26
|
-o, --org=org Provide Organization UID to create a new stack
|
|
27
27
|
-r, --repo=repo GitHub account or GitHub account/repository
|
|
28
28
|
-s, --stack=stack Provide stack UID to seed content to
|
|
29
|
-
-y, --yes=yes
|
|
29
|
+
-y, --yes=yes [Optional] Skip stack confirmation
|
|
30
30
|
|
|
31
31
|
ALIASES
|
|
32
32
|
$ csdx cm:seed
|
|
@@ -14,6 +14,7 @@ class SeedCommand extends cli_command_1.Command {
|
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
const options = {
|
|
17
|
+
parent: this,
|
|
17
18
|
cdaHost: this.cdaHost,
|
|
18
19
|
cmaHost: this.cmaHost,
|
|
19
20
|
authToken: this.authToken,
|
|
@@ -84,6 +85,7 @@ SeedCommand.flags = {
|
|
|
84
85
|
yes: cli_command_1.flags.string({
|
|
85
86
|
char: 'y',
|
|
86
87
|
required: false,
|
|
88
|
+
description: '[Optional] Skip stack confirmation',
|
|
87
89
|
}),
|
|
88
90
|
//To be deprecated
|
|
89
91
|
stack: cli_command_1.flags.string({
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const axios = require('axios');
|
|
4
4
|
const error_1 = require("./error");
|
|
5
5
|
class ContentstackClient {
|
|
6
6
|
constructor(cmaHost, authToken, limit) {
|
|
7
|
-
this.instance =
|
|
7
|
+
this.instance = axios.create({
|
|
8
8
|
baseURL: `https://${cmaHost}/v3/`,
|
|
9
9
|
headers: {
|
|
10
10
|
authtoken: authToken,
|
|
@@ -12,6 +12,7 @@ export default class GitHubClient {
|
|
|
12
12
|
constructor(username: string, defaultStackPattern: string);
|
|
13
13
|
getAllRepos(count?: number): Promise<any>;
|
|
14
14
|
getLatest(repo: string, destination: string): Promise<void>;
|
|
15
|
+
makeHeadApiCall(repo: string): Promise<any>;
|
|
15
16
|
checkIfRepoExists(repo: string): Promise<boolean>;
|
|
16
17
|
getLatestTarballUrl(repo: string): Promise<any>;
|
|
17
18
|
streamRelease(url: string): Promise<Stream>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
4
|
-
const zlib = require("zlib");
|
|
5
3
|
const tar = require("tar");
|
|
4
|
+
const zlib = require("zlib");
|
|
5
|
+
const https = require("https");
|
|
6
6
|
const mkdirp = require("mkdirp");
|
|
7
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
7
8
|
const error_1 = require("./error");
|
|
8
9
|
class GitHubClient {
|
|
9
10
|
static parsePath(path) {
|
|
@@ -41,12 +42,32 @@ class GitHubClient {
|
|
|
41
42
|
await mkdirp(destination);
|
|
42
43
|
return this.extract(destination, releaseStream);
|
|
43
44
|
}
|
|
45
|
+
makeHeadApiCall(repo) {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const { host, pathname } = new URL(this.gitHubRepoUrl);
|
|
48
|
+
const options = {
|
|
49
|
+
host,
|
|
50
|
+
method: 'HEAD',
|
|
51
|
+
path: `${pathname}/${repo}/contents`,
|
|
52
|
+
headers: { 'user-agent': 'node.js' },
|
|
53
|
+
};
|
|
54
|
+
https.request(options, resolve).on('error', reject).end();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
44
57
|
async checkIfRepoExists(repo) {
|
|
45
58
|
try {
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Old code. Keeping it for reference.
|
|
61
|
+
*
|
|
62
|
+
* `const response: any = await this.httpClient.send('HEAD', `${this.gitHubRepoUrl}/${repo}/contents`);`
|
|
63
|
+
*
|
|
64
|
+
* `return response.status === 200;`
|
|
65
|
+
*/
|
|
66
|
+
const response = await this.makeHeadApiCall(repo);
|
|
67
|
+
return response.statusCode === 200;
|
|
48
68
|
}
|
|
49
69
|
catch (error) {
|
|
70
|
+
console.log(error);
|
|
50
71
|
// do nothing
|
|
51
72
|
}
|
|
52
73
|
return false;
|
package/lib/seed/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Organization } from '../seed/contentstack/client';
|
|
|
2
2
|
import { InquireStackResponse } from '../seed/interactive';
|
|
3
3
|
export declare const ENGLISH_LOCALE = "en-us";
|
|
4
4
|
export interface ContentModelSeederOptions {
|
|
5
|
+
parent?: any;
|
|
5
6
|
cdaHost: string;
|
|
6
7
|
cmaHost: string;
|
|
7
8
|
authToken: string;
|
|
@@ -14,6 +15,7 @@ export interface ContentModelSeederOptions {
|
|
|
14
15
|
}
|
|
15
16
|
export default class ContentModelSeeder {
|
|
16
17
|
options: ContentModelSeederOptions;
|
|
18
|
+
private readonly parent;
|
|
17
19
|
private readonly csClient;
|
|
18
20
|
private readonly ghClient;
|
|
19
21
|
private readonly _options;
|
package/lib/seed/index.js
CHANGED
|
@@ -17,7 +17,9 @@ class ContentModelSeeder {
|
|
|
17
17
|
}
|
|
18
18
|
constructor(options) {
|
|
19
19
|
this.options = options;
|
|
20
|
+
this.parent = null;
|
|
20
21
|
this.ghUsername = DEFAULT_OWNER;
|
|
22
|
+
this.parent = options.parent || null;
|
|
21
23
|
this._options = options;
|
|
22
24
|
const gh = client_2.default.parsePath(options.gitHubPath);
|
|
23
25
|
this.ghUsername = gh.username || DEFAULT_OWNER;
|
|
@@ -59,6 +61,8 @@ class ContentModelSeeder {
|
|
|
59
61
|
const repoExists = await this.ghClient.checkIfRepoExists(this.ghRepo);
|
|
60
62
|
if (repoExists === false) {
|
|
61
63
|
cli_utilities_1.cliux.error(`Could not find GitHub repository '${this.ghPath}'.`);
|
|
64
|
+
if (this.parent)
|
|
65
|
+
this.parent.exit(1);
|
|
62
66
|
}
|
|
63
67
|
else {
|
|
64
68
|
let organizationResponse;
|
|
@@ -91,7 +95,6 @@ class ContentModelSeeder {
|
|
|
91
95
|
}
|
|
92
96
|
async createStack(organization, stackName) {
|
|
93
97
|
cli_utilities_1.cliux.loader(`Creating Stack '${stackName}' within Organization '${organization.name}'`);
|
|
94
|
-
this.options.fetchLimit;
|
|
95
98
|
const newStack = await this.csClient.createStack({
|
|
96
99
|
name: stackName,
|
|
97
100
|
description: '',
|
package/lib/seed/interactive.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.inquireStack = exports.inquireProceed = exports.inquireOrganization = exports.inquireRepo = void 0;
|
|
4
|
-
const inquirer = require(
|
|
4
|
+
const inquirer = require('inquirer');
|
|
5
5
|
async function inquireRepo(repos) {
|
|
6
6
|
if (!repos || repos.length === 0)
|
|
7
7
|
throw new Error('Precondition failed: No Repositories found.');
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.1.
|
|
1
|
+
{"version":"1.1.6","commands":{"cm:stacks:seed":{"id":"cm:stacks:seed","description":"Create a stack from existing content types, entries, assets, etc","usage":"cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]","pluginName":"@contentstack/cli-cm-seed","pluginType":"core","aliases":["cm:seed"],"examples":["$ csdx cm:stacks:seed","$ csdx cm:stacks:seed --repo \"account\"","$ csdx cm:stacks:seed --repo \"account/repository\"","$ csdx cm:stacks:seed --repo \"account/repository\" --stack-api-key \"stack-api-key\" //seed content into specific stack","$ csdx cm:stacks:seed --repo \"account/repository\" --org \"your-org-uid\" --stack-name \"stack-name\" //create a new stack in given org uid"],"flags":{"repo":{"name":"repo","type":"option","char":"r","description":"GitHub account or GitHub account/repository","required":false},"org":{"name":"org","type":"option","char":"o","description":"Provide Organization UID to create a new stack","required":false},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"Provide stack api key to seed content to","required":false},"stack-name":{"name":"stack-name","type":"option","char":"n","description":"Name of a new stack that needs to be created.","required":false},"fetch-limit":{"name":"fetch-limit","type":"option","char":"l","description":"Limit for number of Organizations or stacks to be fetched","hidden":true,"required":false},"yes":{"name":"yes","type":"option","char":"y","description":"[Optional] Skip stack confirmation","required":false},"stack":{"name":"stack","type":"option","char":"s","description":"Provide stack UID to seed content to","required":false}},"args":[]}}}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-seed",
|
|
3
3
|
"description": "create a Stack from existing content types, entries, assets, etc.",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.6",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-cm-import": "^1.2.
|
|
9
|
-
"@contentstack/cli-command": "^1.0.
|
|
10
|
-
"@contentstack/cli-utilities": "^1.0.
|
|
8
|
+
"@contentstack/cli-cm-import": "^1.2.4",
|
|
9
|
+
"@contentstack/cli-command": "^1.0.4",
|
|
10
|
+
"@contentstack/cli-utilities": "^1.0.5",
|
|
11
11
|
"@oclif/command": "^1.8.16",
|
|
12
12
|
"@oclif/config": "^1.18.3",
|
|
13
|
-
"axios": "
|
|
14
|
-
"inquirer": "
|
|
13
|
+
"axios": "1.1.3",
|
|
14
|
+
"inquirer": "8.2.4",
|
|
15
15
|
"mkdirp": "^1.0.4",
|
|
16
16
|
"tar": "^6.0.5",
|
|
17
17
|
"tmp": "^0.2.1",
|
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@oclif/dev-cli": "^1.22.2",
|
|
22
|
-
"@
|
|
23
|
-
"@types/inquirer": "^7.3.1",
|
|
22
|
+
"@types/inquirer": "^9.0.3",
|
|
24
23
|
"@types/jest": "^26.0.15",
|
|
25
24
|
"@types/mkdirp": "^1.0.1",
|
|
26
25
|
"@types/node": "^14.14.32",
|
|
@@ -33,7 +32,7 @@
|
|
|
33
32
|
"jest": "^26.6.1",
|
|
34
33
|
"ts-jest": "^26.4.2",
|
|
35
34
|
"ts-node": "^8.10.2",
|
|
36
|
-
"typescript": "^4.
|
|
35
|
+
"typescript": "^4.9.3"
|
|
37
36
|
},
|
|
38
37
|
"engines": {
|
|
39
38
|
"node": ">=8.0.0"
|
|
@@ -53,9 +52,6 @@
|
|
|
53
52
|
"oclif": {
|
|
54
53
|
"commands": "./lib/commands",
|
|
55
54
|
"bin": "csdx",
|
|
56
|
-
"devPlugins": [
|
|
57
|
-
"@oclif/plugin-help"
|
|
58
|
-
],
|
|
59
55
|
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-seed/<%- commandPath %>"
|
|
60
56
|
},
|
|
61
57
|
"csdxConfig": {
|