Skip to content

Commit

Permalink
feat: remove semi
Browse files Browse the repository at this point in the history
  • Loading branch information
khoilen committed Jan 4, 2025
1 parent 222018a commit c5c3e8b
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 149 deletions.
104 changes: 59 additions & 45 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,17 +29,23 @@ 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 @@ -50,42 +56,50 @@ 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: 55 additions & 53 deletions apps/nt-stylesheet/bin/init-tailwind.spec.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,98 @@
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: 7 additions & 3 deletions apps/nt-stylesheet/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/** @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: [],
};
}
4 changes: 2 additions & 2 deletions apps/nt-stylesheet/themes/font.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const fontFamily = {
sans: ['Mulish', 'ui-sans-serif', 'system-ui', 'sans-serif'],
};
}

export const fontWeight = {
black: '900',
Expand All @@ -12,4 +12,4 @@ export const fontWeight = {
light: '300',
extralight: '200',
thin: '100',
};
}
51 changes: 26 additions & 25 deletions apps/nt-stylesheet/themes/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import { ThemeConfig } from 'tailwindcss/types/config';
import { ThemeConfig } from 'tailwindcss/types/config'

import { backgroundColor, boxShadow, colors } from './colors';
import { fontFamily, fontWeight } from './font';
import { borderRadius } from './radius';
import { gap, spacing } from './spacing';
import { backgroundColor, boxShadow, colors } from './colors'
import { fontFamily, fontWeight } from './font'
import { borderRadius } from './radius'
import { gap, spacing } from './spacing'

const theme: Partial<ThemeConfig & { extend: Partial<ThemeConfig> }> = {
extend: {
gap,
spacing,
borderRadius,
colors,
fontFamily,
fontWeight,
screens: {
'viewport-min': '80rem',
const theme: Partial<ThemeConfig & { extend: Partial<ThemeConfig> }> =
{
extend: {
gap,
spacing,
borderRadius,
colors,
fontFamily,
fontWeight,
screens: {
'viewport-min': '80rem',

'viewport-max': '120rem',
'page-container-max': '80rem',
},
backgroundColor,
boxShadow,
'viewport-max': '120rem',
'page-container-max': '80rem',
},
backgroundColor,
boxShadow,

gridTemplateColumns: {
DEFAULT: 'repeat(12, minmax(0, 1fr))',
gridTemplateColumns: {
DEFAULT: 'repeat(12, minmax(0, 1fr))',
},
},
},
};
}

export default theme;
export default theme
Loading

0 comments on commit c5c3e8b

Please sign in to comment.