mirror of
https://github.com/HSLdevcom/digitransit-ui
synced 2025-07-05 16:30:37 +02:00
131 lines
3.5 KiB
JavaScript
Executable file
131 lines
3.5 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
|
|
import { existsSync, mkdirSync, writeFileSync, copySync } from 'fs-extra';
|
|
import { join } from 'path';
|
|
import meow from 'meow';
|
|
import camelcase from 'camelcase';
|
|
import decamelize from 'decamelize';
|
|
|
|
const cli = meow(`
|
|
Usage:
|
|
$ ./scripts/create-new-module <module>
|
|
Examples:
|
|
$ ./scripts/create-new-module clone
|
|
`);
|
|
|
|
if (!cli.input.length) cli.showHelp();
|
|
let name = cli.input[0];
|
|
|
|
// Normalize module name
|
|
// digitransit-search-util-clone => clone
|
|
name = name.replace(/digitransit-search-util-/, '');
|
|
const camelcaseName = camelcase(name);
|
|
const decamelizeName = decamelize(name, '-');
|
|
|
|
// Create Folder
|
|
const folderPath = join(__dirname, '..', 'packages', `digitransit-search-util-${decamelizeName}`);
|
|
if (!existsSync(folderPath)) {
|
|
mkdirSync(folderPath);
|
|
}
|
|
|
|
// Create index.js
|
|
writeFileSync(join(folderPath, 'index.js'), `/**
|
|
* <DESCRIPTION>
|
|
*
|
|
* @name ${camelcaseName}
|
|
* @param {Boolean|Null|Undefined|Number|BigInt|String|Symbol|Object} param1
|
|
* @param {Boolean|Null|Undefined|Number|BigInt|String|Symbol|Object} param2
|
|
* @returns {Boolean} true/false
|
|
* @example
|
|
* digitransit-search-util.${camelcaseName}(param1, param2);
|
|
* //=true
|
|
*/
|
|
export default function ${camelcaseName}(param1, param2) {
|
|
return true;
|
|
};
|
|
`);
|
|
|
|
// Create package.json
|
|
writeFileSync(join(folderPath, 'package.json'), `{
|
|
"name": "@digitransit-search-util/digitransit-search-util-${decamelizeName}",
|
|
"version": "0.0.1",
|
|
"description": "digitransit-search-util ${decamelizeName} module",
|
|
"main": "index.js",
|
|
"publishConfig": {
|
|
"access": "public"
|
|
},
|
|
"scripts": {
|
|
"test": "mocha -r esm test.js",
|
|
"docs": "node -r esm ../../scripts/generate-readmes"
|
|
},
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "git://github.com/HSLdevcom/digitransit-ui.git"
|
|
},
|
|
"keywords": [
|
|
"digitransit-search-util",
|
|
"${name}"
|
|
],
|
|
"author": "Digitransit Authors",
|
|
"license": "(AGPL-3.0 OR EUPL-1.2)"
|
|
}
|
|
`);
|
|
|
|
// Create LICENSE-AGPL
|
|
const licenseAGPL = join(__dirname, '..', '..', 'LICENSE-AGPL.txt');
|
|
copySync(licenseAGPL, join(folderPath, 'LICENSE-AGPL.txt'));
|
|
|
|
// Create LICENSE-EUPL
|
|
const licenseEUPL = join(__dirname, '..', '..', 'LICENSE-EUPL.txt');
|
|
copySync(licenseEUPL, join(folderPath, 'LICENSE-EUPL.txt'));
|
|
|
|
// Create test.js
|
|
writeFileSync(join(folderPath, 'test.js'), `/* eslint-disable import/no-extraneous-dependencies */
|
|
import { expect } from 'chai';
|
|
import { describe, it } from 'mocha';
|
|
import ${camelcaseName} from '.';
|
|
|
|
describe('Testing @digitransit-search-util/digitransit-search-util-${decamelizeName} module', () => {
|
|
it('Checking that true is true', () => {
|
|
//const retValue = ${camelcaseName}(param1, param2);
|
|
expect(true).to.be.equal(true);
|
|
});
|
|
});
|
|
`);
|
|
|
|
// Create README.md
|
|
writeFileSync(join(folderPath, 'README.md'), `# @digitransit-search-util/${decamelizeName}
|
|
|
|
# ${camelcaseName}
|
|
|
|
<DESCRIPTION>
|
|
|
|
**Parameters**
|
|
<PARAMETERS>
|
|
|
|
**Examples**
|
|
|
|
<!-- This file is automatically generated. Please don't edit it directly:
|
|
if you find an error, edit the source file (likely index.js), and re-run
|
|
./scripts/generate-readmes in the digitransit-search-util project. -->
|
|
|
|
---
|
|
|
|
This module is part of the Digitransit project. It is maintained in the
|
|
[HSLdevcom/digitransit-ui](https://github.com/HSLdevcom/digitransit-ui) repository, where you can create
|
|
PRs and issues.
|
|
|
|
### Installation
|
|
|
|
Install this module individually:
|
|
|
|
\`\`\`sh
|
|
$ npm install @digitransit-search-util/${decamelizeName}
|
|
\`\`\`
|
|
|
|
Or install the digitransit-search-util module that includes it as a function:
|
|
|
|
\`\`\`sh
|
|
$ npm install @digitransit-search-util/digitransit-search-util
|
|
\`\`\`
|
|
`);
|