@driveflux/fab 1.0.0 → 1.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.
@@ -1,270 +0,0 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
30
- function _ts_generator(thisArg, body) {
31
- var f, y, t, g, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1) throw t[1];
35
- return t[1];
36
- },
37
- trys: [],
38
- ops: []
39
- };
40
- return g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
- return this;
46
- }), g;
47
- function verb(n) {
48
- return function(v) {
49
- return step([
50
- n,
51
- v
52
- ]);
53
- };
54
- }
55
- function step(op) {
56
- if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
58
- 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;
59
- if (y = 0, t) op = [
60
- op[0] & 2,
61
- t.value
62
- ];
63
- switch(op[0]){
64
- case 0:
65
- case 1:
66
- t = op;
67
- break;
68
- case 4:
69
- _.label++;
70
- return {
71
- value: op[1],
72
- done: false
73
- };
74
- case 5:
75
- _.label++;
76
- y = op[1];
77
- op = [
78
- 0
79
- ];
80
- continue;
81
- case 7:
82
- op = _.ops.pop();
83
- _.trys.pop();
84
- continue;
85
- default:
86
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
- _ = 0;
88
- continue;
89
- }
90
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
- _.label = op[1];
92
- break;
93
- }
94
- if (op[0] === 6 && _.label < t[1]) {
95
- _.label = t[1];
96
- t = op;
97
- break;
98
- }
99
- if (t && _.label < t[2]) {
100
- _.label = t[2];
101
- _.ops.push(op);
102
- break;
103
- }
104
- if (t[2]) _.ops.pop();
105
- _.trys.pop();
106
- continue;
107
- }
108
- op = body.call(thisArg, _);
109
- } catch (e) {
110
- op = [
111
- 6,
112
- e
113
- ];
114
- y = 0;
115
- } finally{
116
- f = t = 0;
117
- }
118
- if (op[0] & 5) throw op[1];
119
- return {
120
- value: op[0] ? op[1] : void 0,
121
- done: true
122
- };
123
- }
124
- }
125
- import { deleteAsync } from "del";
126
- import fs from "node:fs/promises";
127
- import path from "node:path";
128
- import { ensureDir, getBaseDir, runCommand } from "./utils.js";
129
- export var create = function() {
130
- var _ref = _async_to_generator(function(param) {
131
- var template, name, providedDestination, providedCwd, dangerouslyRewrite, cwd, destination, finalDestination, e, templatePath;
132
- return _ts_generator(this, function(_state) {
133
- switch(_state.label){
134
- case 0:
135
- template = param.template, name = param.name, providedDestination = param.destination, providedCwd = param.cwd, dangerouslyRewrite = param.dangerouslyRewrite;
136
- cwd = providedCwd !== null && providedCwd !== void 0 ? providedCwd : process.cwd();
137
- destination = providedDestination ? path.resolve(cwd, providedDestination) : cwd;
138
- finalDestination = path.resolve(destination, name);
139
- _state.label = 1;
140
- case 1:
141
- _state.trys.push([
142
- 1,
143
- 6,
144
- ,
145
- 7
146
- ]);
147
- return [
148
- 4,
149
- fs.stat(finalDestination)
150
- ];
151
- case 2:
152
- if (!_state.sent()) return [
153
- 3,
154
- 5
155
- ];
156
- if (!!dangerouslyRewrite) return [
157
- 3,
158
- 3
159
- ];
160
- console.log("\uD83D\uDEA8 Cannot create the pacakge at ".concat(finalDestination, '. Please delete the previous file or directory or use "dangerouslyRewrite"'));
161
- process.exit(1);
162
- return [
163
- 3,
164
- 5
165
- ];
166
- case 3:
167
- return [
168
- 4,
169
- deleteAsync(finalDestination)
170
- ];
171
- case 4:
172
- _state.sent();
173
- _state.label = 5;
174
- case 5:
175
- return [
176
- 3,
177
- 7
178
- ];
179
- case 6:
180
- e = _state.sent();
181
- return [
182
- 3,
183
- 7
184
- ];
185
- case 7:
186
- // Make sure the folder exists
187
- return [
188
- 4,
189
- ensureDir(finalDestination)
190
- ];
191
- case 8:
192
- _state.sent();
193
- templatePath = path.resolve(getBaseDir(), "templates/".concat(template));
194
- return [
195
- 4,
196
- fs.stat(templatePath)
197
- ];
198
- case 9:
199
- // Make sure the template exists
200
- if (!_state.sent().isDirectory()) {
201
- throw new Error("The template ".concat(template, " doesn't exist"));
202
- }
203
- // First, copy the template into the destintion
204
- return [
205
- 4,
206
- fs.cp(templatePath, finalDestination, {
207
- recursive: true
208
- })
209
- ];
210
- case 10:
211
- _state.sent();
212
- // Now we insert the name into the package file
213
- return [
214
- 4,
215
- replaceInFile("".concat(finalDestination, "/package.json"), {
216
- name: name
217
- })
218
- ];
219
- case 11:
220
- _state.sent();
221
- return [
222
- 4,
223
- runCommand("pnpm", [
224
- "i"
225
- ], {
226
- cwd: cwd
227
- })
228
- ];
229
- case 12:
230
- _state.sent();
231
- return [
232
- 2
233
- ];
234
- }
235
- });
236
- });
237
- return function create(_) {
238
- return _ref.apply(this, arguments);
239
- };
240
- }();
241
- var replaceInFile = function() {
242
- var _ref = _async_to_generator(function(filePath, replacements) {
243
- var content, newContent;
244
- return _ts_generator(this, function(_state) {
245
- switch(_state.label){
246
- case 0:
247
- return [
248
- 4,
249
- fs.readFile(filePath, "utf-8")
250
- ];
251
- case 1:
252
- content = _state.sent();
253
- // No time to build the regex and replace logic, that's for later, we just replace the name now
254
- newContent = content.replace("{{name}}", replacements.name);
255
- return [
256
- 4,
257
- fs.writeFile(filePath, newContent)
258
- ];
259
- case 2:
260
- _state.sent();
261
- return [
262
- 2
263
- ];
264
- }
265
- });
266
- });
267
- return function replaceInFile(filePath, replacements) {
268
- return _ref.apply(this, arguments);
269
- };
270
- }();
package/dist/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- export * from "./build.js";
2
- export * from "./clean.js";
3
- export * from "./config.js";
4
- export * from "./create.js";
5
- export * from "./types.js";
package/dist/src/types.js DELETED
@@ -1 +0,0 @@
1
- export { };
package/dist/src/utils.js DELETED
@@ -1,308 +0,0 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
30
- function _define_property(obj, key, value) {
31
- if (key in obj) {
32
- Object.defineProperty(obj, key, {
33
- value: value,
34
- enumerable: true,
35
- configurable: true,
36
- writable: true
37
- });
38
- } else {
39
- obj[key] = value;
40
- }
41
- return obj;
42
- }
43
- function _object_spread(target) {
44
- for(var i = 1; i < arguments.length; i++){
45
- var source = arguments[i] != null ? arguments[i] : {};
46
- var ownKeys = Object.keys(source);
47
- if (typeof Object.getOwnPropertySymbols === "function") {
48
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
- }));
51
- }
52
- ownKeys.forEach(function(key) {
53
- _define_property(target, key, source[key]);
54
- });
55
- }
56
- return target;
57
- }
58
- function _ts_generator(thisArg, body) {
59
- var f, y, t, g, _ = {
60
- label: 0,
61
- sent: function() {
62
- if (t[0] & 1) throw t[1];
63
- return t[1];
64
- },
65
- trys: [],
66
- ops: []
67
- };
68
- return g = {
69
- next: verb(0),
70
- "throw": verb(1),
71
- "return": verb(2)
72
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
73
- return this;
74
- }), g;
75
- function verb(n) {
76
- return function(v) {
77
- return step([
78
- n,
79
- v
80
- ]);
81
- };
82
- }
83
- function step(op) {
84
- if (f) throw new TypeError("Generator is already executing.");
85
- while(_)try {
86
- 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;
87
- if (y = 0, t) op = [
88
- op[0] & 2,
89
- t.value
90
- ];
91
- switch(op[0]){
92
- case 0:
93
- case 1:
94
- t = op;
95
- break;
96
- case 4:
97
- _.label++;
98
- return {
99
- value: op[1],
100
- done: false
101
- };
102
- case 5:
103
- _.label++;
104
- y = op[1];
105
- op = [
106
- 0
107
- ];
108
- continue;
109
- case 7:
110
- op = _.ops.pop();
111
- _.trys.pop();
112
- continue;
113
- default:
114
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
115
- _ = 0;
116
- continue;
117
- }
118
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
119
- _.label = op[1];
120
- break;
121
- }
122
- if (op[0] === 6 && _.label < t[1]) {
123
- _.label = t[1];
124
- t = op;
125
- break;
126
- }
127
- if (t && _.label < t[2]) {
128
- _.label = t[2];
129
- _.ops.push(op);
130
- break;
131
- }
132
- if (t[2]) _.ops.pop();
133
- _.trys.pop();
134
- continue;
135
- }
136
- op = body.call(thisArg, _);
137
- } catch (e) {
138
- op = [
139
- 6,
140
- e
141
- ];
142
- y = 0;
143
- } finally{
144
- f = t = 0;
145
- }
146
- if (op[0] & 5) throw op[1];
147
- return {
148
- value: op[0] ? op[1] : void 0,
149
- done: true
150
- };
151
- }
152
- }
153
- import { spawn } from "node:child_process";
154
- import fs from "node:fs/promises";
155
- import path from "node:path";
156
- var REQUIRED_DEPS = {
157
- del: [
158
- "del-cli"
159
- ],
160
- tsc: [
161
- "typescript"
162
- ],
163
- swc: [
164
- "@swc/core",
165
- "@swc/cli"
166
- ]
167
- };
168
- export var ensureDir = function() {
169
- var _ref = _async_to_generator(function(dir) {
170
- var stat, e;
171
- return _ts_generator(this, function(_state) {
172
- switch(_state.label){
173
- case 0:
174
- _state.trys.push([
175
- 0,
176
- 2,
177
- ,
178
- 4
179
- ]);
180
- return [
181
- 4,
182
- fs.stat(dir)
183
- ];
184
- case 1:
185
- stat = _state.sent();
186
- if (!stat.isDirectory()) {
187
- throw new Error("".concat(dir, " is not a directory"));
188
- }
189
- return [
190
- 3,
191
- 4
192
- ];
193
- case 2:
194
- e = _state.sent();
195
- return [
196
- 4,
197
- fs.mkdir(dir, {
198
- recursive: true
199
- })
200
- ];
201
- case 3:
202
- _state.sent();
203
- return [
204
- 3,
205
- 4
206
- ];
207
- case 4:
208
- return [
209
- 2
210
- ];
211
- }
212
- });
213
- });
214
- return function ensureDir(dir) {
215
- return _ref.apply(this, arguments);
216
- };
217
- }();
218
- export var runCommand = function() {
219
- var _ref = _async_to_generator(function(cmd, args, options) {
220
- var c;
221
- return _ts_generator(this, function(_state) {
222
- c = spawn(cmd, args, _object_spread({
223
- stdio: "inherit"
224
- }, options));
225
- return [
226
- 2,
227
- new Promise(function(resolve, reject) {
228
- c.on("error", function(error) {
229
- console.error(error);
230
- reject(error);
231
- });
232
- c.on("close", function(code) {
233
- if (code !== 0) {
234
- reject(new Error("Command exited with code ".concat(code)));
235
- } else {
236
- resolve(true);
237
- }
238
- });
239
- })
240
- ];
241
- });
242
- });
243
- return function runCommand(cmd, args, options) {
244
- return _ref.apply(this, arguments);
245
- };
246
- }();
247
- export var validatePackageJson = function() {
248
- var _ref = _async_to_generator(function(param) {
249
- var command, providedCwd, cwd, pkg, _, packageName, notAllowedInScripts, deps, devDeps, allDeps, missingDeps;
250
- return _ts_generator(this, function(_state) {
251
- switch(_state.label){
252
- case 0:
253
- command = param.command, providedCwd = param.cwd;
254
- cwd = providedCwd || process.cwd();
255
- _ = JSON.parse;
256
- return [
257
- 4,
258
- fs.readFile(path.join(cwd, "package.json"), "utf-8")
259
- ];
260
- case 1:
261
- pkg = _.apply(JSON, [
262
- _state.sent()
263
- ]);
264
- packageName = cwd.split("/").pop();
265
- notAllowedInScripts = [
266
- "del",
267
- "tsc",
268
- "swc"
269
- ];
270
- if (command in pkg.scripts && notAllowedInScripts.includes(command)) {
271
- console.log("\uD83D\uDEA8 The ".concat(command, " script is not allowed. Remove the ").concat(command, " script from ").concat(packageName, "/package.json"));
272
- process.exit(1);
273
- }
274
- // Validate dependencies. For each command we try to validate the corresponding dependencies
275
- deps = pkg.dependencies || {};
276
- devDeps = pkg.devDependencies || {};
277
- allDeps = _object_spread({}, deps, devDeps);
278
- missingDeps = REQUIRED_DEPS[command].filter(function(d) {
279
- return !(d in allDeps);
280
- });
281
- if (missingDeps.length > 0) {
282
- console.log("\uD83D\uDEA8 The ".concat(command, " script requires the following dependencies: ").concat(missingDeps.join(", "), ". Add them to ").concat(packageName, "/package.json"));
283
- process.exit(1);
284
- }
285
- return [
286
- 2
287
- ];
288
- }
289
- });
290
- });
291
- return function validatePackageJson(_) {
292
- return _ref.apply(this, arguments);
293
- };
294
- }();
295
- export var getBaseDir = function() {
296
- // This file will end up in ./dist, so we need to remove the dist from the path
297
- return path.resolve(path.dirname(decodeURIComponent(new URL(import.meta.url).pathname)), "..");
298
- };
299
- export var getDefaultOptions = function() {
300
- return {
301
- cwd: process.cwd(),
302
- destination: "dist",
303
- doNotCleanup: [
304
- "src",
305
- "bin"
306
- ]
307
- };
308
- };