init-workspace-cervvaljs 0.1.6 → 0.2.0
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/README.md +1 -1
- package/bin/_build/tsc/src/index.js +168 -0
- package/bin/index.js +31 -18
- package/package.json +1 -1
- package/workspace/_package.json +14 -6
package/README.md
CHANGED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.cli = void 0;
|
|
28
|
+
const child_process_1 = require("child_process");
|
|
29
|
+
const fs = __importStar(require("fs"));
|
|
30
|
+
const path = __importStar(require("path"));
|
|
31
|
+
// console colors
|
|
32
|
+
const FgRed = "\x1b[31m";
|
|
33
|
+
const FgGreen = "\x1b[32m";
|
|
34
|
+
const FgBlue = "\x1b[34m";
|
|
35
|
+
const FgReset = "\x1b[0m";
|
|
36
|
+
/**
|
|
37
|
+
* execSync with standard input outputs
|
|
38
|
+
*/
|
|
39
|
+
function execSyncWithIo(cmd) {
|
|
40
|
+
return (0, child_process_1.execSync)(cmd, { stdio: "inherit" });
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Init workspace
|
|
44
|
+
* install pnpm globally
|
|
45
|
+
* create pnpm workspace
|
|
46
|
+
* create workspace package.json
|
|
47
|
+
* @param options options
|
|
48
|
+
* @param options.dry if true, init will be simulated but not executed
|
|
49
|
+
* @param options.update if true, init will be done even if config files are already present
|
|
50
|
+
* @param options.pnpmVersion if given, fix version of pnpm
|
|
51
|
+
*/
|
|
52
|
+
function initWorkspace(options) {
|
|
53
|
+
// check if user is on Windows & current path contains spaces
|
|
54
|
+
const operatingSystem = process.platform;
|
|
55
|
+
const currentPath = process.cwd();
|
|
56
|
+
if (operatingSystem === "win32" && /\s/.test(currentPath)) {
|
|
57
|
+
console.error(FgRed + "Your workspace path should not contain any whitespaces when using Windows", FgReset);
|
|
58
|
+
process.exit(4 /* ErrorCodes.WRONG_PATH_FORMAT */);
|
|
59
|
+
}
|
|
60
|
+
// check Node Version
|
|
61
|
+
let nodeVersionStr = process.version.toLowerCase();
|
|
62
|
+
if (nodeVersionStr.startsWith("v")) {
|
|
63
|
+
nodeVersionStr = nodeVersionStr.substring(1);
|
|
64
|
+
}
|
|
65
|
+
const nodeMainVersion = Number(nodeVersionStr.substring(0, nodeVersionStr.indexOf(".")));
|
|
66
|
+
console.info("* Node version", nodeMainVersion, "(" + process.version + ")");
|
|
67
|
+
if (nodeMainVersion < 14) {
|
|
68
|
+
console.error(FgRed + "Node version 14 or above is required, init aborted", FgReset);
|
|
69
|
+
console.info("1. Install NVM");
|
|
70
|
+
console.info(" Linux: https://github.com/nvm-sh/nvm");
|
|
71
|
+
console.info(" Windows: https://github.com/coreybutler/nvm-windows");
|
|
72
|
+
console.info("2. Install Node");
|
|
73
|
+
console.info(" nvm install 14.17.0");
|
|
74
|
+
console.info(" nvm use 14.17.0");
|
|
75
|
+
process.exit(1 /* ErrorCodes.WRONG_NODE */);
|
|
76
|
+
}
|
|
77
|
+
// check config files are not already in current folder
|
|
78
|
+
const configFiles = ["package.json", "pnpm-workspace.yaml"];
|
|
79
|
+
{
|
|
80
|
+
for (const cf of configFiles) {
|
|
81
|
+
if (fs.existsSync("./" + cf)) {
|
|
82
|
+
if (!(options === null || options === void 0 ? void 0 : options.update)) {
|
|
83
|
+
console.error(FgRed + cf + " found - init cancelled", FgReset);
|
|
84
|
+
process.exit(2 /* ErrorCodes.INIT_BUT_FILE_EXISTS */);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (options === null || options === void 0 ? void 0 : options.update) {
|
|
88
|
+
console.error(FgRed + cf + " was not found");
|
|
89
|
+
console.error(FgRed + "- Are you at the workspace root ?", FgReset);
|
|
90
|
+
console.error(FgRed + "- Do you want to initialize a new workspace ? then you need to remove --update", FgReset);
|
|
91
|
+
process.exit(3 /* ErrorCodes.UPDATE_BUT_FILE_DOES_NOT_EXIST */);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Install pnpm
|
|
96
|
+
const pnpmFixedVersion = options.pnpmVersion ? "@^" + options.pnpmVersion : "";
|
|
97
|
+
if (!(options === null || options === void 0 ? void 0 : options.update)) {
|
|
98
|
+
console.info("* install pnpm : npm install -g pnpm" + pnpmFixedVersion);
|
|
99
|
+
if (!(options === null || options === void 0 ? void 0 : options.dry)) {
|
|
100
|
+
execSyncWithIo("npm install -g pnpm" + pnpmFixedVersion);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
console.info("* update pnpm : pnpm add -g pnpm" + pnpmFixedVersion);
|
|
105
|
+
if (!(options === null || options === void 0 ? void 0 : options.dry)) {
|
|
106
|
+
execSyncWithIo("pnpm add -g pnpm" + pnpmFixedVersion);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
console.info("* display pnpm version : pnpm -v");
|
|
110
|
+
execSyncWithIo("pnpm -v");
|
|
111
|
+
// install lpx globally
|
|
112
|
+
console.info("* " + (!(options === null || options === void 0 ? void 0 : options.update) ? "install" : "update") + " lpx globally : pnpm add -g lpx");
|
|
113
|
+
if (!(options === null || options === void 0 ? void 0 : options.dry)) {
|
|
114
|
+
execSyncWithIo("pnpm add -g lpx");
|
|
115
|
+
}
|
|
116
|
+
// create configuration files
|
|
117
|
+
const from = path.resolve(__dirname, "../workspace") + "/_";
|
|
118
|
+
for (const cf of configFiles) {
|
|
119
|
+
console.info("* copy", path.resolve(from + cf), " => ", path.resolve("./" + cf));
|
|
120
|
+
if (!(options === null || options === void 0 ? void 0 : options.dry)) {
|
|
121
|
+
fs.copyFileSync(from + cf, "./" + cf);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// create nvmrc
|
|
125
|
+
if (!fs.existsSync("./.nvmrc")) {
|
|
126
|
+
console.info("*", process.version, "> .nvmrc");
|
|
127
|
+
if (!(options === null || options === void 0 ? void 0 : options.dry)) {
|
|
128
|
+
fs.writeFileSync("./.nvmrc", process.version);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (!(options === null || options === void 0 ? void 0 : options.update)) {
|
|
132
|
+
// install packages
|
|
133
|
+
console.info("* init done, you can now checkout cervval.js and install packages");
|
|
134
|
+
console.info("git clone https://git.cervval.com/CERVVAL/cervval.js.git");
|
|
135
|
+
console.info("pnpm install");
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
console.info(FgBlue + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
139
|
+
console.info(FgBlue + "*update done, you can now install packages");
|
|
140
|
+
console.info(FgGreen + "pnpm install", FgReset);
|
|
141
|
+
}
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* parses command arguments and inits workspace in current working directory
|
|
146
|
+
*/
|
|
147
|
+
function cli() {
|
|
148
|
+
const options = { dry: false, update: false, pnpmVersion: "6.32.11" };
|
|
149
|
+
const args = process.argv.slice(2);
|
|
150
|
+
if (args.includes("--dry")) {
|
|
151
|
+
console.info("* dry mode on");
|
|
152
|
+
options.dry = true;
|
|
153
|
+
}
|
|
154
|
+
if (args.includes("--update")) {
|
|
155
|
+
console.info("* update mode on");
|
|
156
|
+
options.update = true;
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
initWorkspace(options);
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
console.error(err);
|
|
163
|
+
process.exit(99 /* ErrorCodes.UNEXPECTED */);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.cli = cli;
|
|
167
|
+
cli();
|
|
168
|
+
//# sourceMappingURL=index.js.map
|
package/bin/index.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function (o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.
|
|
6
|
-
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function () { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function (o, m, k, k2) {
|
|
7
11
|
if (k2 === undefined) k2 = k;
|
|
8
12
|
o[k2] = m[k];
|
|
9
13
|
}));
|
|
10
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function (o, v) {
|
|
11
15
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12
|
-
}) : function(o, v) {
|
|
16
|
+
}) : function (o, v) {
|
|
13
17
|
o["default"] = v;
|
|
14
18
|
});
|
|
15
19
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
@@ -21,9 +25,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
21
25
|
};
|
|
22
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
27
|
exports.cli = void 0;
|
|
24
|
-
const path = __importStar(require("path"));
|
|
25
|
-
const fs = __importStar(require("fs"));
|
|
26
28
|
const child_process_1 = require("child_process");
|
|
29
|
+
const fs = __importStar(require("fs"));
|
|
30
|
+
const path = __importStar(require("path"));
|
|
27
31
|
// console colors
|
|
28
32
|
const FgRed = "\x1b[31m";
|
|
29
33
|
const FgGreen = "\x1b[32m";
|
|
@@ -33,7 +37,7 @@ const FgReset = "\x1b[0m";
|
|
|
33
37
|
* execSync with standard input outputs
|
|
34
38
|
*/
|
|
35
39
|
function execSyncWithIo(cmd) {
|
|
36
|
-
return child_process_1.execSync(cmd, { stdio: "inherit" });
|
|
40
|
+
return (0, child_process_1.execSync)(cmd, { stdio: "inherit" });
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
43
|
* Init workspace
|
|
@@ -43,8 +47,16 @@ function execSyncWithIo(cmd) {
|
|
|
43
47
|
* @param options options
|
|
44
48
|
* @param options.dry if true, init will be simulated but not executed
|
|
45
49
|
* @param options.update if true, init will be done even if config files are already present
|
|
50
|
+
* @param options.pnpmVersion if given, fix version of pnpm
|
|
46
51
|
*/
|
|
47
52
|
function initWorkspace(options) {
|
|
53
|
+
// check if user is on Windows & current path contains spaces
|
|
54
|
+
const operatingSystem = process.platform;
|
|
55
|
+
const currentPath = process.cwd();
|
|
56
|
+
if (operatingSystem === "win32" && /\s/.test(currentPath)) {
|
|
57
|
+
console.error(FgRed + "Your workspace path should not contain any whitespaces when using Windows", FgReset);
|
|
58
|
+
process.exit(4 /* ErrorCodes.WRONG_PATH_FORMAT */);
|
|
59
|
+
}
|
|
48
60
|
// check Node Version
|
|
49
61
|
let nodeVersionStr = process.version.toLowerCase();
|
|
50
62
|
if (nodeVersionStr.startsWith("v")) {
|
|
@@ -60,7 +72,7 @@ function initWorkspace(options) {
|
|
|
60
72
|
console.info("2. Install Node");
|
|
61
73
|
console.info(" nvm install 14.17.0");
|
|
62
74
|
console.info(" nvm use 14.17.0");
|
|
63
|
-
process.exit(1 /* WRONG_NODE */);
|
|
75
|
+
process.exit(1 /* ErrorCodes.WRONG_NODE */);
|
|
64
76
|
}
|
|
65
77
|
// check config files are not already in current folder
|
|
66
78
|
const configFiles = ["package.json", "pnpm-workspace.yaml"];
|
|
@@ -69,28 +81,29 @@ function initWorkspace(options) {
|
|
|
69
81
|
if (fs.existsSync("./" + cf)) {
|
|
70
82
|
if (!(options === null || options === void 0 ? void 0 : options.update)) {
|
|
71
83
|
console.error(FgRed + cf + " found - init cancelled", FgReset);
|
|
72
|
-
process.exit(2 /* INIT_BUT_FILE_EXISTS */);
|
|
84
|
+
process.exit(2 /* ErrorCodes.INIT_BUT_FILE_EXISTS */);
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
else if (options === null || options === void 0 ? void 0 : options.update) {
|
|
76
88
|
console.error(FgRed + cf + " was not found");
|
|
77
89
|
console.error(FgRed + "- Are you at the workspace root ?", FgReset);
|
|
78
90
|
console.error(FgRed + "- Do you want to initialize a new workspace ? then you need to remove --update", FgReset);
|
|
79
|
-
process.exit(3 /* UPDATE_BUT_FILE_DOES_NOT_EXIST */);
|
|
91
|
+
process.exit(3 /* ErrorCodes.UPDATE_BUT_FILE_DOES_NOT_EXIST */);
|
|
80
92
|
}
|
|
81
93
|
}
|
|
82
94
|
}
|
|
83
|
-
//
|
|
95
|
+
// Install pnpm
|
|
96
|
+
const pnpmFixedVersion = options.pnpmVersion ? "@^" + options.pnpmVersion : "";
|
|
84
97
|
if (!(options === null || options === void 0 ? void 0 : options.update)) {
|
|
85
|
-
console.info("* install pnpm : npm install -g pnpm");
|
|
98
|
+
console.info("* install pnpm : npm install -g pnpm" + pnpmFixedVersion);
|
|
86
99
|
if (!(options === null || options === void 0 ? void 0 : options.dry)) {
|
|
87
|
-
execSyncWithIo("npm install -g pnpm");
|
|
100
|
+
execSyncWithIo("npm install -g pnpm" + pnpmFixedVersion);
|
|
88
101
|
}
|
|
89
102
|
}
|
|
90
103
|
else {
|
|
91
|
-
console.info("* update pnpm : pnpm add -g pnpm");
|
|
104
|
+
console.info("* update pnpm : pnpm add -g pnpm" + pnpmFixedVersion);
|
|
92
105
|
if (!(options === null || options === void 0 ? void 0 : options.dry)) {
|
|
93
|
-
execSyncWithIo("pnpm add -g pnpm");
|
|
106
|
+
execSyncWithIo("pnpm add -g pnpm" + pnpmFixedVersion);
|
|
94
107
|
}
|
|
95
108
|
}
|
|
96
109
|
console.info("* display pnpm version : pnpm -v");
|
|
@@ -132,7 +145,7 @@ function initWorkspace(options) {
|
|
|
132
145
|
* parses command arguments and inits workspace in current working directory
|
|
133
146
|
*/
|
|
134
147
|
function cli() {
|
|
135
|
-
const options = { dry: false, update: false };
|
|
148
|
+
const options = { dry: false, update: false, pnpmVersion: "8.6.1" };
|
|
136
149
|
const args = process.argv.slice(2);
|
|
137
150
|
if (args.includes("--dry")) {
|
|
138
151
|
console.info("* dry mode on");
|
|
@@ -147,7 +160,7 @@ function cli() {
|
|
|
147
160
|
}
|
|
148
161
|
catch (err) {
|
|
149
162
|
console.error(err);
|
|
150
|
-
process.exit(99 /* UNEXPECTED */);
|
|
163
|
+
process.exit(99 /* ErrorCodes.UNEXPECTED */);
|
|
151
164
|
}
|
|
152
165
|
}
|
|
153
166
|
exports.cli = cli;
|
package/package.json
CHANGED
package/workspace/_package.json
CHANGED
|
@@ -8,17 +8,25 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"clean-node-modules": "rimraf **/node_modules",
|
|
11
|
-
"
|
|
11
|
+
"clean-locks": "rimraf **/pnpm-lock.yaml",
|
|
12
|
+
"postinstall": "cwt rewrite-tsconfig-references",
|
|
13
|
+
"lint": "eslint --ext -r .ts"
|
|
12
14
|
},
|
|
13
|
-
"dependencies": {},
|
|
14
15
|
"devDependencies": {
|
|
15
|
-
"@cervval.js/builder": "latest",
|
|
16
|
-
"@cervval.js/eslint-config-cervvaljs": "latest",
|
|
16
|
+
"@cervval.js/builder": "workspace:latest",
|
|
17
|
+
"@cervval.js/eslint-config-cervvaljs": "workspace:latest",
|
|
18
|
+
"@types/chai": "^4.2.21",
|
|
19
|
+
"@types/cjs-common": "workspace:latest",
|
|
17
20
|
"@types/mocha": "^8.2.2",
|
|
18
|
-
"chai": "^4.3.4"
|
|
21
|
+
"chai": "^4.3.4",
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "5.59.5",
|
|
23
|
+
"@typescript-eslint/parser": "5.59.5",
|
|
24
|
+
"eslint": "8.40.0",
|
|
25
|
+
"@types/eslint": "8.40.0",
|
|
26
|
+
"eslint-plugin-jsdoc": "46.2.6"
|
|
19
27
|
},
|
|
20
28
|
"eslintConfig": {
|
|
21
29
|
"extends": "@cervval.js/eslint-config-cervvaljs"
|
|
22
30
|
},
|
|
23
|
-
"version": "0.
|
|
31
|
+
"version": "0.2.0"
|
|
24
32
|
}
|