Skip to content

Commit

Permalink
feat: update eslint with pretiier
Browse files Browse the repository at this point in the history
  • Loading branch information
khoilen committed Jan 4, 2025
1 parent 4370305 commit 1eb0acf
Show file tree
Hide file tree
Showing 19 changed files with 6,737 additions and 8,850 deletions.
24 changes: 10 additions & 14 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
{
"semi": false,
"trailingComma": "all",
"arrowParens": "always",
"singleQuote": true,
"printWidth": 70,
"endOfLine": "auto",
"bracketSpacing": true,
"jsxBracketSameLine": true,
"tabWidth": 4,
"importOrder": [
"^@core/(.*)$",
"^@server/(.*)$",
"^@ui/(.*)$",
"^[./]"
],
"importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"importOrderSideEffects": true,
"importOrderCaseInsensitive": true,
"plugins": ["@trivago/prettier-plugin-sort-imports"]
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": false,
"arrowParens": "always"
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"files.associations": {
"*.css": "tailwindcss",
"*.scss": "tailwindcss"
}
},
"prettier.bracketSpacing": false
}
104 changes: 45 additions & 59 deletions apps/nt-stylesheet/bin/init-tailwind.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/usr/bin/env node
import { exec } from 'child_process'
import fs from 'fs'
import readline from 'readline'
import {exec} from 'child_process';
import fs from 'fs';
import readline from 'readline';

export const installPackage = (packageName) => {
return new Promise((resolve, reject) => {
exec(`npm install ${packageName}`, (error) => {
if (error) {
console.error(
`Error installing ${packageName}: ${error.message}`,
)
reject(error)
return
`Error installing ${packageName}: ${error.message}`
);
reject(error);
return;
}
console.log(`${packageName} installed successfully!`)
resolve()
})
})
}
console.log(`${packageName} installed successfully!`);
resolve();
});
});
};

export const createTailwindConfig = () => {
const tailwindConfigContent = `/** @type {import('tailwindcss').Config} */
Expand All @@ -29,23 +29,17 @@ module.exports = {
},
plugins: [],
};
`
fs.writeFile(
'tailwind.config.js',
tailwindConfigContent,
(writeError) => {
if (writeError) {
console.error(
`Error writing tailwind.config.js: ${writeError.message}`,
)
return
}
console.log(
'tailwind.config.js has been initialized successfully!',
)
},
)
}
`;
fs.writeFile('tailwind.config.js', tailwindConfigContent, (writeError) => {
if (writeError) {
console.error(
`Error writing tailwind.config.js: ${writeError.message}`
);
return;
}
console.log('tailwind.config.js has been initialized successfully!');
});
};

export const createPostCSSConfig = () => {
const postcssConfigContent = `module.exports = {
Expand All @@ -56,50 +50,42 @@ export const createPostCSSConfig = () => {
autoprefixer: {},
},
};
`
`;

fs.writeFile(
'postcss.config.js',
postcssConfigContent,
(writeError) => {
if (writeError) {
console.error(
`Error writing postcss.config.js: ${writeError.message}`,
)
return
}
console.log(
'postcss.config.js has been created successfully!',
)
},
)
}
fs.writeFile('postcss.config.js', postcssConfigContent, (writeError) => {
if (writeError) {
console.error(
`Error writing postcss.config.js: ${writeError.message}`
);
return;
}
console.log('postcss.config.js has been created successfully!');
});
};

export const initialize = async () => {
try {
await installPackage('@nashtech/nt-stylesheet')
await installPackage('@nashtech/nt-stylesheet');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
});

rl.question(
'Do you want to initialize Tailwind CSS? (y/n) ',
(answer) => {
if (answer.toLowerCase() === 'y') {
createTailwindConfig()
createPostCSSConfig()
createTailwindConfig();
createPostCSSConfig();
} else {
console.log(
'Tailwind CSS initialization skipped.',
)
console.log('Tailwind CSS initialization skipped.');
}
rl.close()
},
)
rl.close();
}
);
} catch (error) {
console.error('Initialization failed:', error)
console.error('Initialization failed:', error);
}
}
};

initialize()
initialize();
108 changes: 53 additions & 55 deletions apps/nt-stylesheet/bin/init-tailwind.spec.js
Original file line number Diff line number Diff line change
@@ -1,98 +1,96 @@
import { exec } from 'child_process'
import fs from 'fs'
import readline from 'readline'
import { describe, expect, it, vi } from 'vitest'
import {exec} from 'child_process';
import fs from 'fs';
import readline from 'readline';
import {describe, expect, it, vi} from 'vitest';

