Skip to content

Commit

Permalink
Tests passing again
Browse files Browse the repository at this point in the history
  • Loading branch information
foxleigh81 committed Aug 16, 2022
1 parent 88e40e7 commit 4af9332
Show file tree
Hide file tree
Showing 42 changed files with 529 additions and 680 deletions.
30 changes: 30 additions & 0 deletions builda/.builda.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"app": {
"name": "test"
},
"commands": {
"atom": {
"type": "scaffold",
"outputPath": "./experiments/atom",
"use": "default-ts",
"substitute": {}
},
"component": {
"type": "scaffold",
"outputPath": "./experiments/component",
"use": "default-ts",
"substitute": {}
},
"test": {
"type": "scaffold",
"outputPath": "./experiments/test",
"use": "default-ts",
"substitute": {}
}
},
"modules": {
"scaffold": {
"default-ts": "1.0.0"
}
}
}
30 changes: 30 additions & 0 deletions builda/.builda/modules/scaffold/default-ts/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';

/* Types */
interface Props extends React.ComponentProps<'div'> {
/**
* The component text
*/
text: string;
}

/**
* The %SENTENCE_CASE% %TYPE%
*/
export const %PASCAL_CASE%: React.FC<Props> = ({
text = 'Made with Builda',
className,
...props
}: Props) => {

return (
<div className={`'%KEBAB_CASE%' ${className}`} {...props}>
{text}
</div>
);
};

%PASCAL_CASE%.displayName = '%PASCAL_CASE%'

