create-cloudflare 0.0.0 → 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.
Files changed (3) hide show
  1. package/bin.js +18 -23
  2. package/index.js +1 -0
  3. package/package.json +12 -2
package/bin.js CHANGED
@@ -1,24 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
  const argv = require('mri')(process.argv.slice(2), {
3
3
  alias: {
4
- C: 'cwd',
5
- e: 'env',
6
- f: 'format',
7
- t: 'typescript',
8
- // m: 'monorepo',
9
4
  v: 'version',
10
5
  h: 'help',
11
- // c: 'cfw',
12
6
  },
13
7
  default: {
14
- C: '.',
8
+ init: true,
15
9
  force: false,
16
- e: 'cloudflare',
17
- f: '', // ~> env-default
10
+ debug: false
18
11
  }
19
12
  });
20
13
 
21
- /** @param {string} msg */
14
+ /**
15
+ * @param {string} msg
16
+ * @returns {never}
17
+ */
22
18
  function exit(msg, code = 1) {
23
19
  if (code) process.stderr.write(msg + '\n');
24
20
  else process.stdout.write(msg + '\n');
@@ -29,25 +25,23 @@ if (argv.help) {
29
25
  let output = '';
30
26
 
31
27
  output += '\n Usage';
32
- output += '\n npm init worktop <name> [options]';
28
+ output += '\n npm init cloudflare <directory> -- [options]';
29
+ output += '\n pnpm create cloudflare <directory> [options]';
30
+ output += '\n yarn create cloudflare <directory> [options]';
33
31
  output += '\n';
34
32
  output += '\n Options';
35
- output += '\n -C, --cwd Directory to resolve from';
36
- output += '\n -t, --typescript Setup project for TypeScript usage';
37
- output += '\n -e, --env Target platform environment (default "cloudflare")';
38
- output += '\n -f, --format Worker/Script output format (default "module")';
39
- // output += '\n -m, --monorepo Force directory overwrite';
40
- // output += '\n -c, --cfw Force directory overwrite';
41
33
  output += '\n --force Force overwrite target directory';
34
+ output += '\n --no-init Do not initialize a git repository';
35
+ output += '\n --debug Print additional error details';
42
36
  output += '\n -v, --version Displays current version';
43
37
  output += '\n -h, --help Displays this message';
44
38
  output += '\n';
45
39
  output += '\n Examples';
46
- output += '\n $ npm init worktop my-worker';
47
- output += '\n $ yarn create worktop my-worker --force';
48
- output += '\n $ npm init worktop my-worker --env cloudflare';
49
- output += '\n $ npm init worktop my-worker --env cloudflare';
50
- output += '\n $ npm init worktop my-worker --env deno';
40
+ output += '\n $ npm init cloudflare my-project';
41
+ output += '\n $ npm init cloudflare my-project -- --no-init';
42
+ output += '\n $ npm init cloudflare my-project -- pages svelte-kit';
43
+ output += '\n $ npm init cloudflare my-project -- https://github.com/user/repo.git';
44
+ output += '\n $ npm init cloudflare my-project -- https://github.com/user/repo.git#branch';
51
45
  output += '\n';
52
46
 
53
47
  exit(output, 0);
@@ -55,11 +49,12 @@ if (argv.help) {
55
49
 
56
50
  if (argv.version) {
57
51
  let pkg = require('./package.json');
58
- return exit(`${pkg.name}, v${pkg.version}`, 0);
52
+ exit(`${pkg.name}, v${pkg.version}`, 0);
59
53
  }
60
54
 
61
55
  (async function () {
62
56
  try {
57
+ console.log(argv);
63
58
  let dir = argv._.join('-').trim().replace(/[\s_]+/g, '-');
64
59
  if (!dir) return exit('Missing <name> argument', 1);
65
60
  await require('.').setup(dir, argv);
package/index.js ADDED
@@ -0,0 +1 @@
1
+ const e = require('path');const r = require('fs');const { join:t } = require('path');const { promisify:s } = require('util');const { exec:o } = require('child_process');s(o);var i=r.existsSync;function f(e){return r.promises.rm(e,{recursive:!0})}async function a(r,t){let s=process.cwd(),o=e.join(s,r);if(console.log({target:o}),i(o)){if(!t.force){let r=`Refusing to overwrite existing "${e.relative(s,o)}" directory.\n`;throw r+="Please specify a different directory or use the `--force` flag.",new Error(r)}if(!o.startsWith(s))throw new Error("Refusing to manipulate the file system outside the PWD location.\nPlease specify a different target directory.");await f(o)}let a=!1,[l,n]=t._||[];if(console.log({source:l,filter:n}),!l)throw new Error("Missing source value(s).\nPlease view the `--help` text.");if(/^(https?|ftps?|file|git|ssh):\/\//.test(l))a=!0;else if(!n&&l.includes(":"))a=!0;else{if(l=l.toLowerCase(),!n)throw new Error("Missing filter");if(/^workers?/.test(l))n="workers/"+n;else{if("pages"!==l)throw new Error(`Invalid "${l}" source.`);n="pages/"+n}l="https://github.com/cloudflare/worker-examples.git"}return console.log({target:o,source:l,filter:n})}exports.setup=a;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.0",
2
+ "version": "0.0.1",
3
3
  "name": "create-cloudflare",
4
4
  "repository": "lukeed/create-cloudflare",
5
5
  "description": "TODO",
@@ -12,13 +12,23 @@
12
12
  },
13
13
  "exports": "./index.js",
14
14
  "files": [
15
- "bin.js"
15
+ "bin.js",
16
+ "index.js"
16
17
  ],
17
18
  "engines": {
18
19
  "node": ">=12"
19
20
  },
21
+ "scripts": {
22
+ "build": "bundt -m",
23
+ "types": "tsc"
24
+ },
20
25
  "dependencies": {
21
26
  "kleur": "^4.0.0",
22
27
  "mri": "^1.2.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "17.0.29",
31
+ "bundt": "2.0.0-next.2",
32
+ "typescript": "4.6.3"
23
33
  }
24
34
  }