├── .gitignore
├── .npmignore
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── package.json
├── src
└── esriSystem.ts
└── tsconfig.json
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18 | .grunt
19 |
20 | # node-waf configuration
21 | .lock-wscript
22 |
23 | # Compiled binary addons (http://nodejs.org/api/addons.html)
24 | build/Release
25 |
26 | # Dependency directories
27 | node_modules
28 | jspm_packages
29 |
30 | # Optional npm cache directory
31 | .npm
32 |
33 | # Optional REPL history
34 | .node_repl_history
35 |
36 | # mac
37 | .DS_Store
38 |
39 | # typescript output
40 | dist
41 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18 | .grunt
19 |
20 | # node-waf configuration
21 | .lock-wscript
22 |
23 | # Compiled binary addons (http://nodejs.org/api/addons.html)
24 | build/Release
25 |
26 | # Dependency directories
27 | node_modules
28 | jspm_packages
29 |
30 | # Optional npm cache directory
31 | .npm
32 |
33 | # Optional REPL history
34 | .node_repl_history
35 |
36 | # mac
37 | .DS_Store
38 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file.
4 | This project adheres to [Semantic Versioning](http://semver.org/).
5 |
6 | [Upcoming changes][unreleased]
7 |
8 | ### Support
9 | - add deprecation message to README
10 | - add links to systemjs-plugin-dojo and ng2-esri-demo to README
11 | - add links to Josh Werts' blog post and example app
12 |
13 | ## [v1.0.0-beta.0]
14 | ### Added
15 | - option to maintain module names, offering compatibility with official type definitions
16 |
17 | ### Changed
18 | - if no options are supplied to register(), default to maintaing module names
19 |
20 | ## [v0.0.3]
21 |
22 | ### Changed
23 | - added comments about licensing and copyright
24 | - minor formatting clean up
25 |
26 | ### Support
27 | - Fleshed out README w/ Quick Start, Developer Instructions, etc
28 | - Added CONTRIBUTING
29 | - Added contributor info to packge.json and updated repo URL
30 |
31 | ## [v0.0.2]
32 |
33 | ### Changed
34 | - allow user to supply partial options to esriSytem.register()
35 | and use defaults for others #3
36 |
37 | ## [v0.0.1]
38 |
39 | ### Added
40 | - esriSystem which exposes `.register()` which
41 | loads esri modules and registers them w/ SystemJS
42 |
43 | ### Support
44 | - installed typescript as a dev dependency and
45 | added npm scripts to compile TS
46 | - added .gitignore for TS ouput files and
47 | .npmignore to include those files when publishing to NPM
48 | - added "docs" to README and started CHANGELOG
49 |
50 | [unreleased]: https://github.com/arcgis/esri-system-js/compare/v1.0.0-beta.0...HEAD
51 | [v1.0.0-beta.0]: https://github.com/arcgis/esri-system-js/compare/v0.0.2...v1.0.0-beta.0
52 | [v0.0.3]: https://github.com/arcgis/esri-system-js/compare/v0.0.2...v0.0.3
53 | [v0.0.2]: https://github.com/arcgis/esri-system-js/compare/v0.0.1...v0.0.2
54 | [v0.0.1]: https://github.com/arcgis/esri-system-js/commits/v0.0.1
55 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](https://github.com/esri/contributing).
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # esri-system-js
2 | Load [ArcGIS API for JavaScript] modules using [SystemJS]
3 |
4 | > NOTE: this library has been deprecated in favor of [systemjs-plugin-dojo](https://github.com/beginor/systemjs-plugin-dojo) - which is a [SystemJS](https://github.com/systemjs/systemjs) plugin for loading Dojo modules that works with the ArcGIS API for JavaScript. [ng2-esri-demo](https://github.com/beginor/ng2-esri-demo) shows how to use that plugin to load ArcGIS modules in an Angular application.
5 |
6 | Provides a wrapper around [SystemJS]'s `register()` function
7 | that will first use Dojo's AMD loader to load Esri modules,
8 | and then register a SystemJS module that will expose them.
9 |
10 | > **NOTE**: many users have experienced trouble using this library in Visual Studio. For all intents and purposes you should consider Visual Studio to be unsupported by this library. None of the maintainers have access to it. We recommend Visual Studio Code.
11 |
12 | ## SystemJS Plugin
13 | [systemjs-plugin-dojo](https://www.npmjs.com/package/systemjs-plugin-dojo) is a SystemJS plugin for loading Dojo modules that works with the ArcGIS API for JavaScript. [ng2-esri-demo](https://github.com/beginor/ng2-esri-demo) shows how to use that plugin to load ArcGIS modules in an Angular application.
14 |
15 | This library (esri-system-js) predates the above SystemJS plugin, but is **not** a SystemJS plugin, and therefore requires you to perform the additional configuration steps shown below.
16 |
17 | ## Quick Start
18 | For example, if you wanted to use [ArcGIS API for JavaScript] modules in your [TypeScript] code in an [Angular 2] application.
19 |
20 | 1) Install:
21 | ```bash
22 | npm install esri-system-js@beta --save
23 | ```
24 |
25 | 2) Include (in index.html):
26 | ```
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | ```
37 |
38 | 3) Configure (in index.html):
39 | ```html
40 |
68 | ```
69 |
70 | 4) Import modules (in app/boot.ts or any other application module):
71 | ```ts
72 | import Map from 'esri/Map';
73 | import MapView from 'esri/views/MapView';
74 | import esriRequest from 'esri/request';
75 | ```
76 |
77 | If your project requires you to configure SystemJS with `defaultJSExtensions: true`, see [this issue](https://github.com/Esri/esri-system-js/issues/25
78 | ) for additional configuration steps.
79 |
80 | ### Using esri-system-js in TypeScript Applications
81 |
82 | If you're writing your application code in TypeScript, you can now get type checking and intellisense for the above modules by downloading and using the [ArcGIS API for JavaScript type definitions]. Note that you will need to [configure the TypeScript compiler](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to use `"allowSyntheticDefaultImports": true`.
83 |
84 | ## Registering as a Single Module
85 |
86 | You can supply a third, optional argument to `esriSystem.register()` with options to register all the required Esri modules to a single new module. Note that registering all modules as a single SystemJS module will **not** work with the [ArcGIS API for JavaScript type definitions]).
87 |
88 | ```js
89 | // load esri modules needed by this application
90 | // and then regsiter a new SystemJS module that exposes them
91 | esriSystem.register(
92 | // array of Esri module names to load and then register with SystemJS
93 | [
94 | 'esri/Map',
95 | 'esri/views/MapView',
96 | 'esri/widgets/Home/HomeViewModel',
97 | 'esri/request'
98 | ],
99 |
100 | // optional callback function
101 | function() {
102 | // then bootstrap application
103 | System.import('app/boot')
104 | .then(null, console.error.bind(console));
105 | },
106 | // options to register a new, single SystemJS module
107 | {
108 | // name of SystemJS module that you will import from
109 | outModuleName: 'esri-mods',
110 | // by default each module will use everything after the last '/' in their name
111 | // however you can override that for specific modules here
112 | moduleNameOverrides: {
113 | 'esri/request': 'esriRequest'
114 | }
115 | });
116 |
117 | ```
118 |
119 | Now you can import these modules as follows:
120 | ```ts
121 | import { Map, MapView, esriRequest } from 'esri-mods';
122 | ```
123 |
124 | ## Why?
125 |
126 | The [ArcGIS API for JavaScript] is based on Dojo, which uses AMD modules, and [SystemJS] can load AMD modules, so why is this needed? We've not been able to figure out a way to have [SystemJS] load Esri's modules directly. As with other loaders that support AMD, the issue is around plugins. You can see a summary of the issue [here](https://twitter.com/tomwayson/status/709456083388014594).
127 |
128 | ## Example Applications
129 | See these applications for examples of how to use this library:
130 | - [jwasilgeo/angular2-esri-playground](https://github.com/jwasilgeo/angular2-esri-playground) - Angular 2 & Esri 4 [View it live](http://jwasilgeo.github.io/angular2-esri-playground/)
131 | - Josh Wert's blog post on [ESRI Javascript API 4 with Angular 2 and Typescript](http://joshwerts.com/blog/2016/05/17/esri-javascript-api-4-with-angular-2-and-typescript/) - includes Jasmine/Karma test configuration [View it live](http://joshwerts.com/jsapi4-angular2/)
132 | - "Angular 2 + Esri 3 + Dojo Plugin" - Angular 2 with Esri JSAPI v3, demonstrating how to incorporate an external Dojo package/plugin for point layer clustering with esri-system-js. [View it live on plnkr](http://plnkr.co/edit/bZNzdI?p=preview). (This demo originated from [issue #9](https://github.com/Esri/esri-system-js/issues/9).)
133 | - [Angular and Esri JavaScript API](https://github.com/S-Gaballah/Angular-Esri-ArcGIS-API-3) - Startup project for ArcGIS API for JavaScript V3, Angular and Material Design
134 |
135 | Have you built an application using esri-system-js? [Let us know](https://github.com/Esri/esri-system-js/issues/14) and we'll add it here.
136 |
137 | ## Development Instructions
138 |
139 | Make sure you have [Node](http://nodejs.org/) installed.
140 |
141 | 1. [Fork and clone this repo](https://help.github.com/articles/fork-a-repo)
142 | 2. `cd` into the `esri-system-js` folder
143 | 3. Install the dependencies with `npm install`
144 | 4. run `npm start` from the command line. This will run the [TypeScript] compiler then start a local web server hosting the application under the `docs` folder
145 | 5. Modify the source files (under `src`)
146 | 6. Make a [pull request](https://help.github.com/articles/creating-a-pull-request) to contribute your changes
147 |
148 | ## Credit
149 | This pattern was established by [@odoe](https://github.com/odoe/) in the [load.js](https://github.com/odoe/esrijs4-vm-angular2/blob/d309f546d1d183064e4b60d69ba88e9047ebc26c/app/load.ts) file of his [example of using ErsiJS 4.0 view models with Angular 2](https://github.com/odoe/esrijs4-vm-angular2).
150 |
151 | Later, [@nickcam](https://github.com/nickcam) came up with [the idea to register one SystemJS module for each Esri module required and maintain the exact same module names](https://github.com/Esri/esri-system-js/pull/10), which makes it possible to use the [ArcGIS API for JavaScript type definitions] for the modules you import.
152 |
153 | ## Resources
154 | * [ArcGIS API for JavaScript]
155 | * [SystemJS]
156 | * [TypeScript]
157 | * [Angular 2]
158 |
159 | [SystemJS]:https://github.com/systemjs/systemjs
160 | [ArcGIS API for JavaScript]:https://developers.arcgis.com/javascript/
161 | [TypeScript]:http://www.typescriptlang.org/
162 | [ArcGIS API for JavaScript type definitions]:https://github.com/Esri/jsapi-resources/tree/master/4.x/typescript
163 | [Angular 2]:https://angular.io/
164 |
165 | ## Issues
166 |
167 | Find a bug or want to request a new feature? Please let us know by [submitting an issue](https://github.com/esri/esri-system-js/issues). Thank you!
168 |
169 | ## Contributing
170 |
171 | Anyone and everyone is welcome to contribute. Please see our [guidelines for contributing](https://github.com/Esri/esri-system-js/blob/master/CONTRIBUTING.md).
172 |
173 | ## Licensing
174 | Copyright 2016 Esri
175 |
176 | Licensed under the Apache License, Version 2.0 (the "License");
177 | you may not use this file except in compliance with the License.
178 | You may obtain a copy of the License at
179 |
180 | http://www.apache.org/licenses/LICENSE-2.0
181 |
182 | Unless required by applicable law or agreed to in writing, software
183 | distributed under the License is distributed on an "AS IS" BASIS,
184 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
185 | See the License for the specific language governing permissions and
186 | limitations under the License.
187 |
188 | A copy of the license is available in the repository's [license.txt](https://raw.github.com/Esri/esri-system-js/master/LICENSE) file.
189 |
190 | [](Esri Tags: ArcGIS Esri SystemJS TypeScript)
191 | [](Esri Language: JavsScript)
192 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "esri-system-js",
3 | "version": "1.0.0-beta.0",
4 | "description": "Load ArcGIS API for JavaScript modules using SystemJS",
5 | "dependencies": {},
6 | "devDependencies": {
7 | "typescript": "^1.8.2"
8 | },
9 | "scripts": {
10 | "test": "tsc",
11 | "prepublish": "tsc",
12 | "start": "tsc -w"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/esri/esri-system-js.git"
17 | },
18 | "keywords": [
19 | "SystemJS",
20 | "Esri",
21 | "ArcGIS"
22 | ],
23 | "author": "Tom Wayson (http://tomwayson.com)",
24 | "contributors": [
25 | "Rene Rubalcava "
26 | ],
27 | "license": "Apache-2.0",
28 | "bugs": {
29 | "url": "https://github.com/esri/esri-system-js/issues"
30 | },
31 | "homepage": "https://github.com/esri/esri-system-js"
32 | }
33 |
--------------------------------------------------------------------------------
/src/esriSystem.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2016 Esri
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 | Unless required by applicable law or agreed to in writing, software
8 | distributed under the License is distributed on an "AS IS" BASIS,
9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | declare var System: any;
15 | declare var require: Function;
16 |
17 | module esriSystem {
18 |
19 | // return just the last part of a module name
20 | function moduleName(name: string, overrides?: any) {
21 | if (overrides && overrides[name]) {
22 | return overrides[name];
23 | } else {
24 | return name.match(/[^\/]+$/).shift();
25 | }
26 | }
27 |
28 | //get the module name from the url that system js thinks it's loading it from
29 | function getName(location: string) {
30 | let startIndex = location.lastIndexOf("esri");
31 | if (startIndex === -1) startIndex = location.lastIndexOf("dojo");
32 | return location.substring(startIndex, location.length);
33 | }
34 |
35 | function registerToOutModule(mods, names, options: any) {
36 | System.register(options.outModuleName, [], function (exp) {
37 | return {
38 | setters: [],
39 | execute: function () {
40 | mods.map(function (mod, idx) {
41 | exp(moduleName(names[idx], options.moduleNameOverrides), mod);
42 | });
43 | }
44 | };
45 | });
46 | }
47 |
48 | // takes an array of modules and registers them
49 | // with system.js using the given module name(s)
50 | function _register(mods, names: string[], options: any) {
51 | const opts = options || {};
52 |
53 | if (opts.outModuleName) {
54 | // register all modules into a new module w/ the given name (i.e. 'esri-mods')
55 | registerToOutModule(mods, names, opts);
56 | return;
57 | }
58 |
59 | //maintaining the module names so loop each module and register individually.
60 | for (var i = 0, len = mods.length; i < len; i++) {
61 |
62 | System.register(names[i], [], function (exp, idObj) {
63 | let name = getName(idObj.id);
64 | let index = names.indexOf(name);
65 | let mod = mods[index];
66 | let result = {
67 | setters: [],
68 | execute: () => {
69 | //Make the name 'default' here as there is only one export per module so it is technically the default.
70 | //Import using a default import statement - eg: import Map from 'esri/Map'
71 | //It's possible this may only compile using 'system' module type in some IDEs using the official typings file though.
72 | exp("default", mod);
73 | }
74 | };
75 | return result;
76 | });
77 | }
78 | }
79 |
80 | // load esri modules and expose via a System.js module
81 | export function register(moduleNames: string[], callback: Function, options) {
82 | // TODO: config should be optional, parse from arguments
83 |
84 | // call Dojo's require to load esri modules
85 | require(moduleNames, function (...modules) {
86 | // register a System.js module to wrap the required modules
87 | _register(modules, moduleNames, options);
88 |
89 | // call callback (if any)
90 | if (callback) {
91 | callback();
92 | }
93 | });
94 | };
95 | }
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "module": "umd",
5 | "moduleResolution": "node",
6 | "sourceMap": true,
7 | "emitDecoratorMetadata": true,
8 | "experimentalDecorators": true,
9 | "removeComments": false,
10 | "noImplicitAny": false,
11 | "outDir": "./dist"
12 | },
13 | "exclude": [
14 | "node_modules"
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------