Skip to content

Commit ba9e6ac

Browse files
committed
added consume() method and deploy scripts
1 parent ec58775 commit ba9e6ac

File tree

14 files changed

+490
-5
lines changed

14 files changed

+490
-5
lines changed

.deploy/copy_to_enumerableJS.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// The MIT License (MIT)
2+
//
3+
// node-enumerable (https://github.com/mkloubert/node-enumerable)
4+
// Copyright (c) Marcel Joachim Kloubert <marcel.kloubert@gmx.net>
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to
8+
// deal in the Software without restriction, including without limitation the
9+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10+
// sell copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
// DEALINGS IN THE SOFTWARE.
23+
24+
25+
// this is a script target for
26+
// vs-deploy VSCode extension
27+
//
28+
// s. https://github.com/mkloubert/vs-deploy
29+
// for more information
30+
31+
const FS = require('fs');
32+
const Path = require('path');
33+
34+
const LINE_SPLITTER = "\n";
35+
36+
exports.deployFile = function(args) {
37+
// lines of NodeJS '/index.js' file
38+
let index_js = FS.readFileSync(args.file)
39+
.toString('utf8')
40+
.split(LINE_SPLITTER);
41+
42+
// make browser compatible
43+
var enumerable_js = [];
44+
for (let line of index_js) {
45+
let lineToAdd = line;
46+
if ('module.exports = Enumerable;' === lineToAdd.trim()) {
47+
lineToAdd = '';
48+
}
49+
else if ('//# sourceMappingURL=index.js.map' === lineToAdd.trim()) {
50+
lineToAdd = '//# sourceMappingURL=enumerable.js.map';
51+
}
52+
53+
enumerable_js.push(
54+
lineToAdd
55+
);
56+
}
57+
58+
// the content to write
59+
var content = new Buffer(
60+
enumerable_js.join(LINE_SPLITTER),
61+
'utf8'
62+
);
63+
64+
var listOfOutputFiles = [
65+
Path.join( __dirname, '../js/enumerable.js' ),
66+
Path.join( __dirname, '../demo/js/enumerable.js' ),
67+
];
68+
69+
for (let outFile of listOfOutputFiles) {
70+
FS.writeFileSync(
71+
Path.resolve(outFile),
72+
content,
73+
);
74+
}
75+
}

.deploy/github.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// The MIT License (MIT)
2+
//
3+
// node-enumerable (https://github.com/mkloubert/node-enumerable)
4+
// Copyright (c) Marcel Joachim Kloubert <marcel.kloubert@gmx.net>
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to
8+
// deal in the Software without restriction, including without limitation the
9+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10+
// sell copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
// DEALINGS IN THE SOFTWARE.
23+
24+
25+
// this is a script target for
26+
// vs-deploy VSCode extension
27+
//
28+
// s. https://github.com/mkloubert/vs-deploy
29+
// for more information
30+
31+
const FS = require('fs');
32+
const Path = require('path');
33+
const vscode = require('vscode');
34+
35+
exports.deployWorkspace = function(args) {
36+
const FSExtra = args.require('fs-extra');
37+
38+
// workspace & 'releases' folders
39+
const WORKSPACE = Path.resolve(
40+
Path.join(__dirname, '../')
41+
);
42+
const RELEASES = Path.resolve(
43+
Path.join(__dirname, './releases')
44+
);
45+
46+
// package.json
47+
const PACKAGE_JSON_FILE = Path.resolve(
48+
Path.join(WORKSPACE, 'package.json')
49+
);
50+
const PACKAGE_JSON = JSON.parse(
51+
FS.readFileSync(PACKAGE_JSON_FILE)
52+
.toString('utf8')
53+
);
54+
55+
// module version
56+
const VERSION = ('' + PACKAGE_JSON.version).trim();
57+
58+
// output directory
59+
const OUT_DIR = Path.resolve(
60+
Path.join(RELEASES, VERSION)
61+
);
62+
63+
// keep sure to have a clean
64+
// and empty 'releases' folder
65+
if (FSExtra.existsSync(RELEASES)) {
66+
FSExtra.removeSync( RELEASES );
67+
}
68+
FSExtra.mkdirsSync( OUT_DIR );
69+
70+
// ${workspace}/js/enumerable.js
71+
const ENUMERABLE_JS = Path.resolve(
72+
Path.join(WORKSPACE, 'js/enumerable.js')
73+
);
74+
75+
for (let i = 0; i < args.files.length; i++) {
76+
try {
77+
args.onBeforeDeployFile(i);
78+
79+
const FILE = args.files[i];
80+
81+
const SOURCE_FILE = Path.resolve(FILE);
82+
const REL_PATH = Path.relative(WORKSPACE, SOURCE_FILE);
83+
84+
let targetFile;
85+
if (SOURCE_FILE === ENUMERABLE_JS) {
86+
// map 'js/enumerable.js'
87+
// to '/index.js' instead
88+
targetFile = Path.join(OUT_DIR, 'index.js');
89+
}
90+
else {
91+
targetFile = Path.join(OUT_DIR, REL_PATH);
92+
}
93+
targetFile = Path.resolve(targetFile);
94+
95+
// target directory for current file
96+
const TARGET_DIR = Path.resolve(
97+
Path.join(Path.dirname(targetFile))
98+
);
99+
if (!FSExtra.existsSync(TARGET_DIR)) {
100+
FSExtra.mkdirsSync( TARGET_DIR );
101+
}
102+
103+
// copy current file to target
104+
FSExtra.copySync(SOURCE_FILE, targetFile, {
105+
overwrite: false,
106+
errorOnExist: true,
107+
dereference: true
108+
});
109+
110+
args.onFileCompleted(i);
111+
}
112+
catch (e) {
113+
args.onFileCompleted(i, e);
114+
}
115+
}
116+
}

