-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
113 lines (104 loc) · 3.94 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env node
const fs = require('fs');
const chalk = require('chalk');
const argv = require('yargs').argv;
function createDirectories() {
/**
* Create ITCSS directories.
*/
fs.mkdir('settings', function () {
console.log(chalk.bgGreen("Created the settings folder."));
});
fs.mkdir('tools', function () {
console.log(chalk.bgGreen("Created the tools folder."));
});
fs.mkdir('generic', function () {
console.log(chalk.bgGreen("Created the generic folder."));
});
fs.mkdir('elements', function () {
console.log(chalk.bgGreen("Created the elements folder."));
});
fs.mkdir('objects', function () {
console.log(chalk.bgGreen("Created the objects folder."));
});
fs.mkdir('components', function () {
console.log(chalk.bgGreen("Created the components folder."));
});
fs.mkdir('utilities', function () {
console.log(chalk.bgGreen("Created the utilities folder."));
});
}
function createFiles() {
/**
* Create the base files for the ITCSS directories.
*/
fs.open('settings/_settings.scss', 'w', function (err, file) {
if (err) throw err;
console.log(chalk.green('Created settings/_settings.scss file'));
});
fs.open('tools/_tools.scss', 'w', function (err, file) {
if (err) throw err;
console.log(chalk.green('Created tools/_tools.scss file'));
});
fs.open('generic/_generic.scss', 'w', function (err, file) {
if (err) throw err;
console.log(chalk.green('Created generic/_generic.scss file'));
});
fs.open('elements/_elements.scss', 'w', function (err, file) {
if (err) throw err;
console.log(chalk.green('Created elements/_elements.scss file'));
});
fs.open('objects/_objects.scss', 'w', function (err, file) {
if (err) throw err;
console.log(chalk.green('Created objects/_objects.scss file'));
});
fs.open('components/_components.scss', 'w', function (err, file) {
if (err) throw err;
console.log(chalk.green('Created components/_components.scss file'));
});
fs.open('utilities/_utilities.scss', 'w', function (err, file) {
if (err) throw err;
console.log(chalk.green('Created utilities/_utilities.scss file'));
});
}
if (argv.file) {
let file_name = argv.file;
let file_extension = file_name.split('.').pop();
if (file_extension === 'scss'){
exports.createDirectories = createDirectories();
exports.createFiles = createFiles();
fs.writeFile(argv.file,
"@import 'settings/settings';\n" +
"@import 'tools/tools';\n" +
"@import 'generic/generic';\n" +
"@import 'elements/elements';\n" +
"@import 'objects/objects';\n" +
"@import 'components/components';\n" +
"@import 'utilities/utilities';\n",
function (err, file) {
if (err) throw err;
console.log(chalk.green('Created ' + argv.file + ' file.'));
});
} else if(file_extension === 'sass'){
exports.createDirectories = createDirectories();
exports.createFiles = createFiles();
fs.writeFile(argv.file,
"@import 'settings/settings'\n" +
"@import 'tools/tools'\n" +
"@import 'generic/generic'\n" +
"@import 'elements/elements'\n" +
"@import 'objects/objects'\n" +
"@import 'components/components'\n" +
"@import 'utilities/utilities'\n",
function (err, file) {
if (err) throw err;
console.log(chalk.green('Created' + argv.file + ' file'));
});
} else{
throw (chalk.red('Incompatible file type. Use either .scss or .sass file extension.'));
}
} else{
exports.createDirectories = createDirectories();
exports.createFiles = createFiles();
}
console.log(chalk.bold("Thank You for using @r0b0t/itcss.\n"));