You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
3.0 KiB

4 months ago
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const prompts_1 = __importDefault(require("prompts"));
const lodash_kebabcase_1 = __importDefault(require("lodash.kebabcase"));
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);
4 months ago
const repoUrls = {
4 months ago
js: 'https://git.tinkr.site/jeffi/js-tinkrplugin-boilerplate.git',
ts: 'https://git.tinkr.site/jeffi/ts-tinkr-plugin-boilerplate.git',
4 months ago
};
const invalidName = `
It is recommended to keep your plugin name short.
`.trim();
const invalidVersion = `
A valid version has one to four dot-separated integers.
Examples: "1", "1.0", "2.0.3", "3.4.7.219"
`.trim();
4 months ago
(0, prompts_1.default)([
4 months ago
{
type: 'text',
name: 'name',
message: 'Tinkr plugin package name:',
validate: (n) => n.length < 32 || invalidName,
},
{
type: 'text',
name: 'version',
message: 'First version number:',
initial: '1.0.0',
validate: (v) => !/[^.\d]/.test(v) || invalidVersion,
},
{
type: 'text',
name: 'author',
message: 'Author name:',
},
{
type: 'text',
name: 'description',
message: 'Description:',
},
{
type: 'select',
name: 'lang',
message: 'Which do you want to use?',
choices: [
{ title: 'JavaScript', value: 'js' },
{ title: 'TypeScript', value: 'ts' },
],
initial: 0,
},
]).then(async ({ name, version, author, description, lang }) => {
4 months ago
const packageName = (0, lodash_kebabcase_1.default)((0, sanitize_filename_1.default)(name, { replacement: '-' }));
4 months ago
console.log(`Creating a Tinkr plugin in ./${packageName}`);
await exec(`git clone ${repoUrls[lang]} ${packageName}`);
4 months ago
const packageDir = path_1.default.join(process.cwd(), packageName);
const packageJsonPath = path_1.default.join(packageDir, 'package.json');
const { bugs, homepage, keywords, license, repository, ...packageJson } = await fs_extra_1.default.readJSON(packageJsonPath);
await fs_extra_1.default.writeJSON(packageJsonPath, (0, sort_package_json_1.sortPackageJson)({
4 months ago
...packageJson,
author,
description,
name: packageName,
version,
}), { spaces: 2 });
4 months ago
const gitFolderPath = path_1.default.join(packageDir, '.git');
await fs_extra_1.default.remove(gitFolderPath);
4 months ago
console.log('Success: Now just `npm install` using your favorite package manager and create your Tinkr plugin!');
}).catch((error) => {
console.error(error);
process.exit(1);
});