mirror of
https://github.com/HSLdevcom/digitransit-ui
synced 2025-06-16 05:00:40 +02:00
161 lines
4.5 KiB
JavaScript
Executable file
161 lines
4.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-component-clone => clone
|
|
name = name.replace(/digitransit-component-/, '');
|
|
const camelcaseName = camelcase(name);
|
|
const decamelizeName = decamelize(name, '-');
|
|
const pascalCaseName = camelcase(name, {pascalCase: true});
|
|
|
|
// Create Folder
|
|
const folderPath = join(__dirname, '..', 'packages', `digitransit-component-${decamelizeName}`);
|
|
if (!existsSync(folderPath)) {
|
|
mkdirSync(folderPath);
|
|
mkdirSync(join(folderPath, 'src'));
|
|
}
|
|
|
|
// Create index.js
|
|
writeFileSync(join(folderPath, 'src', 'index.js'), `/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
|
|
/* eslint react/forbid-prop-types: 0 */
|
|
import PropTypes from 'prop-types';
|
|
import React, { Fragment } from 'react';
|
|
|
|
/**
|
|
* General component description in JSDoc format. Markdown is *supported*.
|
|
*
|
|
* @example
|
|
* <${pascalCaseName} />
|
|
*/
|
|
class ${pascalCaseName} extends React.Component {
|
|
static propTypes = {
|
|
}
|
|
|
|
static defaultProps = {
|
|
};
|
|
|
|
render() {
|
|
return <div>Show content</div>;
|
|
}
|
|
}
|
|
|
|
export default ${pascalCaseName};
|
|
`);
|
|
|
|
// Create package.json
|
|
writeFileSync(join(folderPath, 'package.json'), `{
|
|
"name": "@digitransit-component/digitransit-component-${decamelizeName}",
|
|
"version": "0.0.0",
|
|
"description": "digitransit-component ${decamelizeName} module",
|
|
"main": "lib/index.js",
|
|
"files": [
|
|
"/lib"
|
|
],
|
|
"publishConfig": {
|
|
"access": "public"
|
|
},
|
|
"scripts": {
|
|
"build:index": "ENV=production NAME=digitransit-component-${decamelizeName} webpack --config ../webpack.config.babel.js && yarn run docs",
|
|
"build:test": "babel test.js --presets=@babel/preset-react,@babel/preset-env --plugins=@babel/plugin-transform-class-properties,@babel/plugin-transform-numeric-separator --out-file test.generated",
|
|
"watch": "ENV=development NAME=digitransit-component-${decamelizeName} webpack --watch --config ../webpack.config.babel.js",
|
|
"clean": "rm -rf ./lib ./node_modules",
|
|
"test": "mocha -r esm test.generated",
|
|
"docs": "node -r esm ../../scripts/generate-readmes"
|
|
},
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "git://github.com/HSLdevcom/digitransit-ui.git"
|
|
},
|
|
"keywords": [
|
|
"digitransit-component",
|
|
"${pascalCaseName}"
|
|
],
|
|
"author": "Digitransit Authors",
|
|
"license": "(AGPL-3.0 OR EUPL-1.2)",
|
|
"peerDependencies": {
|
|
"i18next": "^19.3.3",
|
|
"prop-types": "^15.7.2",
|
|
"react": "^16.13.0"
|
|
}
|
|
}
|
|
`);
|
|
|
|
// 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 React from 'react';
|
|
import Adapter from 'enzyme-adapter-react-16';
|
|
import { expect } from 'chai';
|
|
import { describe, it } from 'mocha';
|
|
import { shallow, configure } from 'enzyme';
|
|
import ${pascalCaseName} from '.';
|
|
|
|
configure({ adapter: new Adapter() });
|
|
|
|
describe('Testing @digitransit-component/digitransit-component-${decamelizeName} module', () => {
|
|
const wrapper = shallow(<${pascalCaseName} />);
|
|
|
|
it('should render', () => {
|
|
expect(wrapper.isEmptyRender()).to.equal(false);
|
|
});
|
|
});
|
|
`);
|
|
|
|
// Create README.md
|
|
writeFileSync(join(folderPath, 'README.md'), `# @digitransit-component/${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-component folder. -->
|
|
|
|
---
|
|
|
|
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-component/${decamelizeName}
|
|
\`\`\`
|
|
|
|
Or install the digitransit-component module that includes it as a class:
|
|
|
|
\`\`\`sh
|
|
$ npm install @digitransit-component/digitransit-component
|
|
\`\`\`
|
|
`);
|