Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump json5 from 2.1.3 to 2.2.3 #11

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions AntComponent/component.template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';

const path = require('path');
const common = require(path.resolve(__dirname, '../common'));

const {
createComponentName,
createClassName,
createModuleName,
} = common;

const createComponent = (opts = {}) => {
const {
name = '',
className = '',
moduleName = '',
componentName = '',
} = opts;

return `
import type { FC } from '@alipay/bigfish/react';

import React from '@alipay/bigfish/react';
import classnames from '@alipay/bigfish/util/classnames';

import style from './style.less';

interface ${componentName}Props {
className?: string;
}

const ${componentName}: FC<${componentName}Props> = (props) => {
const {
className = '',
children,
...others
} = props;

const cls = classnames({
[style.${moduleName}]: true,
[className]: !!className,
});

return (
<div className={cls} {...others}>
{ children }
</div>
);
};

export default ${ componentName };
`;
};

module.exports = (opts) => {
const componentName = createComponentName(opts);
const className = createClassName(opts);
const moduleName = createModuleName(opts);

const res = { componentName, className , moduleName, ...opts};

return createComponent(res);
};
17 changes: 17 additions & 0 deletions AntComponent/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const path = require('path');
const common = require(path.resolve(__dirname, '../common'));

const { createComponentName } = common;

const create = ({ compName } = {}) => `
export * from './${compName}';
export { default } from './${compName}';
`;

module.exports = (opts) => {
const compName = createComponentName(opts);

return create({ compName });
};
12 changes: 12 additions & 0 deletions AntComponent/style.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const path = require('path');
const common = require(path.resolve(__dirname, '../common'));

const { createModuleName } = common;

module.exports = opts => `
.${createModuleName(opts)} {
:global {}
}
`;
9 changes: 9 additions & 0 deletions __tests__/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,12 @@ test('create single page function', () => {

expect(included).toBe(true);
});

test('create ant typescript component function', () => {
child_process.execSync(`node ${INDEX_PATH} AntComponentFunction -a`,{ cwd: RUNTIME_PATH });

const list = getFiles(RUNTIME_PATH);
const included = icludes(list);

expect(included).toBe(true);
});
31 changes: 31 additions & 0 deletions __tests__/files/AntComponentFunction/AntComponentFunction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { FC } from '@alipay/bigfish/react';

import React from '@alipay/bigfish/react';
import classnames from '@alipay/bigfish/util/classnames';

import style from './style.less';

interface AntComponentFunctionProps {
className?: string;
}

const AntComponentFunction: FC<AntComponentFunctionProps> = (props) => {
const {
className = '',
children,
...others
} = props;

const cls = classnames({
[style.antComponentFunction]: true,
[className]: !!className,
});

return (
<div className={cls} {...others}>
{ children }
</div>
);
};

export default AntComponentFunction;
2 changes: 2 additions & 0 deletions __tests__/files/AntComponentFunction/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './AntComponentFunction';
export { default } from './AntComponentFunction';
3 changes: 3 additions & 0 deletions __tests__/files/AntComponentFunction/style.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.antComponentFunction {
:global {}
}
63 changes: 63 additions & 0 deletions createAntComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env node
'use strict';

const fs = require("fs");
const path = require("path");
const program = require("commander");

const BASR_PATH = path.resolve(__dirname, './AntComponent');
const common = require(path.resolve(__dirname, './common'));

const {
clearLine,
createClassName,
createModuleName,
createComponentName,
} = common;

function wirte(path, code) {
fs.writeSync(fs.openSync(path, "w"), clearLine(code));
};

function createAntComponent(opts = {}) {
const fileNames = fs.readdirSync(BASR_PATH);
const name = createComponentName(opts);
const { isSingle } = opts;

const dir = isSingle ? path.resolve() : path.resolve(name);

if (isSingle) {
const fn = require(path.resolve(BASR_PATH, 'component.template.js'));
const code = fn(opts);
const filePath = path.resolve(dir, `${name}.tsx`);

wirte(filePath, code);
return;
}

fs.mkdirSync(`./${name}`);

fileNames.forEach((fileName) => {
const fn = require(path.resolve(BASR_PATH, fileName));

switch (fileName) {
case 'component.template.js': {
const code = fn(opts);
const filePath = path.resolve(dir, `${name}.tsx`);

wirte(filePath, code);

break;
}
default: {
const code = fn(opts);
const filePath = path.resolve(dir, fileName);

wirte(filePath, code);
break;
}
}
});
}

module.exports = createAntComponent;
85 changes: 85 additions & 0 deletions createComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env node
'use strict';

const fs = require("fs");
const path = require("path");
const program = require("commander");

const BASR_PATH = path.resolve(__dirname, './Component');
const common = require(path.resolve(__dirname, './common'));

const {
clearLine,
createClassName,
createModuleName,
createComponentName,
} = common;

function wirte(path, code) {
fs.writeSync(fs.openSync(path, "w"), clearLine(code));
};

function createComponent(opts = {}) {
const fileNames = fs.readdirSync(BASR_PATH);
const name = createComponentName(opts);
const {
hooks: isHooks,
single: isSingle,
function: isFunction,
} = opts;

const dir = isSingle ? path.resolve() : path.resolve(name);

if (isSingle) {
const fn = require(path.resolve(BASR_PATH, 'component.template.js'));
const code = fn(opts);
const filePath = path.resolve(dir, `${name}.jsx`);

wirte(filePath, code);
return;
}

fs.mkdirSync(`./${name}`);

fileNames.forEach((fileName) => {
const fn = require(path.resolve(BASR_PATH, fileName));

switch (fileName) {
case 'component.template.js': {
const code = fn(opts);
const filePath = path.resolve(dir, `${name}.jsx`);

wirte(filePath, code);

break;
}
case 'style.template.js': {
const code = fn(opts);
const filePath = path.resolve(dir, `${name}.scss`);

wirte(filePath, code);

break;
}
case 'hooks.js': {
if (isHooks && isFunction) {
const code = fn(opts);
const filePath = path.resolve(dir, fileName);

wirte(filePath, code);
}

break;
}
default: {
const code = fn(opts);
const filePath = path.resolve(dir, fileName);

wirte(filePath, code);
break;
}
}
});
}

module.exports = createComponent;
Loading