Skip to content

Commit 76ec420

Browse files
author
hitesh.baldaniya
committed
Initial setup of Built.io Contentstack - Utilty Tools
0 parents  commit 76ec420

File tree

14 files changed

+2422
-0
lines changed

14 files changed

+2422
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.git/*
2+
.idea*/
3+
node_modules/

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 built.io
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
[![Built.io Contentstack](https://contentstackdocs.built.io/static/images/logo.png)](https://www.built.io/products/contentstack/overview)
2+
3+
# Built.io Contentstack Command Line Interface(CLI).
4+
5+
## Installation
6+
7+
Run the following command in a Terminal or Command Prompt to globally install the latest version of Built.io Contentstack CLI on your system:
8+
9+
```bash
10+
$ npm install -g contentstack-cli
11+
```
12+
*You might need administrator privileges to perform this installation.*
13+
14+
## Commands in CLI
15+
16+
Built.io Contentstack CLI comes with handy commands which helps to achieve the support work for the contentstack-express like publishing, unpublishing, synchronizing the data, connecting existing stacks etc.
17+
18+
```
19+
20+
**
21+
***
22+
****
23+
***** ** .----------------------------------.
24+
**** *** | Built.io Contentstack! |
25+
*** **** '----------------------------------'
26+
** *****
27+
****
28+
***
29+
**
30+
31+
Built.io Contentstack Command Line Interface 1.0.2
32+
33+
Usage: contentstack [command]
34+
35+
Commands:
36+
connect Connect to an existing stack in Built.io Contentstack
37+
sync Synchronize all the published content locally
38+
publish Publish content-types/assets/both on specified environment
39+
unpublish Unpublish content-types/assets/both on specified environment
40+
plugin create Create the new plugin in the current application
41+
42+
Options:
43+
-h, --help output usage information
44+
-V, --version output the version number
45+
46+
Documentation can be found at https://contentstackdocs.built.io/
47+
```
48+
### Connect
49+
The connect command is used to connect to a existing stack. Navigate to a location on your computer and create a site development folder using the following command.
50+
```bash
51+
$ contentstack connect
52+
```
53+
You'll be guided through a step-by-step procedure to create the directory where the stack's files will be kept.
54+
55+
### Publish
56+
57+
The publish command is used to publish the content to the specified environment.
58+
59+
```
60+
$ contentstack publish
61+
```
62+
You'll be guided through a step-by-step procedure to publish content of the stack.
63+
64+
### Unpublish
65+
66+
The unpublish command is used to unpublish the content from the specified environment.
67+
68+
```
69+
$ contentstack unpublish
70+
```
71+
You'll be guided through a step-by-step procedure to unpublish content of the stack.
72+
73+
### Sync
74+
75+
The sync command is used to synchronize all the published content on your web application.
76+
77+
```
78+
$ contentstack sync
79+
```
80+
You'll be guided through a step-by-step procedure to synchronize all the content of the stack.
81+
82+
### Plugin
83+
84+
The 'plugin create' command creates the plugin with the basic structure.
85+
86+
```
87+
$ contentstack plugin create YOUR_PLUGIN_NAME
88+
```
89+
Once the plugin is created, you can activate it in config/all.js file.
90+
91+
## Links
92+
- [Website](https://www.built.io/products/contentstack/overview)
93+
- [Official Documentation](http://contentstackdocs.built.io/developer/javascript/quickstart)
94+
95+
### License
96+
Copyright © 2012-2016 [Built.io](https://www.built.io/). All Rights Reserved.

bin/index.js

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
#!/usr/bin/env node
2+
/*!
3+
* contentstack-cli
4+
* copyright (c) Built.io Contentstack
5+
* MIT Licensed
6+
*/
7+
8+
'use strict';
9+
10+
/*!
11+
* Module dependencies
12+
*/
13+
var domain = require('domain'),
14+
program = require('commander'),
15+
path = require('path'),
16+
helper = require('./../lib/helper');
17+
18+
/*
19+
* Application defined variables
20+
* */
21+
var messages = [
22+
'\t \x1b[33m**'
23+
, ' \x1b[33m***'
24+
, ' \x1b[33m****'
25+
, '\x1b[33m***** \x1b[31m** \x1b[36m.----------------------------------.'
26+
, ' \x1b[33m**** \x1b[31m*** \x1b[36m| Built.io Contentstack! |'
27+
, ' \x1b[33m*** \x1b[31m**** \x1b[36m\'----------------------------------\''
28+
, ' \x1b[33m** \x1b[31m***** '
29+
, ' \x1b[31m****'
30+
, ' \x1b[31m***'
31+
, ' \x1b[31m**'
32+
].join("\n\t"),
33+
pkg = require('./../package.json');
34+
35+
function list(val) {
36+
return ((val && val.length) ? val.split(',').map(String) : undefined);
37+
}
38+
39+
function getDefaultOptions (opts, events) {
40+
var opt = {};
41+
for(var key in events) {
42+
opt[key] = updateDefaultOption(opts, key);
43+
}
44+
return opt;
45+
}
46+
47+
function updateDefaultOption (opts, key) {
48+
if(~['content_types', 'skip_content_types'].indexOf(key) && opts[key] === true) {
49+
opts[key] = [];
50+
} else if('backup' === key && opts[key] === true) {
51+
opts[key] = 'yes';
52+
} else if('type' === key && opts[key] === true) {
53+
opts[key] = 'all';
54+
} else if('language' === key && opts[key] === true) {
55+
opts[key] = 'en-us';
56+
} else if('datetime' === key && opts[key] === true) {
57+
opts[key] = new Date('1970').toISOString();
58+
}
59+
return opts[key];
60+
}
61+
62+
function optionConversion(options) {
63+
var _options = {
64+
environment: options.env,
65+
language: options.lang
66+
};
67+
options.language = options._events.language = _options.language;
68+
options.environment = options._events.environment = _options.environment;
69+
delete options.env;
70+
delete options.lang;
71+
delete options._events.env;
72+
delete options._events.lang;
73+
return _options;
74+
}
75+
// printing the Built.io Contentstack Animation
76+
console.log('\n'+messages+'\x1b[0m\n');
77+
78+
program
79+
.version(pkg.version || "0.1.x");
80+
81+
program
82+
.command('connect [directory] [api_key] [access_token] [template]')
83+
.option('-d, --dir <directory>', 'Enter the name of "Directory"')
84+
.option('-a, --api_key <api_key>', 'Enter the stack "API KEY" to connect')
85+
.option('-c, --token <access_token>', 'Enter the "Access Token" relative to "API KEY"')
86+
.option('-t, --template [template]', 'Enter the template', 'basic')
87+
.description('Connect to an existing stack in Built.io Contentstack.')
88+
.action(function(directory, api_key, access_token, template, options) {
89+
setImmediate(function () {
90+
//creating the domain to execute in safe mode
91+
var context = domain.create();
92+
93+
// error handling in domain
94+
context.on('error', errorHandler);
95+
96+
// running the connect in domain
97+
context.run(function() {
98+
var connect = require('./../lib/connect'),
99+
args = {
100+
directory: directory || options.dir,
101+
api_key: api_key || options.api_key,
102+
access_token: access_token || options.token,
103+
template: "basic" || options.template
104+
};
105+
new connect(args);
106+
});
107+
});
108+
});
109+
110+
program
111+
.command('plugin create')
112+
.alias('plugin create')
113+
.description('Create a new plugin in the current application')
114+
.action(function (path, directory) {
115+
setImmediate(function() {
116+
var context = domain.create();
117+
118+
// error handling in domain
119+
context.on('error', errorHandler);
120+
121+
// running the plugin in domain
122+
context.run(function() {
123+
var plugin = require('./../lib/plugin');
124+
new plugin(directory);
125+
});
126+
});
127+
});
128+
129+
program
130+
.command('sync')
131+
.option('-e, --env <environment>', 'Enter the environment of which the content needs to be synchronized', undefined)
132+
.option('-l, --lang [language]', 'Enter the language of which the content needs to be synchronized', undefined)
133+
.option('-c, --content_types [content_types]', 'Enter the content types to be included in synchronization (comma(",") seperated)', list, undefined)
134+
.option('-s, --skip_content_types [skip_content_types]', 'Enter the content types to be excluded from synchronization (comma(",") seperated)', list, undefined)
135+
.option('-d, --datetime [datetime]', 'Enter start date in ISO String format. Content published after this date will be synchronized (skip for all content)', undefined)
136+
.option('-b, --backup [backup]', 'Enter backup option', /(yes|no|y|n)/i, undefined)
137+
.description('Synchronize the previously published entries in the current application')
138+
.action(function (options) {
139+
setImmediate(function() {
140+
var context = domain.create();
141+
142+
// error handling in domain
143+
context.on('error', errorHandler);
144+
145+
// running the synchronization in domain
146+
context.run(function() {
147+
var _options = optionConversion(options);
148+
console.error(_options);
149+
_options = helper.merge(getDefaultOptions(options, options._events), _options);
150+
console.error(_options);
151+
var sync = require('./../lib/sync');
152+
new sync(_options);
153+
});
154+
});
155+
});
156+
157+
/*
158+
* command for bulk publish
159+
* */
160+
161+
program
162+
.command('publish')
163+
.alias('bulk-publish')
164+
.option('-u, --username <username>', 'Email id registered on Built.io Contentstack', undefined)
165+
.option('-p, --password <password>', 'Password', undefined)
166+
.option('-e, --env <environment>', 'Environment/s where you want to publish (comma(",") seperated)', list, undefined)
167+
.option('-b, --backup [backup]', 'Enter backup option', /(yes|no|y|n)/i, undefined)
168+
.option('-t, --type [type]', 'Enter a type of content to include in publishing [content_types/assets/all]', /(content_types|assets|all)/, undefined)
169+
.option('-c, --content_types [content_types]', 'Enter the content types to be included (comma(",") seperated)', list, undefined)
170+
.option('-s, --skip_content_types [skip_content_types]', 'Enter the content types to be excluded (comma(",") seperated)', list, undefined)
171+
.option('-l, --lang [language]', 'Enter the language where content should be published', undefined)
172+
.description('Publish content-types/assets/both on specified environment/s')
173+
.action(function (options) {
174+
setImmediate(function() {
175+
var context = domain.create();
176+
177+
// error handling in domain
178+
context.on('error', errorHandler);
179+
// running the synchronization in domain
180+
context.run(function() {
181+
var _options = optionConversion(options);
182+
_options = helper.merge(getDefaultOptions(options, options._events), _options);
183+
var publish = require('./../lib/publish');
184+
new publish('publish', _options);
185+
});
186+
});
187+
});
188+
189+
/*
190+
* command for bulk unpublish
191+
* */
192+
193+
program
194+
.command('unpublish')
195+
.alias('bulk-unpublish')
196+
.option('-u, --username <username>', 'Email id registered on Built.io Contentstack', undefined)
197+
.option('-p, --password <password>', 'Password', undefined)
198+
.option('-e, --env <environment>', 'Environment/s where you want to unpublish (comma(",") seperated)', list, undefined)
199+
.option('-b, --backup [backup]', 'Enter backup option', /(yes|no|y|n)/i, undefined)
200+
.option('-t, --type [type]', 'Enter a type of content to include in unpublishing [content_types/assets/all]', /(content_types|assets|all)/, undefined)
201+
.option('-c, --content_types [content_types]', 'Enter the content types to be included (comma(",") seperated)', list, undefined)
202+
.option('-s, --skip_content_types [skip_content_types]', 'Enter the content types to be excluded (comma(",") seperated)', list, undefined)
203+
.option('-l, --lang [language]', 'Enter the language where content should be unpublished', undefined)
204+
.description('Unpublish content-types/assets/both on specified environment/s')
205+
.action(function (options) {
206+
setImmediate(function() {
207+
var context = domain.create();
208+
209+
// error handling in domain
210+
context.on('error', errorHandler);
211+
212+
// running the synchronization in domain
213+
context.run(function() {
214+
var _options = optionConversion(options);
215+
_options = helper.merge(getDefaultOptions(options, options._events), _options);
216+
var unpublish = require('./../lib/publish');
217+
new unpublish('unpublish', _options);
218+
});
219+
});
220+
});
221+
222+
// parse the input arguments
223+
program.parse(process.argv);
224+
225+
// show help by default if no args
226+
if (program.args.length == 0) {
227+
var message = [
228+
'Built.io Contentstack Command Line Interface '+pkg.version
229+
, '\nUsage: contentstack [command]'
230+
, '\nCommands:'
231+
, ' connect Connect to an existing stack in Built.io Contentstack'
232+
, ' sync Synchronize the previously published entries in the current application'
233+
, ' publish Publish content-types/assets/both on specified environment'
234+
, ' unpublish Unpublish content-types/assets/both on specified environment'
235+
, ' plugin create Create the new plugin in the current application'
236+
, '\nOptions:'
237+
, ' -h, --help output usage information'
238+
, ' -V, --version output the version number'
239+
, '\nDocumentation can be found at http://contentstackdocs.built.io/'
240+
].join('\n');
241+
console.log(message);
242+
process.exit(1);
243+
}
244+
/*
245+
* Error Handler to handle the domain level error
246+
* */
247+
function errorHandler(err) {
248+
console.error(err.message);
249+
}
250+
251+
process.on('uncaughtException', function(err) {
252+
console.error('Caught exception: ', err.message);
253+
process.exit(0);
254+
});

0 commit comments

Comments
 (0)