create-orioro 0.0.1
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 +10 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.mjs +304 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +164 -0
- package/dist/index.mjs +162 -0
- package/package.json +43 -0
package/README.md
ADDED
package/dist/cli.d.ts
ADDED
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { join, basename, resolve } from 'node:path';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import * as prompts from '@clack/prompts';
|
|
5
|
+
import { statSync, readFileSync, writeFileSync, readdirSync } from 'node:fs';
|
|
6
|
+
import degit from 'degit';
|
|
7
|
+
|
|
8
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) {
|
|
10
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
11
|
+
resolve(value);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) {
|
|
16
|
+
try {
|
|
17
|
+
step(generator.next(value));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
reject(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function rejected(value) {
|
|
23
|
+
try {
|
|
24
|
+
step(generator["throw"](value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function step(result) {
|
|
30
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
31
|
+
}
|
|
32
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function __generator(thisArg, body) {
|
|
36
|
+
var _ = {
|
|
37
|
+
label: 0,
|
|
38
|
+
sent: function sent() {
|
|
39
|
+
if (t[0] & 1) throw t[1];
|
|
40
|
+
return t[1];
|
|
41
|
+
},
|
|
42
|
+
trys: [],
|
|
43
|
+
ops: []
|
|
44
|
+
},
|
|
45
|
+
f,
|
|
46
|
+
y,
|
|
47
|
+
t,
|
|
48
|
+
g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
49
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
50
|
+
return this;
|
|
51
|
+
}), g;
|
|
52
|
+
function verb(n) {
|
|
53
|
+
return function (v) {
|
|
54
|
+
return step([n, v]);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function step(op) {
|
|
58
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
59
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
60
|
+
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;
|
|
61
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
62
|
+
switch (op[0]) {
|
|
63
|
+
case 0:
|
|
64
|
+
case 1:
|
|
65
|
+
t = op;
|
|
66
|
+
break;
|
|
67
|
+
case 4:
|
|
68
|
+
_.label++;
|
|
69
|
+
return {
|
|
70
|
+
value: op[1],
|
|
71
|
+
done: false
|
|
72
|
+
};
|
|
73
|
+
case 5:
|
|
74
|
+
_.label++;
|
|
75
|
+
y = op[1];
|
|
76
|
+
op = [0];
|
|
77
|
+
continue;
|
|
78
|
+
case 7:
|
|
79
|
+
op = _.ops.pop();
|
|
80
|
+
_.trys.pop();
|
|
81
|
+
continue;
|
|
82
|
+
default:
|
|
83
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
84
|
+
_ = 0;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
88
|
+
_.label = op[1];
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
92
|
+
_.label = t[1];
|
|
93
|
+
t = op;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
if (t && _.label < t[2]) {
|
|
97
|
+
_.label = t[2];
|
|
98
|
+
_.ops.push(op);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
if (t[2]) _.ops.pop();
|
|
102
|
+
_.trys.pop();
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
op = body.call(thisArg, _);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
op = [6, e];
|
|
108
|
+
y = 0;
|
|
109
|
+
} finally {
|
|
110
|
+
f = t = 0;
|
|
111
|
+
}
|
|
112
|
+
if (op[0] & 5) throw op[1];
|
|
113
|
+
return {
|
|
114
|
+
value: op[0] ? op[1] : void 0,
|
|
115
|
+
done: true
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function __spreadArray(to, from, pack) {
|
|
120
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
121
|
+
if (ar || !(i in from)) {
|
|
122
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
123
|
+
ar[i] = from[i];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
127
|
+
}
|
|
128
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
129
|
+
var e = new Error(message);
|
|
130
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
function scaffold(projectDir, templateUrl) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
var stat, emitter, pkgPath, pkg;
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0:
|
|
139
|
+
try {
|
|
140
|
+
stat = statSync(projectDir);
|
|
141
|
+
} catch (_b) {
|
|
142
|
+
// path does not exist — fine to proceed
|
|
143
|
+
}
|
|
144
|
+
if (stat) {
|
|
145
|
+
if (stat.isFile()) {
|
|
146
|
+
throw new Error("\"".concat(projectDir, "\" already exists as a file"));
|
|
147
|
+
}
|
|
148
|
+
if (stat.isDirectory() && readdirSync(projectDir).length > 0) {
|
|
149
|
+
throw new Error("Directory \"".concat(projectDir, "\" already exists and is not empty"));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
emitter = degit(templateUrl, {
|
|
153
|
+
cache: false,
|
|
154
|
+
force: false
|
|
155
|
+
});
|
|
156
|
+
return [4 /*yield*/, emitter.clone(projectDir)];
|
|
157
|
+
case 1:
|
|
158
|
+
_a.sent();
|
|
159
|
+
pkgPath = join(projectDir, 'package.json');
|
|
160
|
+
try {
|
|
161
|
+
statSync(pkgPath);
|
|
162
|
+
pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
163
|
+
pkg.name = basename(projectDir);
|
|
164
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
165
|
+
} catch (_c) {
|
|
166
|
+
// no package.json — skip
|
|
167
|
+
}
|
|
168
|
+
return [2 /*return*/];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Branch where templates live — update once merged to main
|
|
175
|
+
var TEMPLATE_BRANCH = 'main';
|
|
176
|
+
var GITHUB_REPO = 'orioro/node-devtools';
|
|
177
|
+
// degit requires short-form paths (user/repo/subdir) for subdirectory cloning;
|
|
178
|
+
// full https URLs do not support the subdir syntax
|
|
179
|
+
var TEMPLATES = {
|
|
180
|
+
ts: {
|
|
181
|
+
label: 'TypeScript library (ts)',
|
|
182
|
+
src: "".concat(GITHUB_REPO, "/packages/template-ts#").concat(TEMPLATE_BRANCH)
|
|
183
|
+
// url: `https://github.com/${GITHUB_REPO}/tree/${TEMPLATE_BRANCH}/packages/template-ts`,
|
|
184
|
+
},
|
|
185
|
+
react: {
|
|
186
|
+
label: 'React component library (react)',
|
|
187
|
+
src: "".concat(GITHUB_REPO, "/packages/template-react#").concat(TEMPLATE_BRANCH)
|
|
188
|
+
// url: `https://github.com/${GITHUB_REPO}/tree/${TEMPLATE_BRANCH}/packages/template-react`,
|
|
189
|
+
},
|
|
190
|
+
workspaces: {
|
|
191
|
+
label: 'Monorepo workspaces (workspaces)',
|
|
192
|
+
src: "".concat(GITHUB_REPO, "/packages/template-workspaces#").concat(TEMPLATE_BRANCH)
|
|
193
|
+
// url: `https://github.com/${GITHUB_REPO}/tree/${TEMPLATE_BRANCH}/packages/template-workspaces`,
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
function resolveTemplateSrc(template) {
|
|
197
|
+
var _a, _b;
|
|
198
|
+
return (_b = (_a = TEMPLATES[template]) === null || _a === void 0 ? void 0 : _a.src) !== null && _b !== void 0 ? _b : template;
|
|
199
|
+
}
|
|
200
|
+
var program = new Command();
|
|
201
|
+
program.name('create-orioro').description('Scaffold a new project from an orioro template').argument('[project-dir]', 'Directory to scaffold the project into').option('-t, --template <template>', 'Template to use: ts, react, workspaces, or a custom degit path').action(function (projectDirArg, options) {
|
|
202
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
203
|
+
var projectDir, _a, templateUrl, spinner, absProjectDir, err_1;
|
|
204
|
+
return __generator(this, function (_b) {
|
|
205
|
+
switch (_b.label) {
|
|
206
|
+
case 0:
|
|
207
|
+
prompts.intro('create-orioro');
|
|
208
|
+
_a = projectDirArg;
|
|
209
|
+
if (_a) return [3 /*break*/, 2];
|
|
210
|
+
return [4 /*yield*/, prompts.text({
|
|
211
|
+
message: 'Project directory',
|
|
212
|
+
placeholder: 'my-project',
|
|
213
|
+
validate: function validate(v) {
|
|
214
|
+
return !v ? 'Please enter a directory name' : undefined;
|
|
215
|
+
}
|
|
216
|
+
})];
|
|
217
|
+
case 1:
|
|
218
|
+
_a = _b.sent();
|
|
219
|
+
_b.label = 2;
|
|
220
|
+
case 2:
|
|
221
|
+
projectDir = _a;
|
|
222
|
+
if (prompts.isCancel(projectDir)) {
|
|
223
|
+
prompts.cancel('Cancelled');
|
|
224
|
+
process.exit(0);
|
|
225
|
+
}
|
|
226
|
+
return [4 /*yield*/, function () {
|
|
227
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
228
|
+
var selected, custom;
|
|
229
|
+
return __generator(this, function (_a) {
|
|
230
|
+
switch (_a.label) {
|
|
231
|
+
case 0:
|
|
232
|
+
if (options.template) {
|
|
233
|
+
return [2 /*return*/, resolveTemplateSrc(options.template)];
|
|
234
|
+
}
|
|
235
|
+
return [4 /*yield*/, prompts.select({
|
|
236
|
+
message: 'Select a template',
|
|
237
|
+
options: __spreadArray(__spreadArray([], Object.entries(TEMPLATES).map(function (_a) {
|
|
238
|
+
var id = _a[0],
|
|
239
|
+
_b = _a[1],
|
|
240
|
+
label = _b.label;
|
|
241
|
+
_b.url;
|
|
242
|
+
return {
|
|
243
|
+
value: id,
|
|
244
|
+
label: "".concat(label)
|
|
245
|
+
};
|
|
246
|
+
}), true), [{
|
|
247
|
+
value: 'other',
|
|
248
|
+
label: 'Other (custom degit path / git URL)'
|
|
249
|
+
}], false)
|
|
250
|
+
})];
|
|
251
|
+
case 1:
|
|
252
|
+
selected = _a.sent();
|
|
253
|
+
if (prompts.isCancel(selected)) {
|
|
254
|
+
prompts.cancel('Cancelled');
|
|
255
|
+
process.exit(0);
|
|
256
|
+
}
|
|
257
|
+
if (selected !== 'other') {
|
|
258
|
+
return [2 /*return*/, resolveTemplateSrc(selected)];
|
|
259
|
+
}
|
|
260
|
+
return [4 /*yield*/, prompts.text({
|
|
261
|
+
message: 'Enter a degit path or git URL',
|
|
262
|
+
placeholder: 'user/repo or user/repo/subdir or https://...',
|
|
263
|
+
validate: function validate(v) {
|
|
264
|
+
return !v ? 'Please enter a path or URL' : undefined;
|
|
265
|
+
}
|
|
266
|
+
})];
|
|
267
|
+
case 2:
|
|
268
|
+
custom = _a.sent();
|
|
269
|
+
if (prompts.isCancel(custom)) {
|
|
270
|
+
prompts.cancel('Cancelled');
|
|
271
|
+
process.exit(0);
|
|
272
|
+
}
|
|
273
|
+
return [2 /*return*/, custom];
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
}()];
|
|
278
|
+
case 3:
|
|
279
|
+
templateUrl = _b.sent();
|
|
280
|
+
spinner = prompts.spinner();
|
|
281
|
+
spinner.start("Cloning ".concat(templateUrl, " \u2192 ").concat(projectDir));
|
|
282
|
+
absProjectDir = resolve(projectDir);
|
|
283
|
+
_b.label = 4;
|
|
284
|
+
case 4:
|
|
285
|
+
_b.trys.push([4, 6,, 7]);
|
|
286
|
+
return [4 /*yield*/, scaffold(absProjectDir, templateUrl)];
|
|
287
|
+
case 5:
|
|
288
|
+
_b.sent();
|
|
289
|
+
spinner.stop('Done!');
|
|
290
|
+
prompts.outro("Project ready at ".concat(absProjectDir));
|
|
291
|
+
return [3 /*break*/, 7];
|
|
292
|
+
case 6:
|
|
293
|
+
err_1 = _b.sent();
|
|
294
|
+
spinner.stop('Failed');
|
|
295
|
+
prompts.cancel(err_1 instanceof Error ? err_1.message : String(err_1));
|
|
296
|
+
process.exit(1);
|
|
297
|
+
return [3 /*break*/, 7];
|
|
298
|
+
case 7:
|
|
299
|
+
return [2 /*return*/];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
program.parse();
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function scaffold(projectDir: string, templateUrl: string): Promise<void>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_fs = require('node:fs');
|
|
4
|
+
var node_path = require('node:path');
|
|
5
|
+
var degit = require('degit');
|
|
6
|
+
|
|
7
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) {
|
|
9
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) {
|
|
15
|
+
try {
|
|
16
|
+
step(generator.next(value));
|
|
17
|
+
} catch (e) {
|
|
18
|
+
reject(e);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function rejected(value) {
|
|
22
|
+
try {
|
|
23
|
+
step(generator["throw"](value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function step(result) {
|
|
29
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function __generator(thisArg, body) {
|
|
35
|
+
var _ = {
|
|
36
|
+
label: 0,
|
|
37
|
+
sent: function sent() {
|
|
38
|
+
if (t[0] & 1) throw t[1];
|
|
39
|
+
return t[1];
|
|
40
|
+
},
|
|
41
|
+
trys: [],
|
|
42
|
+
ops: []
|
|
43
|
+
},
|
|
44
|
+
f,
|
|
45
|
+
y,
|
|
46
|
+
t,
|
|
47
|
+
g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
48
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
49
|
+
return this;
|
|
50
|
+
}), g;
|
|
51
|
+
function verb(n) {
|
|
52
|
+
return function (v) {
|
|
53
|
+
return step([n, v]);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function step(op) {
|
|
57
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
58
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
59
|
+
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;
|
|
60
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
61
|
+
switch (op[0]) {
|
|
62
|
+
case 0:
|
|
63
|
+
case 1:
|
|
64
|
+
t = op;
|
|
65
|
+
break;
|
|
66
|
+
case 4:
|
|
67
|
+
_.label++;
|
|
68
|
+
return {
|
|
69
|
+
value: op[1],
|
|
70
|
+
done: false
|
|
71
|
+
};
|
|
72
|
+
case 5:
|
|
73
|
+
_.label++;
|
|
74
|
+
y = op[1];
|
|
75
|
+
op = [0];
|
|
76
|
+
continue;
|
|
77
|
+
case 7:
|
|
78
|
+
op = _.ops.pop();
|
|
79
|
+
_.trys.pop();
|
|
80
|
+
continue;
|
|
81
|
+
default:
|
|
82
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
+
_ = 0;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
+
_.label = op[1];
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
+
_.label = t[1];
|
|
92
|
+
t = op;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (t && _.label < t[2]) {
|
|
96
|
+
_.label = t[2];
|
|
97
|
+
_.ops.push(op);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (t[2]) _.ops.pop();
|
|
101
|
+
_.trys.pop();
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
op = body.call(thisArg, _);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
op = [6, e];
|
|
107
|
+
y = 0;
|
|
108
|
+
} finally {
|
|
109
|
+
f = t = 0;
|
|
110
|
+
}
|
|
111
|
+
if (op[0] & 5) throw op[1];
|
|
112
|
+
return {
|
|
113
|
+
value: op[0] ? op[1] : void 0,
|
|
114
|
+
done: true
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
119
|
+
var e = new Error(message);
|
|
120
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
function scaffold(projectDir, templateUrl) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
+
var stat, emitter, pkgPath, pkg;
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
try {
|
|
130
|
+
stat = node_fs.statSync(projectDir);
|
|
131
|
+
} catch (_b) {
|
|
132
|
+
// path does not exist — fine to proceed
|
|
133
|
+
}
|
|
134
|
+
if (stat) {
|
|
135
|
+
if (stat.isFile()) {
|
|
136
|
+
throw new Error("\"".concat(projectDir, "\" already exists as a file"));
|
|
137
|
+
}
|
|
138
|
+
if (stat.isDirectory() && node_fs.readdirSync(projectDir).length > 0) {
|
|
139
|
+
throw new Error("Directory \"".concat(projectDir, "\" already exists and is not empty"));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
emitter = degit(templateUrl, {
|
|
143
|
+
cache: false,
|
|
144
|
+
force: false
|
|
145
|
+
});
|
|
146
|
+
return [4 /*yield*/, emitter.clone(projectDir)];
|
|
147
|
+
case 1:
|
|
148
|
+
_a.sent();
|
|
149
|
+
pkgPath = node_path.join(projectDir, 'package.json');
|
|
150
|
+
try {
|
|
151
|
+
node_fs.statSync(pkgPath);
|
|
152
|
+
pkg = JSON.parse(node_fs.readFileSync(pkgPath, 'utf8'));
|
|
153
|
+
pkg.name = node_path.basename(projectDir);
|
|
154
|
+
node_fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
155
|
+
} catch (_c) {
|
|
156
|
+
// no package.json — skip
|
|
157
|
+
}
|
|
158
|
+
return [2 /*return*/];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
exports.scaffold = scaffold;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { statSync, readFileSync, writeFileSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join, basename } from 'node:path';
|
|
3
|
+
import degit from 'degit';
|
|
4
|
+
|
|
5
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) {
|
|
7
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator["throw"](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
28
|
+
}
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function __generator(thisArg, body) {
|
|
33
|
+
var _ = {
|
|
34
|
+
label: 0,
|
|
35
|
+
sent: function sent() {
|
|
36
|
+
if (t[0] & 1) throw t[1];
|
|
37
|
+
return t[1];
|
|
38
|
+
},
|
|
39
|
+
trys: [],
|
|
40
|
+
ops: []
|
|
41
|
+
},
|
|
42
|
+
f,
|
|
43
|
+
y,
|
|
44
|
+
t,
|
|
45
|
+
g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
46
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
47
|
+
return this;
|
|
48
|
+
}), g;
|
|
49
|
+
function verb(n) {
|
|
50
|
+
return function (v) {
|
|
51
|
+
return step([n, v]);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function step(op) {
|
|
55
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
56
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
57
|
+
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;
|
|
58
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
59
|
+
switch (op[0]) {
|
|
60
|
+
case 0:
|
|
61
|
+
case 1:
|
|
62
|
+
t = op;
|
|
63
|
+
break;
|
|
64
|
+
case 4:
|
|
65
|
+
_.label++;
|
|
66
|
+
return {
|
|
67
|
+
value: op[1],
|
|
68
|
+
done: false
|
|
69
|
+
};
|
|
70
|
+
case 5:
|
|
71
|
+
_.label++;
|
|
72
|
+
y = op[1];
|
|
73
|
+
op = [0];
|
|
74
|
+
continue;
|
|
75
|
+
case 7:
|
|
76
|
+
op = _.ops.pop();
|
|
77
|
+
_.trys.pop();
|
|
78
|
+
continue;
|
|
79
|
+
default:
|
|
80
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
81
|
+
_ = 0;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
85
|
+
_.label = op[1];
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
89
|
+
_.label = t[1];
|
|
90
|
+
t = op;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (t && _.label < t[2]) {
|
|
94
|
+
_.label = t[2];
|
|
95
|
+
_.ops.push(op);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (t[2]) _.ops.pop();
|
|
99
|
+
_.trys.pop();
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
op = body.call(thisArg, _);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
op = [6, e];
|
|
105
|
+
y = 0;
|
|
106
|
+
} finally {
|
|
107
|
+
f = t = 0;
|
|
108
|
+
}
|
|
109
|
+
if (op[0] & 5) throw op[1];
|
|
110
|
+
return {
|
|
111
|
+
value: op[0] ? op[1] : void 0,
|
|
112
|
+
done: true
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
117
|
+
var e = new Error(message);
|
|
118
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
function scaffold(projectDir, templateUrl) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
123
|
+
var stat, emitter, pkgPath, pkg;
|
|
124
|
+
return __generator(this, function (_a) {
|
|
125
|
+
switch (_a.label) {
|
|
126
|
+
case 0:
|
|
127
|
+
try {
|
|
128
|
+
stat = statSync(projectDir);
|
|
129
|
+
} catch (_b) {
|
|
130
|
+
// path does not exist — fine to proceed
|
|
131
|
+
}
|
|
132
|
+
if (stat) {
|
|
133
|
+
if (stat.isFile()) {
|
|
134
|
+
throw new Error("\"".concat(projectDir, "\" already exists as a file"));
|
|
135
|
+
}
|
|
136
|
+
if (stat.isDirectory() && readdirSync(projectDir).length > 0) {
|
|
137
|
+
throw new Error("Directory \"".concat(projectDir, "\" already exists and is not empty"));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
emitter = degit(templateUrl, {
|
|
141
|
+
cache: false,
|
|
142
|
+
force: false
|
|
143
|
+
});
|
|
144
|
+
return [4 /*yield*/, emitter.clone(projectDir)];
|
|
145
|
+
case 1:
|
|
146
|
+
_a.sent();
|
|
147
|
+
pkgPath = join(projectDir, 'package.json');
|
|
148
|
+
try {
|
|
149
|
+
statSync(pkgPath);
|
|
150
|
+
pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
151
|
+
pkg.name = basename(projectDir);
|
|
152
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
153
|
+
} catch (_c) {
|
|
154
|
+
// no package.json — skip
|
|
155
|
+
}
|
|
156
|
+
return [2 /*return*/];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export { scaffold };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-orioro",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"packageManager": "yarn@4.0.2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"create-orioro": "dist/cli.mjs"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./dist/index.mjs",
|
|
13
|
+
"./*": "./dist/*"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"prepublishOnly": "npm run build",
|
|
24
|
+
"build": "rm -rf dist && rollup --config ./rollup.config.mjs && chmod +x dist/cli.mjs",
|
|
25
|
+
"test": "jest",
|
|
26
|
+
"readme": "readme",
|
|
27
|
+
"dev:run": "yarn build && node dist/cli.mjs"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@orioro/dev": "workspace:^",
|
|
31
|
+
"@orioro/readme": "^1.0.1",
|
|
32
|
+
"@types/jest": "^29.5.12",
|
|
33
|
+
"babel-jest": "^30.3.0",
|
|
34
|
+
"jest": "^29.7.0",
|
|
35
|
+
"rollup": "^4.13.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@clack/prompts": "^1.2.0",
|
|
39
|
+
"@types/degit": "^2.8.6",
|
|
40
|
+
"commander": "^14.0.3",
|
|
41
|
+
"degit": "^2.8.4"
|
|
42
|
+
}
|
|
43
|
+
}
|