├── .gitignore ├── LICENSE ├── README.md ├── bstudio.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *.bscomp 3 | *.bsdesign 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Zine EOOD 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bstudio - CLI for Bootstrap Studio 2 | 3 | `bstudio` is a node.js command line application which presents an interface to 4 | [Bootstrap Studio](https://bootstrapstudio.io/) through the command line. Its 5 | purpose is to automate various tasks like automatically generating Bootstrap 6 | Studio components (.bscomp files) from scripts. 7 | 8 | You need to have Bootstrap Studio running on the same computer in order to use 9 | this utility. The communication happens through a UNIX domain socket (under 10 | Linux and OS X) or through a named pipe (under Windows). 11 | 12 | ## Installation 13 | 14 | The script is available on npm. To install it: 15 | 16 | ```sh 17 | npm install -g bstudio 18 | ``` 19 | 20 | This will create a global `bstudio` command which you can call from the 21 | terminal. 22 | 23 | `bstudio` doesn't export any library functions currently, so there is no 24 | point in `require()`-ing it in node.js scripts. 25 | 26 | ## Usage 27 | 28 | The utility is structured around passing commands to Bootstrap Studio. To run 29 | it, call `bstudio` from your terminal while passing one of the available 30 | commands: 31 | 32 | ```sh 33 | bstudio [options] 34 | ``` 35 | 36 | The only command implemented right now is `create-component`, for 37 | programatically generating **.bscomp** files. More will be added in the future 38 | according to user feedback. 39 | 40 | ## Examples 41 | 42 | ### Generating .bscomp files 43 | 44 | Generating **.bscomp** files is done with the `create-component` command: 45 | 46 | ```sh 47 | bstudio create-component -i definition.json 48 | 49 | # Alternatively, omit the -i flag and pass the json through stdin: 50 | # cat definition.json | bstudio create-component 51 | ``` 52 | 53 | The resulting **.bscomp** file will be placed in the current working directory. 54 | 55 | **definition.json** is a specially structured JSON file that, as a 56 | minimum, has the following structure: 57 | 58 | ```json 59 | { 60 | "name": "My Sweet Component", 61 | "html": "

The HTML of your component.

" 62 | } 63 | ``` 64 | 65 | If you wish to add CSS, JS, fonts or images to your component, you can add 66 | these to the JSON: 67 | 68 | ```json 69 | { 70 | "name": "My Sweet Component", 71 | "framework": "4", 72 | "html": "

The HTML of your component.

", 73 | "js": [ "alert(1);" ], 74 | "css": [ ".custom { font-size:20px;color:red; }" ], 75 | "fonts": { 76 | "Open Sans": "https://fonts.googleapis.com/css?family=Open+Sans:400,700" 77 | }, 78 | "images": [ "/path/to/image.png" ] 79 | } 80 | ``` 81 | 82 | The **framework** property indicates which version of the Bootstrap framework 83 | to use. By default it is set to Bootstrap 3. 84 | 85 | You can add more values to the arrays if you wish your component to contain 86 | multiple files of that type. The **images** array should contain paths to 87 | images on your computer. If you are on Windows, this path should look like 88 | `C:\\Users\\xxxx\\picture.jpg`. 89 | 90 | ## Reporting bugs and issues 91 | 92 | To report bugs or ask for help, use our [forum](https://bootstrapstudio.io/forums/). 93 | 94 | ## License 95 | 96 | Released under the MIT license. 97 | 98 | Zine EOOD (c) 2019 -------------------------------------------------------------------------------- /bstudio.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fs = require('fs'); 4 | var net = require('net'); 5 | var os = require('os'); 6 | var path = require('path'); 7 | 8 | var argv = require('yargs') 9 | .usage('Usage: $0 [options]') 10 | .command('create-component', 'Create a Bootstrap Studio component (.bscomp)') 11 | .demand(1) 12 | .example('$0 create-component -i f.json', 'create a component out of the description in the json file') 13 | .alias('i', 'input') 14 | .nargs('i', 1) 15 | .describe('i', 'Provide a JSON definition file as input. If this option is missing, bstudio will read standard input and attempt to parse it as JSON.') 16 | .argv; 17 | 18 | 19 | if(argv.input && fs.existsSync(argv.input)){ 20 | handle(fs.readFileSync(argv.input, 'utf-8')); 21 | } 22 | else { 23 | 24 | // No file was provided. Attempt to read JSON from stdin 25 | // Read json from stdin 26 | 27 | var content = ''; 28 | 29 | process.stdin.resume(); 30 | process.stdin.on('data', function(buf) { 31 | content += buf.toString(); 32 | }); 33 | 34 | process.stdin.on('end', function() { 35 | handle(content); 36 | }); 37 | 38 | } 39 | 40 | 41 | function handle(str){ 42 | 43 | var definition = null; 44 | 45 | try { 46 | definition = JSON.parse(str); 47 | } 48 | catch(e){ 49 | console.error(e); 50 | errorAndExit('The provided JSON definition is invalid.'); 51 | } 52 | 53 | if(!definition.name){ 54 | errorAndExit('Missing component name.'); 55 | } 56 | 57 | if(!definition.html){ 58 | errorAndExit('Missing component html.'); 59 | } 60 | 61 | execute({ 62 | type: "create-component", 63 | path: process.cwd(), 64 | definition: definition 65 | }); 66 | } 67 | 68 | /*definition: { 69 | name: 'testcli', 70 | html: '
this is a test!
', 71 | css: [ 72 | '.someclass{ font-weight:bold; text-decoration:underline;}', 73 | 'div.someclass{ font-size:36px;color:red;}', 74 | ], 75 | js: ['alert(123);', 'function(){another_test();}'], 76 | fonts: { 77 | 'Open Sans': 'https://fonts.googleapis.com/css?family=Open+Sans:400,700', 78 | 'Paleo Diet': 'https://fonts.googleapis.com/css?family=Paleo:400,700' 79 | }, 80 | images: ['/home/martin/Pictures/wsj-paywall.png'] 81 | } 82 | */ 83 | 84 | function execute(command) { 85 | 86 | var socket = process.platform === 'win32' ? 87 | '\\\\.\\pipe\\bootstrapstudio-sock' : 88 | path.join(os.tmpdir(), 'bootstrapstudio.sock'); 89 | 90 | var client = net.connect({ path: socket }, function () { 91 | 92 | client.write(JSON.stringify(command)); 93 | client.end(); 94 | 95 | }).on('error', function (err) { 96 | errorAndExit('Bootstrap Studio is not running. Please start it.'); 97 | }); 98 | }; 99 | 100 | function errorAndExit(message){ 101 | console.error(message); 102 | process.exit(1); 103 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bstudio", 3 | "version": "1.0.0", 4 | "description": "Bootstrap Studio command line interface", 5 | "main": "bstudio.js", 6 | "bin": { 7 | "bstudio": "bstudio.js" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/zine-eood/bstudio.git" 15 | }, 16 | "keywords": [ 17 | "bootstrap", 18 | "studio", 19 | "command", 20 | "line" 21 | ], 22 | "author": "Zine EOOD (http://zine.bg/)", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://bootstrapstudio.io/forums/" 26 | }, 27 | "homepage": "https://github.com/zine-eood/bstudio#readme", 28 | "dependencies": { 29 | "yargs": "^4.3.1" 30 | } 31 | } 32 | --------------------------------------------------------------------------------