main
ChrisKader 4 months ago
parent f6dc683a45
commit 256bf676ce
  1. 41
      index.js
  2. 4
      tsconfig.json

@ -1,14 +1,19 @@
import prompts from 'prompts'; "use strict";
import kebabCase from 'lodash.kebabcase'; var __importDefault = (this && this.__importDefault) || function (mod) {
import sanitize from 'sanitize-filename'; return (mod && mod.__esModule) ? mod : { "default": mod };
import util from 'util'; };
import fs from 'fs-extra'; Object.defineProperty(exports, "__esModule", { value: true });
import path from 'path'; const prompts_1 = __importDefault(require("prompts"));
import { sortPackageJson } from 'sort-package-json'; const lodash_kebabcase_1 = __importDefault(require("lodash.kebabcase"));
const exec = util.promisify(require('child_process').exec); const sanitize_filename_1 = __importDefault(require("sanitize-filename"));
const util_1 = __importDefault(require("util"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const sort_package_json_1 = require("sort-package-json");
const exec = util_1.default.promisify(require('child_process').exec);
const repoUrls = { const repoUrls = {
js: '/Users/ck/dev/js-tinkr-plugin-boilerplate', //'https://git.tinkr.site/jeffi/js-tinkrplugin-boilerplate.git', js: 'https://git.tinkr.site/jeffi/js-tinkrplugin-boilerplate.git',
ts: '/Users/ck/dev/ts-tinkr-plugin-boilerplate', //'https://git.tinkr.site/jeffi/ts-tinkr-plugin-boilerplate.git', ts: 'https://git.tinkr.site/jeffi/ts-tinkr-plugin-boilerplate.git',
}; };
const invalidName = ` const invalidName = `
It is recommended to keep your plugin name short. It is recommended to keep your plugin name short.
@ -17,7 +22,7 @@ const invalidVersion = `
A valid version has one to four dot-separated integers. A valid version has one to four dot-separated integers.
Examples: "1", "1.0", "2.0.3", "3.4.7.219" Examples: "1", "1.0", "2.0.3", "3.4.7.219"
`.trim(); `.trim();
prompts([ (0, prompts_1.default)([
{ {
type: 'text', type: 'text',
name: 'name', name: 'name',
@ -52,21 +57,21 @@ prompts([
initial: 0, initial: 0,
}, },
]).then(async ({ name, version, author, description, lang }) => { ]).then(async ({ name, version, author, description, lang }) => {
const packageName = kebabCase(sanitize(name, { replacement: '-' })); const packageName = (0, lodash_kebabcase_1.default)((0, sanitize_filename_1.default)(name, { replacement: '-' }));
console.log(`Creating a Tinkr plugin in ./${packageName}`); console.log(`Creating a Tinkr plugin in ./${packageName}`);
await exec(`git clone ${repoUrls[lang]} ${packageName}`); await exec(`git clone ${repoUrls[lang]} ${packageName}`);
const packageDir = path.join(process.cwd(), packageName); const packageDir = path_1.default.join(process.cwd(), packageName);
const packageJsonPath = path.join(packageDir, 'package.json'); const packageJsonPath = path_1.default.join(packageDir, 'package.json');
const { bugs, homepage, keywords, license, repository, ...packageJson } = await fs.readJSON(packageJsonPath); const { bugs, homepage, keywords, license, repository, ...packageJson } = await fs_extra_1.default.readJSON(packageJsonPath);
await fs.writeJSON(packageJsonPath, sortPackageJson({ await fs_extra_1.default.writeJSON(packageJsonPath, (0, sort_package_json_1.sortPackageJson)({
...packageJson, ...packageJson,
author, author,
description, description,
name: packageName, name: packageName,
version, version,
}), { spaces: 2 }); }), { spaces: 2 });
const gitFolderPath = path.join(packageDir, '.git'); const gitFolderPath = path_1.default.join(packageDir, '.git');
await fs.remove(gitFolderPath); await fs_extra_1.default.remove(gitFolderPath);
console.log('Success: Now just `npm install` using your favorite package manager and create your Tinkr plugin!'); console.log('Success: Now just `npm install` using your favorite package manager and create your Tinkr plugin!');
}).catch((error) => { }).catch((error) => {
console.error(error); console.error(error);

@ -25,9 +25,9 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */ /* Modules */
"module": "ESNext", /* Specify what module code is generated. */ "module": "CommonJS", /* Specify what module code is generated. */
"rootDir": "./src", /* Specify the root folder within your source files. */ "rootDir": "./src", /* Specify the root folder within your source files. */
"moduleResolution": "Bundler", /* Specify how TypeScript looks up a file from a given module specifier. */ "moduleResolution": "Node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */

Loading…
Cancel
Save