├── .editorconfig ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .jshintrc ├── .npmrc ├── .travis.yml ├── CHANGES.md ├── CODEOWNERS ├── fixtures └── app.js ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = tab 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [package.json] 12 | indent_style = space 13 | indent_size = 2 14 | 15 | [*.md] 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 9 | 10 | # Description/Steps to reproduce 11 | 12 | 16 | 17 | # Link to reproduction sandbox 18 | 19 | 24 | 25 | # Expected result 26 | 27 | 30 | 31 | # Additional information 32 | 33 | 38 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | 4 | #### Related issues 5 | 6 | 12 | 13 | - connect to 14 | 15 | ### Checklist 16 | 17 | 22 | 23 | - [ ] New tests added or existing tests modified to cover all changes 24 | - [ ] Code conforms with the [style 25 | guide](http://loopback.io/doc/en/contrib/style-guide.html) 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "immed": true, 8 | "newcap": true, 9 | "noarg": true, 10 | "undef": true, 11 | "unused": "vars", 12 | "strict": true 13 | } 14 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "6" 5 | - "8" 6 | - "10" 7 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | 2020-03-06, Version 1.0.1 2 | ========================= 3 | 4 | * Update LTS status in README (Miroslav Bajtoš) 5 | 6 | * chore: update copyrights years (Agnes Lin) 7 | 8 | * add lts announcement (jannyHou) 9 | 10 | 11 | 2018-06-07, Version 1.0.0 12 | ========================= 13 | 14 | * Update dependencies to the latest versions (Miroslav Bajtoš) 15 | 16 | * Drop Node 4.x, add travis and npmrc (Miroslav Bajtoš) 17 | 18 | * Add CODEOWNER file (Diana Lau) 19 | 20 | * Create Issue and PR Templates (#18) (Sakib Hasan) 21 | 22 | * Replicate new issue_template from loopback (Siddhi Pai) 23 | 24 | * Replicate issue_template from loopback repo (Siddhi Pai) 25 | 26 | * Update paid support URL (Siddhi Pai) 27 | 28 | 29 | 2016-11-23, Version 0.2.0 30 | ========================= 31 | 32 | * First release! 33 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Lines starting with '#' are comments. 2 | # Each line is a file pattern followed by one or more owners, 3 | # the last matching pattern has the most precedence. 4 | 5 | # Core team members from IBM 6 | * @kjdelisle @jannyHou @loay @b-admike @ssh24 @virkt25 @dhmlau 7 | -------------------------------------------------------------------------------- /fixtures/app.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2018. All Rights Reserved. 2 | // Node module: gulp-loopback-sdk-angular 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | var loopback = require('loopback'); 7 | var app = loopback(); 8 | 9 | // Setup default datasources for autoAttach() 10 | app.dataSource('db', { connector: 'memory'}); 11 | 12 | // Configure REST API path 13 | app.set('restApiRoot', '/rest-api-root'); 14 | 15 | module.exports = app; 16 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014. All Rights Reserved. 2 | // Node module: gulp-loopback-sdk-angular 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | 'use strict'; 7 | var gutil = require('gulp-util'); 8 | var through = require('through2'); 9 | var generator = require('loopback-sdk-angular'); 10 | var path = require('path'); 11 | var WatchJS = require('watchjs'); 12 | 13 | var watch = WatchJS.watch; 14 | var unwatch = WatchJS.unwatch; 15 | 16 | // This callback will be passed to watch, this refers to the datasource 17 | function disconnectDataSource(prop, action, newValue) { 18 | if (newValue === true) { 19 | this.disconnect(); 20 | unwatch(this, 'connected'); 21 | } 22 | } 23 | 24 | module.exports = function (options) { 25 | return through.obj(function (file, enc, cb) { 26 | if (file.isNull()) { 27 | this.push(file); 28 | cb(); 29 | return; 30 | } 31 | 32 | var app; 33 | try { 34 | app = require(path.resolve(file.path)); 35 | 36 | // Incase options is undefined. 37 | options = options || {ngModuleName: 'lbServices', apiUrl: undefined}; 38 | 39 | options.ngModuleName = options.ngModuleName || 'lbServices'; 40 | options.apiUrl = options.apiUrl || app.get('restApiRoot') || '/api'; 41 | 42 | gutil.log('Loaded LoopBack app', gutil.colors.magenta(file.path)); 43 | gutil.log('Generating', 44 | gutil.colors.magenta(options.ngModuleName), 45 | 'for the API endpoint', 46 | gutil.colors.magenta(options.apiUrl) 47 | ); 48 | 49 | var script = generator.services( 50 | app, 51 | options.ngModuleName, 52 | options.apiUrl 53 | ); 54 | 55 | file.contents = new Buffer(script); 56 | 57 | gutil.log('Generated Angular services file.'); 58 | 59 | this.push(file); 60 | 61 | var dataSources = app.dataSources; 62 | for (var dataSource in dataSources) { 63 | if (dataSources.hasOwnProperty(dataSource)) { 64 | var ds = dataSources[dataSource]; 65 | watch(ds, 'connected', disconnectDataSource); 66 | } 67 | } 68 | } catch (err) { 69 | this.emit('error', new gutil.PluginError('gulp-loopback-sdk-angular', err)); 70 | } 71 | 72 | cb(); 73 | return; 74 | }); 75 | }; 76 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Zi Ming Lin 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. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-loopback-sdk-angular", 3 | "version": "1.0.1", 4 | "description": "gulp plugin for auto-generating Angular $resource services for LoopBack", 5 | "license": "MIT", 6 | "repository": "strongloop/gulp-loopback-sdk-angular", 7 | "author": "IBM Corp.", 8 | "engines": { 9 | "node": ">=6" 10 | }, 11 | "scripts": { 12 | "test": "mocha --timeout 5000" 13 | }, 14 | "files": [ 15 | "index.js" 16 | ], 17 | "keywords": [ 18 | "gulpplugin", 19 | "angular", 20 | "loopback" 21 | ], 22 | "dependencies": { 23 | "gulp-util": "^3.0.1", 24 | "loopback-sdk-angular": "^3.0.0", 25 | "through2": "^2.0.3", 26 | "watchjs": "0.0.0" 27 | }, 28 | "devDependencies": { 29 | "loopback": "^3.19.3", 30 | "mocha": "*" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # gulp-loopback-sdk-angular [![Build Status](https://travis-ci.org/zimlin/gulp-loopback-sdk-angular.svg?branch=master)](https://travis-ci.org/zimlin/gulp-loopback-sdk-angular) 2 | 3 | **⚠️ LoopBack 3 has reached end of life. We are no longer accepting pull requests or providing 4 | support for community users. The only exception is fixes for critical bugs and security 5 | vulnerabilities provided as part of support for IBM API Connect customers. (See 6 | [Module Long Term Support Policy](#module-long-term-support-policy) below.)** 7 | 8 | We urge all LoopBack 3 users to migrate their applications to LoopBack 4 as 9 | soon as possible. Refer to our 10 | [Migration Guide](https://loopback.io/doc/en/lb4/migration-overview.html) 11 | for more information on how to upgrade. 12 | 13 | ## Overview 14 | 15 | [gulp](http://gulpjs.com) plugin for auto-generating Angular $resource services for LoopBack. 16 | This is a port of the Grunt plugin [here](https://github.com/strongloop/grunt-loopback-sdk-angular) 17 | 18 | ## Install 19 | 20 | ```sh 21 | $ npm install --save-dev gulp-loopback-sdk-angular 22 | ``` 23 | 24 | 25 | ## Usage 26 | 27 | ```js 28 | var gulp = require('gulp'); 29 | var rename = require('gulp-rename'); 30 | var loopbackAngular = require('gulp-loopback-sdk-angular'); 31 | 32 | gulp.task('default', function () { 33 | return gulp.src('./server/app.js') 34 | .pipe(loopbackAngular()) 35 | .pipe(rename('lb-services.js')) 36 | .pipe(gulp.dest('./client/js')); 37 | }); 38 | ``` 39 | 40 | 41 | ## API 42 | 43 | ### loopbackAngular(options) 44 | 45 | #### options 46 | 47 | ##### options.ngModuleName 48 | 49 | Type: `String` 50 | Default: `lbServices` 51 | 52 | Name for the generated AngularJS module. 53 | 54 | ##### options.apiUrl 55 | 56 | Type: `String` 57 | Default: The value configured in the LoopBack application via app.set('restApiRoot') or `/api` 58 | 59 | ## Everything Else 60 | 61 | http://docs.strongloop.com/display/LB/AngularJS+JavaScript+SDK 62 | 63 | 64 | ## License 65 | 66 | MIT © [Zi Ming Lin](https://github.com/zimlin) 67 | 68 | ## Module Long Term Support Policy 69 | 70 | This module adopts the [Module Long Term Support (LTS)](http://github.com/CloudNativeJS/ModuleLTS) policy, with the following End Of Life (EOL) dates: 71 | 72 | | Version | Status | Published | EOL | 73 | | ------- | --------------- | --------- | -------- | 74 | | 1.x | End-of-Life | Jun 2018 | Dec 2020 | 75 | 76 | Learn more about our LTS plan in the [docs](https://loopback.io/doc/en/contrib/Long-term-support.html). 77 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2016. All Rights Reserved. 2 | // Node module: gulp-loopback-sdk-angular 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | 'use strict'; 7 | var assert = require('assert'); 8 | var gutil = require('gulp-util'); 9 | var loopbackAngular = require('./index'); 10 | var fs = require('fs'); 11 | 12 | it('should ', function (cb) { 13 | var stream = loopbackAngular(); 14 | 15 | stream.on('data', function (file) { 16 | assert(/var urlBase = "\/rest-api-root";/.test(file.contents)); 17 | assert(/var module = angular.module\("lbServices", \['ngResource'\]\);/ 18 | .test(file.contents)); 19 | assert(/\.provider\('LoopBackResource', function LoopBackResourceProvider/ 20 | .test(file.contents)); 21 | assert(/\}\)\(window, window.angular\);/.test(file.contents)); 22 | }); 23 | 24 | stream.on('end', cb); 25 | 26 | stream.write(new gutil.File({ 27 | base: __dirname, 28 | path: __dirname + '/fixtures/app.js', 29 | contents: fs.readFileSync('fixtures/app.js') 30 | })); 31 | 32 | stream.end(); 33 | }); 34 | --------------------------------------------------------------------------------