import {
createPostCSSConfig,
createTailwindConfig,
initialize,
installPackage,
} from './init-tailwind.js'
} from './init-tailwind.js';

vi.mock('fs')
vi.mock('child_process')
vi.mock('readline')
vi.mock('fs');
vi.mock('child_process');
vi.mock('readline');

describe('init-tailwind.js', () => {
describe('installPackage', () => {
it('should install package successfully', async () => {
exec.mockImplementation((cmd, callback) => callback(null))
await expect(
installPackage('nt-stylesheet'),
).toStrictEqual(Promise.resolve())
exec.mockImplementation((cmd, callback) => callback(null));
await expect(installPackage('nt-stylesheet')).toStrictEqual(
Promise.resolve()
);
expect(exec).toHaveBeenCalledWith(
'npm install nt-stylesheet',
expect.any(Function),
)
})
expect.any(Function)
);
});

it('should fail to install package', async () => {
const error = new Error('Installation failed')
exec.mockImplementation((cmd, callback) =>
callback(error),
)
await expect(
installPackage('nt-stylesheet'),
).rejects.toThrow('Installation failed')
})
})
const error = new Error('Installation failed');
exec.mockImplementation((cmd, callback) => callback(error));
await expect(installPackage('nt-stylesheet')).rejects.toThrow(
'Installation failed'
);
});
});

describe('createTailwindConfig', () => {
it('should create tailwind.config.js file', () => {
fs.writeFile.mockImplementation(
(path, content, callback) => callback(null),
)
createTailwindConfig()
fs.writeFile.mockImplementation((path, content, callback) =>
callback(null)
);
createTailwindConfig();
expect(fs.writeFile).toHaveBeenCalledWith(
'tailwind.config.js',
expect.stringContaining('module.exports = {'),
expect.any(Function),
)
})
})
expect.any(Function)
);
});
});

describe('createPostCSSConfig', () => {
it('should create postcss.config.js file', () => {
fs.writeFile.mockImplementation(
(path, content, callback) => callback(null),
)
createPostCSSConfig()
fs.writeFile.mockImplementation((path, content, callback) =>
callback(null)
);
createPostCSSConfig();
expect(fs.writeFile).toHaveBeenCalledWith(
'postcss.config.js',
expect.stringContaining('module.exports = {'),
expect.any(Function),
)
})
})
expect.any(Function)
);
});
});

describe('initialize', () => {
it('should initialize successfully', async () => {
exec.mockImplementation((cmd, callback) => callback(null))
exec.mockImplementation((cmd, callback) => callback(null));
readline.createInterface.mockReturnValue({
question: (query, callback) => callback('y'),
close: vi.fn(),
})
fs.writeFile.mockImplementation(
(path, content, callback) => callback(null),
)
});
fs.writeFile.mockImplementation((path, content, callback) =>
callback(null)
);

await initialize()
await initialize();

expect(exec).toHaveBeenCalledWith(
'npm install nt-stylesheet',
expect.any(Function),
)
expect.any(Function)
);
expect(fs.writeFile).toHaveBeenCalledWith(
'tailwind.config.js',
expect.stringContaining('module.exports = {'),
expect.any(Function),
)
expect.any(Function)
);
expect(fs.writeFile).toHaveBeenCalledWith(
'postcss.config.js',
expect.stringContaining('module.exports = {'),
expect.any(Function),
)
})
})
})
expect.any(Function)
);
});
});
});
6 changes: 3 additions & 3 deletions apps/nt-stylesheet/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './styles/styles.scss'
import ntTheme from './themes'
import './styles/styles.scss';
import ntTheme from './themes';

export default ntTheme
export default ntTheme;
2 changes: 1 addition & 1 deletion apps/nt-stylesheet/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
10 changes: 3 additions & 7 deletions apps/nt-stylesheet/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/** @type {import('tailwindcss').Config} */
const ntTheme = require('./themes').default
const ntTheme = require('./themes').default;

module.exports = {
content: [
'./styles/**/*.scss',
'./themes/**/*.ts',
'./index.html',
],
content: ['./styles/**/*.scss', './themes/**/*.ts', './index.html'],
theme: {
extend: ntTheme.extend,
},
plugins: [],
}
};
Loading

0 comments on commit 1eb0acf

Please sign in to comment.