@featurevisor/cli 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +66 -0
- package/bin.js +3 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +148 -0
- package/lib/index.js.map +1 -0
- package/package.json +54 -0
- package/src/index.ts +116 -0
- package/tsconfig.cjs.json +7 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.0.3](https://github.com/fahad19/featurevisor/compare/v0.0.2...v0.0.3) (2023-03-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* publish access ([ea5cd7c](https://github.com/fahad19/featurevisor/commit/ea5cd7cd8554e2def5fdcc1d3488598a08e99bfa))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.0.2](https://github.com/fahad19/featurevisor/compare/v0.0.1...v0.0.2) (2023-03-05)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* cli package ([5aeca09](https://github.com/fahad19/featurevisor/commit/5aeca098a02afcd16c5327dc94a286006f618d60))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## 0.0.1 (2023-03-05)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* linting ([230bfa0](https://github.com/fahad19/featurevisor/commit/230bfa0824f79181581585ccc37c2e78c5aeac42))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Fahad Heylaal (https://fahad19.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.
|
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @featurevisor/cli
|
|
2
|
+
|
|
3
|
+
CLI package of Featurevisor.
|
|
4
|
+
|
|
5
|
+
Visit [https://featurevisor.com](https://featurevisor.com) for more information.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
$ npm install -g @featurevisor/cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or via `npx`:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
$ npx featurevisor <command>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### `init`
|
|
22
|
+
|
|
23
|
+
Initialize your project.
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
$ featurevisor init
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
If you want to initialize your project with a specific example:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
$ featurevisor init --example <name>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Examples found [here](../../examples).
|
|
36
|
+
|
|
37
|
+
### `lint`
|
|
38
|
+
|
|
39
|
+
Check if your YAMLs are valid.
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
$ featurevisor lint
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### `build`
|
|
47
|
+
|
|
48
|
+
Build your datafiles.
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
$ featurevisor build
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### `test`
|
|
55
|
+
|
|
56
|
+
Test your generated datafiles using the SDK, against specs written in YAMLs.
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
$ featurevisor test
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
See test specs in YAMLs [here](../../examples/example-1/tests) for inspiration.
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT © [Fahad Heylaal](https://fahad19.com)
|
package/bin.js
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var fs = require("fs");
|
|
40
|
+
var path = require("path");
|
|
41
|
+
var yargs = require("yargs");
|
|
42
|
+
var core_1 = require("@featurevisor/core");
|
|
43
|
+
process.on("unhandledRejection", function (reason, p) {
|
|
44
|
+
console.error(reason);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
});
|
|
47
|
+
function requireConfigFile(configModulePath) {
|
|
48
|
+
if (!fs.existsSync(configModulePath)) {
|
|
49
|
+
console.error("No config file found. Please create `featurevisor.config.js` file first.");
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function requireAndGetProjectConfig(rootDirectoryPath) {
|
|
54
|
+
var configModulePath = path.join(rootDirectoryPath, core_1.CONFIG_MODULE_NAME);
|
|
55
|
+
requireConfigFile(configModulePath);
|
|
56
|
+
return (0, core_1.getProjectConfig)(rootDirectoryPath);
|
|
57
|
+
}
|
|
58
|
+
function main() {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
+
var rootDirectoryPath;
|
|
61
|
+
return __generator(this, function (_a) {
|
|
62
|
+
rootDirectoryPath = process.cwd();
|
|
63
|
+
yargs(process.argv.slice(2))
|
|
64
|
+
.usage("Usage: <command> [options]")
|
|
65
|
+
/**
|
|
66
|
+
* Commands
|
|
67
|
+
*/
|
|
68
|
+
.command({
|
|
69
|
+
command: "init",
|
|
70
|
+
handler: function (options) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
+
var hasError;
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0: return [4 /*yield*/, (0, core_1.initProject)(rootDirectoryPath, options.example)];
|
|
76
|
+
case 1:
|
|
77
|
+
hasError = _a.sent();
|
|
78
|
+
if (hasError) {
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
})
|
|
87
|
+
.example("$0 init", "scaffold a new project")
|
|
88
|
+
.example("$0 init --example=exampleName", "scaffold a new project from known example")
|
|
89
|
+
.command({
|
|
90
|
+
command: "lint",
|
|
91
|
+
handler: function (options) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
var projectConfig, hasError;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0:
|
|
97
|
+
projectConfig = requireAndGetProjectConfig(rootDirectoryPath);
|
|
98
|
+
return [4 /*yield*/, (0, core_1.lintProject)(projectConfig)];
|
|
99
|
+
case 1:
|
|
100
|
+
hasError = _a.sent();
|
|
101
|
+
if (hasError) {
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
return [2 /*return*/];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
.example("$0 lint", "lint all YAML file content")
|
|
111
|
+
.command({
|
|
112
|
+
command: "build",
|
|
113
|
+
handler: function (options) {
|
|
114
|
+
var projectConfig = requireAndGetProjectConfig(rootDirectoryPath);
|
|
115
|
+
(0, core_1.buildProject)(rootDirectoryPath, projectConfig);
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
.example("$0 build", "build datafiles")
|
|
119
|
+
.command({
|
|
120
|
+
command: "test",
|
|
121
|
+
handler: function (options) {
|
|
122
|
+
var projectConfig = requireAndGetProjectConfig(rootDirectoryPath);
|
|
123
|
+
var hasError = (0, core_1.testProject)(rootDirectoryPath, projectConfig);
|
|
124
|
+
if (hasError) {
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
.example("$0 test", "test features")
|
|
130
|
+
/**
|
|
131
|
+
* Options
|
|
132
|
+
*/
|
|
133
|
+
// @TODO: add --config option
|
|
134
|
+
/**
|
|
135
|
+
* Help
|
|
136
|
+
*/
|
|
137
|
+
.command({
|
|
138
|
+
command: "*",
|
|
139
|
+
handler: function () {
|
|
140
|
+
yargs.showHelp();
|
|
141
|
+
},
|
|
142
|
+
}).argv;
|
|
143
|
+
return [2 /*return*/];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
main();
|
|
148
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@featurevisor/cli",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "CLI package of Featurevisor",
|
|
5
|
+
"main": "bin.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"featurevisor": "bin.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"lint": "echo 'not linting in this package yet'",
|
|
12
|
+
"transpile": "rimraf lib && tsc --project tsconfig.cjs.json",
|
|
13
|
+
"dist": "echo 'Nothing to dist here'",
|
|
14
|
+
"build": "npm run transpile",
|
|
15
|
+
"test": "echo 'Nothing to test in this package'"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://featurevisor.com",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"featurevisor",
|
|
20
|
+
"feature",
|
|
21
|
+
"features",
|
|
22
|
+
"flags",
|
|
23
|
+
"feature flags",
|
|
24
|
+
"feature toggles",
|
|
25
|
+
"feature management",
|
|
26
|
+
"experimentation",
|
|
27
|
+
"experiment",
|
|
28
|
+
"experiments"
|
|
29
|
+
],
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/fahad19/featurevisor.git"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/fahad19/featurevisor/issues"
|
|
40
|
+
},
|
|
41
|
+
"author": {
|
|
42
|
+
"name": "Fahad Heylaal",
|
|
43
|
+
"url": "https://fahad19.com"
|
|
44
|
+
},
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@featurevisor/core": "^0.0.3",
|
|
48
|
+
"yargs": "^17.6.2"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/yargs": "^17.0.22"
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "303aca84f7c32163cb1079513d799296bd892e72"
|
|
54
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
|
|
4
|
+
import * as yargs from "yargs";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
CONFIG_MODULE_NAME,
|
|
8
|
+
getProjectConfig,
|
|
9
|
+
lintProject,
|
|
10
|
+
testProject,
|
|
11
|
+
buildProject,
|
|
12
|
+
initProject,
|
|
13
|
+
} from "@featurevisor/core";
|
|
14
|
+
|
|
15
|
+
process.on("unhandledRejection", (reason, p) => {
|
|
16
|
+
console.error(reason);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function requireConfigFile(configModulePath) {
|
|
21
|
+
if (!fs.existsSync(configModulePath)) {
|
|
22
|
+
console.error("No config file found. Please create `featurevisor.config.js` file first.");
|
|
23
|
+
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function requireAndGetProjectConfig(rootDirectoryPath) {
|
|
29
|
+
const configModulePath = path.join(rootDirectoryPath, CONFIG_MODULE_NAME);
|
|
30
|
+
|
|
31
|
+
requireConfigFile(configModulePath);
|
|
32
|
+
|
|
33
|
+
return getProjectConfig(rootDirectoryPath);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function main() {
|
|
37
|
+
const rootDirectoryPath = process.cwd();
|
|
38
|
+
|
|
39
|
+
yargs(process.argv.slice(2))
|
|
40
|
+
.usage("Usage: <command> [options]")
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Commands
|
|
44
|
+
*/
|
|
45
|
+
.command({
|
|
46
|
+
command: "init",
|
|
47
|
+
handler: async function (options) {
|
|
48
|
+
const hasError = await initProject(rootDirectoryPath, options.example);
|
|
49
|
+
|
|
50
|
+
if (hasError) {
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
.example("$0 init", "scaffold a new project")
|
|
56
|
+
.example("$0 init --example=exampleName", "scaffold a new project from known example")
|
|
57
|
+
|
|
58
|
+
.command({
|
|
59
|
+
command: "lint",
|
|
60
|
+
handler: async function (options) {
|
|
61
|
+
const projectConfig = requireAndGetProjectConfig(rootDirectoryPath);
|
|
62
|
+
|
|
63
|
+
const hasError = await lintProject(projectConfig);
|
|
64
|
+
|
|
65
|
+
if (hasError) {
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
.example("$0 lint", "lint all YAML file content")
|
|
71
|
+
|
|
72
|
+
.command({
|
|
73
|
+
command: "build",
|
|
74
|
+
handler: function (options) {
|
|
75
|
+
const projectConfig = requireAndGetProjectConfig(rootDirectoryPath);
|
|
76
|
+
|
|
77
|
+
buildProject(rootDirectoryPath, projectConfig);
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
.example("$0 build", "build datafiles")
|
|
81
|
+
|
|
82
|
+
.command({
|
|
83
|
+
command: "test",
|
|
84
|
+
handler: function (options) {
|
|
85
|
+
const projectConfig = requireAndGetProjectConfig(rootDirectoryPath);
|
|
86
|
+
|
|
87
|
+
const hasError = testProject(rootDirectoryPath, projectConfig);
|
|
88
|
+
|
|
89
|
+
if (hasError) {
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
.example("$0 test", "test features")
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Options
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
// @TODO: add --config option
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Help
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
.command({
|
|
107
|
+
command: "*",
|
|
108
|
+
handler() {
|
|
109
|
+
yargs.showHelp();
|
|
110
|
+
},
|
|
111
|
+
}).argv;
|
|
112
|
+
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
main();
|