@nzz/q-cli 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +18 -0
- package/bin/commands/bootstrap.js +34 -14
- package/bin/q.js +46 -3
- package/package.json +1 -1
- package/skeletons/custom-code-skeleton/tsconfig.json +12 -12
- package/skeletons/et-utils-package-skeleton/.nvmrc +1 -0
- package/skeletons/et-utils-package-skeleton/README.md +7 -0
- package/skeletons/et-utils-package-skeleton/package-lock.json +3969 -0
- package/skeletons/et-utils-package-skeleton/package.json +34 -0
- package/skeletons/et-utils-package-skeleton/rollup.config.js +17 -0
- package/skeletons/et-utils-package-skeleton/src/Service.ts +8 -0
- package/skeletons/et-utils-package-skeleton/src/index.ts +4 -0
- package/skeletons/et-utils-package-skeleton/test/Service.spec.ts +19 -0
- package/skeletons/et-utils-package-skeleton/tsconfig.json +9 -0
package/README.md
CHANGED
@@ -164,6 +164,24 @@ Q new-custom-code my-project-name
|
|
164
164
|
Q new-custom-code my-project-name -d my-project-directory
|
165
165
|
```
|
166
166
|
|
167
|
+
### Creating new ed-tech utility package project
|
168
|
+
|
169
|
+
Once `Q` cli is installed one can create the skeleton of a new ed-tech utility package project by executing
|
170
|
+
|
171
|
+
```bash
|
172
|
+
Q new-et-utils-package package-name package-author package-description
|
173
|
+
```
|
174
|
+
|
175
|
+
- The directory name where the new ed-tech utility package project is being created defaults to the project name and can be overwritten by using option `-d` or `--dir`
|
176
|
+
|
177
|
+
```bash
|
178
|
+
Q new-et-utils-package package-name -d my-project-directory
|
179
|
+
```
|
180
|
+
|
181
|
+
#### Notes
|
182
|
+
|
183
|
+
New utility package projects should only be created inside the [ed-tech-utilities](https://github.com/nzzdev/ed-tech-utilities) repository.
|
184
|
+
|
167
185
|
### Q item actions
|
168
186
|
|
169
187
|
The `Q` cli can copy and/or update existing Q items.
|
@@ -2,11 +2,19 @@ const fs = require("fs-extra");
|
|
2
2
|
const path = require("path");
|
3
3
|
const replaceInFile = require("replace-in-file");
|
4
4
|
const chalk = require("chalk");
|
5
|
+
const { replace } = require("nunjucks/src/filters");
|
5
6
|
const errorColor = chalk.red;
|
6
7
|
const successColor = chalk.green;
|
7
8
|
const warningColor = chalk.yellow;
|
8
9
|
|
9
|
-
|
10
|
+
/**
|
11
|
+
*
|
12
|
+
* @param {string} type - Skeleton type
|
13
|
+
* @param {string} name - Name of the project
|
14
|
+
* @param {string} basedir - Base directory name to be created
|
15
|
+
* @param {Array.<{regex: RegExp, replaceWith: string}>} textReplacements
|
16
|
+
*/
|
17
|
+
module.exports = async function (type, basedir, textReplacements) {
|
10
18
|
if (fs.existsSync(basedir)) {
|
11
19
|
console.error(
|
12
20
|
errorColor(`directory ${basedir} already exists or is not writable`)
|
@@ -16,34 +24,46 @@ module.exports = async function (type, name, basedir) {
|
|
16
24
|
fs.mkdirSync(basedir);
|
17
25
|
}
|
18
26
|
|
19
|
-
const replaceOptions = {
|
20
|
-
files: `${basedir}/**`,
|
21
|
-
from: new RegExp(`${type}-skeleton`, "g"),
|
22
|
-
to: name,
|
23
|
-
glob: {
|
24
|
-
dot: true, // Include file names starting with a dot
|
25
|
-
},
|
26
|
-
};
|
27
|
-
|
28
27
|
try {
|
29
28
|
await fs.copySync(
|
30
29
|
path.join(__dirname, `../../skeletons/${type}-skeleton`),
|
31
30
|
basedir
|
32
31
|
);
|
33
|
-
|
32
|
+
|
33
|
+
if (textReplacements) {
|
34
|
+
for (const txtRe of textReplacements) {
|
35
|
+
await replaceText(txtRe.regex, txtRe.replaceWith, basedir);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
34
39
|
console.log(successColor(`Q ${type} is now bootstrapped in ${basedir}`));
|
35
40
|
|
36
|
-
if (type === "tool")
|
41
|
+
if (type === "tool" || type === "et-utils-package")
|
37
42
|
console.log(
|
38
|
-
warningColor(
|
43
|
+
warningColor(
|
44
|
+
"Search for 'TODO' inside the new tool/package to get started!"
|
45
|
+
)
|
39
46
|
);
|
40
47
|
} catch (error) {
|
41
48
|
console.error(
|
42
49
|
errorColor(
|
43
|
-
`An unexpected error
|
50
|
+
`An unexpected error occurred. Please check the entered information and try again. ${JSON.stringify(
|
44
51
|
error
|
45
52
|
)}`
|
46
53
|
)
|
47
54
|
);
|
48
55
|
}
|
49
56
|
};
|
57
|
+
|
58
|
+
async function replaceText(regex, replaceWith, basedir) {
|
59
|
+
const replaceOptions = {
|
60
|
+
files: `${basedir}/**`, // Replace in all files
|
61
|
+
from: regex,
|
62
|
+
to: replaceWith,
|
63
|
+
glob: {
|
64
|
+
dot: true, // Include file names starting with a dot
|
65
|
+
},
|
66
|
+
};
|
67
|
+
|
68
|
+
return await replaceInFile(replaceOptions);
|
69
|
+
}
|
package/bin/q.js
CHANGED
@@ -46,7 +46,11 @@ async function main() {
|
|
46
46
|
process.exit(1);
|
47
47
|
}
|
48
48
|
const baseDir = program.dir || name;
|
49
|
-
|
49
|
+
const textReplacements = [
|
50
|
+
{ regex: new RegExp(`${type}-skeleton`, "g"), replaceWith: name },
|
51
|
+
];
|
52
|
+
|
53
|
+
await bootstrap("server", baseDir, textReplacements);
|
50
54
|
});
|
51
55
|
|
52
56
|
program
|
@@ -63,7 +67,11 @@ async function main() {
|
|
63
67
|
process.exit(1);
|
64
68
|
}
|
65
69
|
const baseDir = program.dir || name;
|
66
|
-
|
70
|
+
const textReplacements = [
|
71
|
+
{ regex: new RegExp(`${type}-skeleton`, "g"), replaceWith: name },
|
72
|
+
];
|
73
|
+
|
74
|
+
await bootstrap("tool", baseDir, textReplacements);
|
67
75
|
});
|
68
76
|
|
69
77
|
program
|
@@ -80,7 +88,42 @@ async function main() {
|
|
80
88
|
process.exit(1);
|
81
89
|
}
|
82
90
|
const baseDir = program.dir || name;
|
83
|
-
|
91
|
+
const textReplacements = [
|
92
|
+
{ regex: new RegExp(`${type}-skeleton`, "g"), replaceWith: name },
|
93
|
+
];
|
94
|
+
|
95
|
+
await bootstrap("custom-code", baseDir, textReplacements);
|
96
|
+
});
|
97
|
+
|
98
|
+
program
|
99
|
+
.command("new-et-utils-package")
|
100
|
+
.option(
|
101
|
+
"-d, --dir <path>",
|
102
|
+
"the base directory to bootstrap the new tool in, defaults to the tools name"
|
103
|
+
)
|
104
|
+
.description("bootstrap a new ed-tech utility package")
|
105
|
+
.action(async () => {
|
106
|
+
const name = program.args[1];
|
107
|
+
const author = program.args[2] || "TODO: Set package author name";
|
108
|
+
const description =
|
109
|
+
program.args[3] || "TODO: Write a package description";
|
110
|
+
|
111
|
+
if (!name) {
|
112
|
+
console.error(errorColor("no package name given"));
|
113
|
+
process.exit(1);
|
114
|
+
}
|
115
|
+
|
116
|
+
const baseDir = program.dir || name;
|
117
|
+
const textReplacements = [
|
118
|
+
{ regex: new RegExp("<package-name>", "g"), replaceWith: name },
|
119
|
+
{ regex: new RegExp("<author-name>", "g"), replaceWith: author },
|
120
|
+
{
|
121
|
+
regex: new RegExp("<package-description>", "g"),
|
122
|
+
replaceWith: description,
|
123
|
+
},
|
124
|
+
];
|
125
|
+
|
126
|
+
await bootstrap("et-utils-package", baseDir, textReplacements);
|
84
127
|
});
|
85
128
|
|
86
129
|
program
|
package/package.json
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
2
|
+
"extends": "@tsconfig/svelte/tsconfig.json",
|
3
|
+
"include": ["src/**/*"],
|
4
|
+
"exclude": ["node_modules/*", "__sapper__/*", "public/*"],
|
5
|
+
"compilerOptions": {
|
6
|
+
"lib": ["es2015", "DOM"],
|
7
|
+
"types": ["svelte"],
|
8
|
+
"outDir": "public",
|
9
|
+
"declaration": false,
|
10
|
+
"paths": {
|
11
|
+
"@src": ["./src/"],
|
12
|
+
"@interfaces": ["./src/interfaces.ts"]
|
14
13
|
}
|
14
|
+
}
|
15
15
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
16
|