Skip to content

Commit

Permalink
Removes chic.js dependency for sveltekit projects
Browse files Browse the repository at this point in the history
  • Loading branch information
markschellhas committed Jul 14, 2024
1 parent d004424 commit 45bf745
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 110 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ or in your project directory:
npm install chic.js
```

## [1.4.3] - 2024-07-17

- small refactor: removes `chic.js` as a dependency in `package.json` file

## [1.4.3] - 2024-03-04

- bug fix on destroy method for api endpoints
Expand Down
24 changes: 4 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,8 @@ prog
// Run init function
init();

// Install chic.js as dependency:
console.log(`> Installing chic.js in project ${name}`);
const installChicProcess = spawn('npm', ['install', 'chic.js', '--save'], {
stdio: 'inherit',
shell: true
});

installChicProcess.on('error', (error) => {
console.error(`Error installing chic.js: ${error}`);
});

installChicProcess.on('exit', (code) => {
if (code !== 0) {
console.error(`The process exited with code ${code}`);
} else {
console.log('Chic.js installed successfully');

// Install sequelize
// Install sequelize
console.log(`> Installing sequelize in project ${name}`);
const installSequelizeProcess = spawn('npm', ['install', 'sequelize', '--save'], {
stdio: 'inherit',
Expand Down Expand Up @@ -131,8 +115,6 @@ prog
});
}
});
}
});

}
});
Expand Down Expand Up @@ -261,7 +243,9 @@ prog
prog
.command('*', '', { default: true })
.action(() => {
console.log(CONSOLE_COLOR.BLUE, `Chic.js`);
console.log(CONSOLE_COLOR.BLUE, "╔═╗┬ ┬┬┌─┐ ┬┌─┐");
console.log(CONSOLE_COLOR.BLUE, "║ ├─┤││ │└─┐");
console.log(CONSOLE_COLOR.BLUE, "╚═╝┴ ┴┴└─┘o└┘└─┘");
console.log(CONSOLE_COLOR.BLUE, `Version: ${pjson.version}`);
console.log(CONSOLE_COLOR.BLUE, `Author: Mark Schellhas`);
console.log(CONSOLE_COLOR.BLUE, `For help, run chic --help`);
Expand Down
21 changes: 11 additions & 10 deletions lib/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fs from 'fs';
import readline from 'readline';
import path from 'path';
import { fileURLToPath } from 'url';
import YAML from 'yaml';

import { getNamespaces, singularize, pluralize, transformFieldsToObject, capitalize, CONSOLE_COLOR } from './helpers.js';

Expand Down Expand Up @@ -39,6 +38,17 @@ export function init() {
// serialize data to JSON string
const data = JSON.stringify(chicConfig, null, 2);

// Copy file from this package to the project's root directory:
const dirname = packageDirName();

// open file relative to this npm package:
const routeTableFile = fs.readFileSync(path.join(dirname, '../ui/renderedRouteTable.js'), 'utf8');
// copy file to project root:
const projectRoot = findProjectRoot(process.cwd());
const newFilePath = path.join(projectRoot, 'src', 'RouteTable.js');
fs.writeFileSync(newFilePath, routeTableFile);


// create a file:
return fs.writeFile('chic.json', data, async (err) => {
if (err) {
Expand Down Expand Up @@ -568,15 +578,6 @@ export function readConfig() {
return chicConfig;
};

export function readYamlConfig() {
// read file
const data = fs.readFileSync('chic.yaml', 'utf8');
// parse JSON
const chicConfig = YAML.parse(data);
// return config
return chicConfig;
};

export function updateConfig(payload) {
// read file
const data = fs.readFileSync('chic.json');
Expand Down
31 changes: 0 additions & 31 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { YAMLMap } from "yaml";
import YAML from 'yaml';
// Helpers
export function pluralize(val) {
if (val.endsWith('s')) return val;
Expand Down Expand Up @@ -76,35 +74,6 @@ export function styledBy(options) {

}

/**
*
* @param {YAMLMap} input
*/
export function transformYamlModelsAndFields(input){
let parsed = YAML.parseDocument(input).toJSON(
{
mapAsMap: true,
keepBlobsInJSON: true
});
// console.log(parsed);

for (const [key, value] of Object.entries(parsed)) {
if (key === 'models') {
// console.log(parsed[key]);
parsed[key] = value.map(v => {
// console.log(v);
return {
...v,
fields: transformFieldsToObject(v.fields)
}
});
}
}
//
// console.log(parsed);
return parsed;
}

export const CONSOLE_COLOR = {
RED: '\x1b[31m%s\x1b[0m',
BLUE: '\x1b[36m%s\x1b[0m',
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/hooks_server_template.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chicConfig from '../chic.json';
import { RoutesTable } from 'chic.js/ui';
import { RoutesTable } from './RoutesTable.js';
import { CHIC_DEBUG } from '$env/static/private';

/** @type {import('@sveltejs/kit').Handle} */
Expand Down
19 changes: 7 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chic.js",
"version": "1.4.3",
"version": "1.4.4",
"description": "CLI for rapidly scaffolding SvelteKit apps",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -33,8 +33,7 @@
"url": "https://ko-fi.com/sveltesafari"
},
"dependencies": {
"sade": "^1.8.1",
"yaml": "^2.3.1"
"sade": "^1.8.1"
},
"devDependencies": {
"@babel/core": "^7.22.9",
Expand Down
33 changes: 0 additions & 33 deletions test/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,37 +101,4 @@ describe("styledBy", () => {
expect(result).toEqual([false, '', '', '']);
});

});

describe("transformYamlModelsAndFields", () => {
it("should return an array of objects with name and fields properties", () => {
const yaml = `
models:
- name: User
fields: name age:number
- name: Post
fields: title body:text
`;
const result = transformYamlModelsAndFields(yaml);
expect(result).toEqual({
models: [
{
name: 'User',
fields: [
{ name: 'name', type: 'string' },
{ name: 'age', type: 'number' }
]
},
{
name: 'Post',
fields: [
{ name: 'title', type: 'string' },
{ name: 'body', type: 'text' }
]
}
]
});

});

});

0 comments on commit 45bf745

Please sign in to comment.