Skip to content

Commit 03e8bb6

Browse files
committed
Initial commit
0 parents  commit 03e8bb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1729
-0
lines changed

.editorconfig

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# ____ __ __ __ _
2+
# / ___) / \ / \ ( ( \
3+
# \___ \( O )( O )/ / ____
4+
# (____/ \__/ \__/ \_)__)(____)
5+
#
6+
# SOON_ Cross team root editorconfig configuration
7+
# Projects can also have a local .editorconfig to customise syntax
8+
#
9+
10+
# top-most EditorConfig file
11+
root = true
12+
13+
# Unix-style newlines with a newline ending every file
14+
[*]
15+
end_of_line = lf
16+
insert_final_newline = true
17+
18+
# Backend Languages (Python, Go, Ruby etc)
19+
20+
# Python
21+
[*.py]
22+
indent_style = space
23+
indent_size = 4
24+
line_length=80
25+
multi_line_output=3
26+
default_section=THIRDPARTY
27+
import_heading_stdlib=Standard Libs
28+
import_heading_thirdparty=Third Party Libs
29+
import_heading_firstparty=First Party Libs
30+
lines_after_imports=2
31+
32+
# Ruby
33+
[{*.rb,Vagrantfile}]
34+
indent_style = space
35+
indent_size = 2
36+
37+
# Front End Languages (HTML, JS, CSS etc)
38+
39+
[*.{ts, js, css, html}]
40+
indent_style = space
41+
indent_size = 2
42+
charset = utf-8
43+
trim_trailing_whitespace = true
44+
45+
## JS
46+
[*.{js,ts}]
47+
quote_type = single
48+
49+
# Misc
50+
51+
# YAML Based files - 2 space indent
52+
[*.{yml, yaml, sls}]
53+
indent_style = space
54+
indent_size = 2

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.DS_STORE
2+
dist/
3+
node_modules/
4+
out-tsc/
5+
debug.log
6+
npm-debug.log
7+
src/**/*.js
8+
!src/demo/systemjs.config.js
9+
!src/demo/systemjs.config.lib.js
10+
!**/*systemjs-angular-loader.js
11+
*.js.map
12+
e2e/**/*.js
13+
e2e/**/*.js.map
14+
coverage

.travis.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
dist: trusty
2+
sudo: false
3+
language: node_js
4+
node_js:
5+
- "8"
6+
os:
7+
- linux
8+
before_install:
9+
# Use a virtual display.
10+
- export DISPLAY=:99.0
11+
- sh -e /etc/init.d/xvfb start
12+
# Install latest chrome.
13+
- export CHROME_BIN=chromium-browser
14+
install:
15+
- npm install
16+
script:
17+
- npm run lint
18+
- npm run test:once
19+
- npm run integration
20+
- npm run coverage

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License
2+
3+
Copyright (c) 2017 SOON_. http://thisissoon.com/
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+

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Angular ScrollSpy
2+
[![Build Status][travis-badge]][travis-badge-url]
3+
[![Coverage Status][coveralls-badge]][coveralls-badge-url]
4+
5+
A simple lightweight library for [Angular (2/4+)][angular] which automatically updates links to indicate the currently active section in the viewport.
6+
7+
This is a simple library for [Angular][angular], implemented in the [Angular Package Format v4.0](https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/edit#heading=h.k0mh3o8u5hx).
8+
9+
10+
## Install
11+
12+
`npm i @thisissoon/angular-scrollspy --save`
13+
14+
`app.module.ts`
15+
```ts
16+
import { ScrollSpyModule } from '@thisissoon/angular-scrollspy';
17+
18+
@NgModule({
19+
imports: [
20+
ScrollSpyModule
21+
]
22+
})
23+
export class AppModule { }
24+
```
25+
26+
27+
## Example
28+
29+
`app.component.html`
30+
31+
```html
32+
<p class="foo" snScrollSpy>
33+
...
34+
</p>
35+
```
36+
37+
[travis-badge]: https://travis-ci.org/thisissoon/angular-scrollspy.svg?branch=master
38+
[travis-badge-url]: https://travis-ci.org/thisissoon/angular-scrollspy
39+
[coveralls-badge]: https://coveralls.io/repos/github/thisissoon/angular-scrollspy/badge.svg?branch=master
40+
[coveralls-badge-url]: https://coveralls.io/github/thisissoon/angular-scrollspy?branch=master
41+
[angular]: https://angular.io/

bs-config.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"ghostMode": false,
3+
"server": {
4+
"baseDir": "src/demo",
5+
"routes": {
6+
"/node_modules": "node_modules",
7+
"/angular-scrollspy": "src/lib"
8+
}
9+
}
10+
}

