@ryziz/cli 0.0.17

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.
Files changed (2) hide show
  1. package/create.js +28 -0
  2. package/package.json +8 -0
package/create.js ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync as exists, cpSync, renameSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { resolve, join, dirname, basename } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { task } from '@ryziz/flow';
6
+
7
+ task('Initialize Project', {
8
+ 'Locating': (c) => {
9
+ const root = resolve(dirname(fileURLToPath(import.meta.url)), '../'), name = basename(process.argv[1]);
10
+ c.src = [resolve(root, name), resolve(root, '../templates', name)].find((p) => exists(join(p, 'package.json')));
11
+ if (!c.src) throw Error(`Template ${name} not found`);
12
+ },
13
+ 'Verifying': (c) => {
14
+ if (!process.argv[2]) throw Error('Usage: create-app <dir>');
15
+ if (exists(c.dest = resolve(process.argv[2]))) throw Error('Directory exists');
16
+ },
17
+ 'Cloning': ({ src, dest }) => {
18
+ cpSync(src, dest, { recursive: true });
19
+ if (exists(join(dest, 'gitignore'))) renameSync(join(dest, 'gitignore'), join(dest, '.gitignore'));
20
+ },
21
+ 'Configuring': ({ dest }) => {
22
+ const p = join(dest, 'package.json'), pkg = JSON.parse(readFileSync(p));
23
+ delete pkg.bin; pkg.name = basename(dest);
24
+ if (pkg.dependencies?.['@ryziz/cli']) (pkg.devDependencies ||= {})['@ryziz/cli'] = pkg.dependencies['@ryziz/cli'], delete pkg.dependencies['@ryziz/cli'];
25
+ writeFileSync(p, JSON.stringify(pkg, null, 2));
26
+ },
27
+ 'Ready': ({ dest }) => console.log(`Run: cd ${basename(dest)} && npm install`),
28
+ });
package/package.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@ryziz/cli",
3
+ "version": "0.0.17",
4
+ "type": "module",
5
+ "dependencies": {
6
+ "@ryziz/flow": "^0.0.16"
7
+ }
8
+ }