.deploy/github_pages.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// The MIT License (MIT)
2+
//
3+
// node-enumerable (https://github.com/mkloubert/node-enumerable)
4+
// Copyright (c) Marcel Joachim Kloubert <marcel.kloubert@gmx.net>
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to
8+
// deal in the Software without restriction, including without limitation the
9+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10+
// sell copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
// DEALINGS IN THE SOFTWARE.
23+
24+
25+
// this is a script target for
26+
// vs-deploy VSCode extension
27+
//
28+
// s. https://github.com/mkloubert/vs-deploy
29+
// for more information
30+
31+
const Path = require('path');
32+
const vscode = require('vscode');
33+
34+
exports.execute = function(args) {
35+
const FSExtra = args.require('fs-extra');
36+
37+
// workspace folder
38+
const WORKSPACE = Path.resolve(
39+
Path.join(__dirname, '../')
40+
);
41+
42+
// GitHub pages
43+
const GITHUB_PAGES = Path.resolve(
44+
Path.join(__dirname, '../mkloubert.github.io')
45+
);
46+
47+
// copy demo and playground page
48+
{
49+
const DEMO = Path.resolve(
50+
Path.join(WORKSPACE, 'demo')
51+
);
52+
53+
const GITHUB_PAGES_DEMOS = Path.resolve(
54+
Path.join(GITHUB_PAGES, 'demos/node-enumerable')
55+
);
56+
57+
if (FSExtra.existsSync(GITHUB_PAGES_DEMOS)) {
58+
FSExtra.removeSync(GITHUB_PAGES_DEMOS);
59+
}
60+
FSExtra.mkdirsSync(GITHUB_PAGES_DEMOS);
61+
62+
FSExtra.copySync(DEMO, GITHUB_PAGES_DEMOS);
63+
}
64+
65+
// copy documentation
66+
{
67+
const DOCS = Path.resolve(
68+
Path.join(WORKSPACE, 'docs')
69+
);
70+
71+
const GITHUB_PAGES_DOCS = Path.resolve(
72+
Path.join(GITHUB_PAGES, 'node-enumerable')
73+
);
74+
75+
if (FSExtra.existsSync(GITHUB_PAGES_DOCS)) {
76+
FSExtra.removeSync(GITHUB_PAGES_DOCS);
77+
}
78+
FSExtra.mkdirsSync(GITHUB_PAGES_DOCS);
79+
80+
FSExtra.copySync(DOCS, GITHUB_PAGES_DOCS);
81+
}
82+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
/node_modules
55
/pushall.sh
66
/typedoc.cmd
7+
/mkloubert.github.io/**
8+
/.deploy/releases/**
79
docs

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ index.ts
88
pushall.sh
99
tsconfig.json
1010
typedoc.cmd
11+
.deploy/**
12+
mkloubert.github.io/**

.vscode/settings.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
// s. https://github.com/mkloubert/vs-deploy
3+
"deploy": {
4+
"openOutputOnDeploy": false,
5+
"openOutputOnStartup": false,
6+
"showPopupOnSuccess": false,
7+
8+
"packages": [
9+
{
10+
"name": "GitHub",
11+
12+
"files": [
13+
"/demo/**",
14+
"/js/enumerable.js",
15+
"/CHANGELOG.md",
16+
"/index.d.ts",
17+
"/LICENSE.md",
18+
"/README.md"
19+
],
20+
21+
"targets": [ "GitHub Release" ]
22+
},
23+
{
24+
"name": "index.js",
25+
"description": "The NodeJS compatible generated file from 'index.ts'.",
26+
27+
"deployOnChange": {
28+
"files": [
29+
"/index.js"
30+
],
31+
"useTargetList": true
32+
},
33+
"files": [
34+
"/index.js"
35+
],
36+
37+
"targets": [ "enumerable.js" ],
38+
39+
"sortOrder": 1
40+
}
41+
],
42+
43+
"targets": [
44+
{
45+
"name": "GitHub Release",
46+
"type": "script",
47+
"script": "./.deploy/github.js",
48+
"deployed": [
49+
{
50+
"type": "script",
51+
"script": "./.deploy/github_pages.js"
52+
}
53+
]
54+
},
55+
{
56+
"name": "enumerable.js",
57+
"description": "Generates a browser compatible version of 'index.js' file.",
58+
"type": "script",
59+
"script": "./.deploy/copy_to_enumerableJS.js"
60+
}
61+
]
62+
}
63+
}

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log (node-enumerable)
22

3-
## 3.6.0 (November 5th, 2017; methods)
3+
## 3.7.0 (November 7th, 2017; methods)
4+
5+
* added `consume()` method
6+
7+
## 3.6.0 (November 6th, 2017; methods & functions)
48

59
* added `defaultArrayIfEmpty()` method
610
* added `exp()` method

0 commit comments

Comments
 (0)