build.js

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const glob = require('glob');
6+
const camelCase = require('camelcase');
7+
const ngc = require('@angular/compiler-cli/src/main').main;
8+
const rollup = require('rollup');
9+
const uglify = require('rollup-plugin-uglify');
10+
const sourcemaps = require('rollup-plugin-sourcemaps');
11+
const nodeResolve = require('rollup-plugin-node-resolve');
12+
const commonjs = require('rollup-plugin-commonjs');
13+
14+
const inlineResources = require('./inline-resources');
15+
16+
const libName = require('./package.json').name.replace('@thisissoon/', '');
17+
const rootFolder = path.join(__dirname);
18+
const compilationFolder = path.join(rootFolder, 'out-tsc');
19+
const srcFolder = path.join(rootFolder, 'src/lib');
20+
const distFolder = path.join(rootFolder, 'dist');
21+
const tempLibFolder = path.join(compilationFolder, 'lib');
22+
const es5OutputFolder = path.join(compilationFolder, 'lib-es5');
23+
const es2015OutputFolder = path.join(compilationFolder, 'lib-es2015');
24+
25+
return Promise.resolve()
26+
// Copy library to temporary folder and inline html/css.
27+
.then(() => _relativeCopy(`**/*`, srcFolder, tempLibFolder)
28+
.then(() => inlineResources(tempLibFolder))
29+
.then(() => console.log('Inlining succeeded.'))
30+
)
31+
// Compile to ES2015.
32+
.then(() => ngc({ project: `${tempLibFolder}/tsconfig.lib.json` })
33+
.then(exitCode => exitCode === 0 ? Promise.resolve() : Promise.reject())
34+
.then(() => console.log('ES2015 compilation succeeded.'))
35+
)
36+
// Compile to ES5.
37+
.then(() => ngc({ project: `${tempLibFolder}/tsconfig.es5.json` })
38+
.then(exitCode => exitCode === 0 ? Promise.resolve() : Promise.reject())
39+
.then(() => console.log('ES5 compilation succeeded.'))
40+
)
41+
// Copy typings and metadata to `dist/` folder.
42+
.then(() => Promise.resolve()
43+
.then(() => _relativeCopy('**/*.d.ts', es2015OutputFolder, distFolder))
44+
.then(() => _relativeCopy('**/*.metadata.json', es2015OutputFolder, distFolder))
45+
.then(() => console.log('Typings and metadata copy succeeded.'))
46+
)
47+
// Bundle lib.
48+
.then(() => {
49+
// Base configuration.
50+
const es5Entry = path.join(es5OutputFolder, `${libName}.js`);
51+
const es2015Entry = path.join(es2015OutputFolder, `${libName}.js`);
52+
const rollupBaseConfig = {
53+
moduleName: camelCase(libName),
54+
sourceMap: true,
55+
// ATTENTION:
56+
// Add any dependency or peer dependency your library to `globals` and `external`.
57+
// This is required for UMD bundle users.
58+
globals: {
59+
// The key here is library name, and the value is the the name of the global variable name
60+
// the window object.
61+
// See https://github.com/rollup/rollup/wiki/JavaScript-API#globals for more.
62+
'@angular/core': 'ng.core'
63+
},
64+
external: [
65+
// List of dependencies
66+
// See https://github.com/rollup/rollup/wiki/JavaScript-API#external for more.
67+
'@angular/core'
68+
],
69+
plugins: [
70+
commonjs({
71+
include: ['node_modules/rxjs/**']
72+
}),
73+
sourcemaps(),
74+
nodeResolve({ jsnext: true, module: true })
75+
]
76+
};
77+
78+
// UMD bundle.
79+
const umdConfig = Object.assign({}, rollupBaseConfig, {
80+
entry: es5Entry,
81+
dest: path.join(distFolder, `bundles`, `${libName}.umd.js`),
82+
format: 'umd',
83+
});
84+
85+
// Minified UMD bundle.
86+
const minifiedUmdConfig = Object.assign({}, rollupBaseConfig, {
87+
entry: es5Entry,
88+
dest: path.join(distFolder, `bundles`, `${libName}.umd.min.js`),
89+
format: 'umd',
90+
plugins: rollupBaseConfig.plugins.concat([uglify({})])
91+
});
92+
93+
// ESM+ES5 flat module bundle.
94+
const fesm5config = Object.assign({}, rollupBaseConfig, {
95+
entry: es5Entry,
96+
dest: path.join(distFolder, `${libName}.es5.js`),
97+
format: 'es'
98+
});
99+
100+
// ESM+ES2015 flat module bundle.
101+
const fesm2015config = Object.assign({}, rollupBaseConfig, {
102+
entry: es2015Entry,
103+
dest: path.join(distFolder, `${libName}.js`),
104+
format: 'es'
105+
});
106+
107+
const allBundles = [
108+
umdConfig,
109+
minifiedUmdConfig,
110+
fesm5config,
111+
fesm2015config
112+
].map(cfg => rollup.rollup(cfg).then(bundle => bundle.write(cfg)));
113+
114+
return Promise.all(allBundles)
115+
.then(() => console.log('All bundles generated successfully.'))
116+
})
117+
// Copy package files
118+
.then(() => Promise.resolve()
119+
.then(() => _relativeCopy('LICENSE', rootFolder, distFolder))
120+
.then(() => _relativeCopy('package.json', rootFolder, distFolder))
121+
.then(() => _relativeCopy('README.md', rootFolder, distFolder))
122+
.then(() => console.log('Package files copy succeeded.'))
123+
)
124+
.catch(e => {
125+
console.error('\Build failed. See below for errors.\n');
126+
console.error(e);
127+
process.exit(1);
128+
});
129+
130+
131+
// Copy files maintaining relative paths.
132+
function _relativeCopy(fileGlob, from, to) {
133+
return new Promise((resolve, reject) => {
134+
glob(fileGlob, { cwd: from, nodir: true }, (err, files) => {
135+
if (err) reject(err);
136+
files.forEach(file => {
137+
const origin = path.join(from, file);
138+
const dest = path.join(to, file);
139+
const data = fs.readFileSync(origin, 'utf-8');
140+
_recursiveMkDir(path.dirname(dest));
141+
fs.writeFileSync(dest, data);
142+
resolve();
143+
})
144+
})
145+
});
146+
}
147+
148+
// Recursively create a dir.
149+
function _recursiveMkDir(dir) {
150+
if (!fs.existsSync(dir)) {
151+
_recursiveMkDir(path.dirname(dir));
152+
fs.mkdirSync(dir);
153+
}
154+
}

0 commit comments

Comments
 (0)