export default %PASCAL_CASE%;
export type { Props };
20 changes: 20 additions & 0 deletions builda/.builda/modules/scaffold/default-ts/registry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "default-ts",
"type": "scaffold",
"version": "1.0.0",
"author": "Alex Foxleigh (https://www.alexfoxleigh.com/)",
"funding": "https://www.patreon.com/builda",
"moduleUrl": "https://builda.add/scaffolds/default-ts",
"description": "This is the default typescript scaffold that ships with builda. It only has the bare minimum of dependencies to get you started.\n",
"keywords": [
"react",
"typescript"
],
"files": [
"index.tsx"
],
"dependencies": {
"react": "^17.0.0",
"typescript": "^4.5.0"
}
}
14 changes: 0 additions & 14 deletions builda/.gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +0,0 @@
.vscode/
.DS_Store
/node_modules
npm-debug.log
/components
log.txt
.builda.yml
.buildcomrc
.nyc_output/
coverage/
src/helpers/globals.ts
**/tsconfig.tsbuildinfo
/experiments
.builda/*
2 changes: 1 addition & 1 deletion builda/dist/data/globals.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = { "version": "3.0.0-alpha.1", "buildaDir": ".builda", "configFileName": ".builda.yml", "websiteUrl": "https://www.builda.app" };
exports.default = { "version": "3.0.0-alpha.1", "buildaDir": ".builda", "configFileName": ".builda.json", "websiteUrl": "https://www.builda.app" };
2 changes: 1 addition & 1 deletion builda/dist/data/globals.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default {"version":"3.0.0-alpha.1","buildaDir":".builda","configFileName":".builda.yml","websiteUrl":"https://www.builda.app"};
export default {"version":"3.0.0-alpha.1","buildaDir":".builda","configFileName":".builda.json","websiteUrl":"https://www.builda.app"};
9 changes: 3 additions & 6 deletions builda/dist/helpers/get-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const js_yaml_1 = __importDefault(require("js-yaml"));
const globals_1 = __importDefault(require("../data/globals"));
const { configFileName } = globals_1.default;
const configFile = path_1.default.join(configFileName);
const configFile = path_1.default.resolve(configFileName);
const getConfigFile = () => {
if (fs_1.default.existsSync(configFile)) {
const config = js_yaml_1.default.load(fs_1.default.readFileSync(configFile, 'utf8'), {
json: true
});
return config;
const config = fs_1.default.readFileSync(configFile, 'utf8');
return JSON.parse(config);
}
else {
return null;
Expand Down
7 changes: 3 additions & 4 deletions builda/dist/helpers/get-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.getmodule = void 0;
const fs_1 = __importDefault(require("fs"));
const js_yaml_1 = __importDefault(require("js-yaml"));
// Import globals
const globals_1 = __importDefault(require("../data/globals"));
// Import helpers
Expand All @@ -17,9 +16,9 @@ const getmodule = (name) => {
const moduleList = config.modules;
const moduleCategory = moduleTypes.find((category) => { var _a; return moduleList[category] && ((_a = moduleList === null || moduleList === void 0 ? void 0 : moduleList[category]) === null || _a === void 0 ? void 0 : _a[name]); });
const path = `${globals_1.default.buildaDir}/modules/${moduleCategory}/${name}`;
const registryFile = fs_1.default.readFileSync(`${path}/registry.yaml`, 'utf8');
const registry = js_yaml_1.default.load(registryFile, { json: true });
const files = registry.files.filter((file) => file !== 'registry.yaml');
console.log(path);
const registry = JSON.parse(fs_1.default.readFileSync(`${path}/registry.json`, 'utf8'));
const files = registry.files.filter((file) => file !== 'registry.json');
return {
path,
registry,
Expand Down
9 changes: 3 additions & 6 deletions builda/dist/helpers/get-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRegistry = void 0;
const axios_1 = __importDefault(require("axios"));
const js_yaml_1 = __importDefault(require("js-yaml"));
const fs_1 = __importDefault(require("fs"));
const convert_registry_path_to_url_1 = __importDefault(require("./convert-registry-path-to-url"));
const detect_path_type_1 = __importDefault(require("./detect-path-type"));
const getRegistry = async (registryPath) => {
const pathType = (0, detect_path_type_1.default)(registryPath);
let registryData;
if (pathType === 'local') {
registryData = fs_1.default.readFileSync(`${registryPath}/registry.yaml`, 'utf8');
return JSON.parse(fs_1.default.readFileSync(`${registryPath}/registry.json`, 'utf8'));
}
if (pathType === 'remote') {
const registryUrl = `${(0, convert_registry_path_to_url_1.default)(registryPath)}/registry.yaml`;
const registryUrl = `${(0, convert_registry_path_to_url_1.default)(registryPath)}/registry.json`;
try {
const response = await axios_1.default.get(registryUrl);
registryData = response.data;
return response.data;
}
catch (error) {
throw new Error(error);
}
}
return js_yaml_1.default.load(registryData, { json: true });
};
exports.getRegistry = getRegistry;
exports.default = exports.getRegistry;
2 changes: 1 addition & 1 deletion builda/dist/helpers/tests/change-case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const string_functions_1 = require("../string-functions");
describe('changeCase() convert from kebab case', () => {
beforeEach(() => {
// jest.spyOn(console, 'log').mockImplementation(() => {});
jest.spyOn(console, 'log').mockImplementation(() => { });
});
afterAll(() => {
jest.resetAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const fileList = ['index.stories.mdx', 'index.tsx', 'styles.module.scss'];
describe('getFileListFromRegistry() function', () => {
test('should return a list of files from a registry.json file', async () => {
axios_1.default.get = jest.fn().mockResolvedValue({ data: { files: fileList } });
const registryPath = 'https://raw.githubusercontent.com/st-elmos-fire/builda/master/scaffolds/component-with-storybook';
const registryPath = 'https://builda.app/scaffolds/foxys-own';
const registryContent = await (0, get_registry_1.getRegistry)(registryPath);
expect(axios_1.default.get).toHaveBeenCalledWith(`${registryPath}/registry.json`);
expect(registryContent).toEqual(fileList);
expect(registryContent.files).toEqual(fileList);
});
});
38 changes: 19 additions & 19 deletions builda/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,53 +65,53 @@ const CREATE_CONFIG_QUESTION = {
const commands = config ? (0, generate_commands_1.default)() : [];
const commandString = process.argv[2].replace('--', '');
const command = commands.find((c) => c.name === commandString);
const getSubstitutions = (command) => {
const getSubstitutions = (commandList) => {
const substitutions = [];
if (command.substitute) {
command.substitute.forEach((substitute) => {
if (commandList.substitute) {
commandList.substitute.forEach((sub) => {
var _a;
// No substitution was provided but the config requires one
if (substitute.required && !argv[substitute.string]) {
(0, _helpers_1.throwError)(`"--${substitute.string}" missing in arguments. This is required.\n`);
if (sub.required && !argv[sub.string]) {
(0, _helpers_1.throwError)(`"--${sub.string}" missing in arguments. This is required.\n`);
}
// User has not provided a substitution but the config has a default fallback value
if (substitute.default && !argv[substitute.string]) {
if (sub.default && !argv[sub.string]) {
substitutions.push({
replace: substitute.string,
with: substitute.default
replace: sub.string,
with: sub.default
});
}
// User has provided the substitution argument
if (argv[substitute.string]) {
const value = argv[substitute.string] === true
if (argv[sub.string]) {
const value = argv[sub.string] === true
? ''
: argv[substitute.string];
: argv[sub.string];
// User has provided the substitution argument with no value
if (value === '') {
(0, _helpers_1.throwError)(`"--${substitute.string}" requires a value`);
(0, _helpers_1.throwError)(`"--${sub.string}" requires a value`);
}
if (substitute.valid &&
if (sub.valid &&
value !== '' &&
!((_a = substitute.valid) === null || _a === void 0 ? void 0 : _a.includes(value))) {
(0, _helpers_1.throwError)(`\n"${value}" is not a valid ${substitute.string}. Please use one of the following: \n - ${substitute.valid.join(`\n - `)}\n`);
!((_a = sub.valid) === null || _a === void 0 ? void 0 : _a.includes(value))) {
(0, _helpers_1.throwError)(`\n"${value}" is not a valid ${sub.string}. Please use one of the following: \n - ${sub.valid.join(`\n - `)}\n`);
}
// The value provided is valid
substitutions.push({
replace: substitute.string,
with: argv[substitute.string]
replace: sub.string,
with: argv[sub.string]
});
}
});
}
return substitutions;
};
const substitutions = getSubstitutions(command);
const substitute = getSubstitutions(command);
if (command) {
const name = argv._[1].toString();
return (0, build_from_scaffold_1.default)({
name,
command: command.name,
substitute: substitutions
substitute
});
}
else {
Expand Down
4 changes: 2 additions & 2 deletions builda/dist/mocks/preset-answers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ exports.presetAnswers = void 0;
exports.presetAnswers = {
appName: 'test',
outputDirectory: './experiments',
installDefaultModule: 'default-js',
scaffoldUrl: 'http://test.url',
installDefaultModule: 'typescript',
scaffoldUrl: '',
scaffoldSelection: ['atom', 'component'],
customScaffoldList: 'test'
};
Expand Down
14 changes: 7 additions & 7 deletions builda/dist/scripts/add-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.addModule = void 0;
const axios_1 = __importDefault(require("axios"));
const fs_1 = __importDefault(require("fs"));
const js_yaml_1 = __importDefault(require("js-yaml"));
// Import helpers
const _helpers_1 = require("../helpers/index.js");
// Import data
Expand All @@ -25,10 +24,10 @@ const addLocalModule = async (modulePath) => {
// filter out the ignore files
const filteredFiles = files.filter((file) => !ignoreFiles.includes(file));
// write the files to the output directory
filteredFiles.forEach((file) => {
filteredFiles.forEach(async (file) => {
const srcPath = `${modulePath}/${file}`;
const outputPath = `${globals_1.default.buildaDir}/modules/${registry.type}/${registry.name}`;
(0, _helpers_1.createDir)(outputPath).then(() => {
await (0, _helpers_1.createDir)(outputPath).then(() => {
fs_1.default.copyFileSync(srcPath, `${outputPath}/${file}`);
});
});
Expand All @@ -37,17 +36,18 @@ const addLocalModule = async (modulePath) => {
const addRemoteModule = async (modulePath) => {
// get the directory contents
const registry = await (0, _helpers_1.getRegistry)(modulePath);
const files = [...registry.files, 'registry.yaml'];
const files = [...registry.files, 'registry.json'];
files
.filter((file) => !ignoreFiles.includes(file))
.forEach((file) => {
// Download the file
axios_1.default
.get(`${modulePath}/${file}`)
.then((response) => {
const content = file === 'registry.json' ? JSON.stringify(response.data, null, 2) : response.data.toString();
const fileObject = {
name: file,
content: response.data
content
};
const outputPath = `${globals_1.default.buildaDir}/modules/${registry.type}/${registry.name}`;
(0, _helpers_1.createDir)(outputPath).then(() => {
Expand Down Expand Up @@ -101,8 +101,8 @@ const addModule = async ({ path, official }) => {
prefabs[name] = version;
}
// Write the config file
fs_1.default.writeFileSync(globals_1.default.configFileName, js_yaml_1.default.dump(config, { indent: 2 }));
return (0, _helpers_1.printMessage)(`${(0, string_functions_1.default)(type, 'pascal')}: ${name}@${version} installed`, 'success');
fs_1.default.writeFileSync(globals_1.default.configFileName, JSON.stringify(config, null, 2));
(0, _helpers_1.printMessage)(`${(0, string_functions_1.default)(type, 'pascal')}: ${name}@${version} installed`, 'success');
}
});
}
Expand Down
Loading

0 comments on commit 4af9332

Please sign in to comment.