lapikit 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/bin/helper.js +74 -0
- package/bin/lapikit.js +54 -0
- package/bin/modules/adapter.js +52 -0
- package/bin/modules/preset.js +11 -0
- package/package.json +8 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Nycolaide <https://github.com/Nycolaide>.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/helper.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const color = {
|
|
2
|
+
red: (text) => `\x1b[31m${text}\x1b[0m`,
|
|
3
|
+
green: (text) => `\x1b[32m${text}\x1b[0m`,
|
|
4
|
+
yellow: (text) => `\x1b[33m${text}\x1b[0m`,
|
|
5
|
+
blue: (text) => `\x1b[34m${text}\x1b[0m`,
|
|
6
|
+
purple: (text) => `\x1b[35m${text}\x1b[0m`,
|
|
7
|
+
cyan: (text) => `\x1b[36m${text}\x1b[0m`
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const variant = {
|
|
11
|
+
bold: (text) => `\x1b[1m${text}\x1b[0m`,
|
|
12
|
+
underline: (text) => `\x1b[4m${text}\x1b[0m`,
|
|
13
|
+
inverse: (text) => `\x1b[7m${text}\x1b[0m`
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const bold = {
|
|
17
|
+
red: (text) => `\x1b[1m\x1b[31m${text}\x1b[0m`,
|
|
18
|
+
green: (text) => `\x1b[1m\x1b[32m${text}\x1b[0m`,
|
|
19
|
+
yellow: (text) => `\x1b[1m\x1b[33m${text}\x1b[0m`,
|
|
20
|
+
blue: (text) => `\x1b[1m\x1b[34m${text}\x1b[0m`,
|
|
21
|
+
purple: (text) => `\x1b[1m\x1b[35m${text}\x1b[0m`,
|
|
22
|
+
cyan: (text) => `\x1b[1m\x1b[36m${text}\x1b[0m`
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const inverse = {
|
|
26
|
+
red: (text) => `\x1b[7m\x1b[31m${text}\x1b[0m`,
|
|
27
|
+
green: (text) => `\x1b[7m\x1b[32m${text}\x1b[0m`,
|
|
28
|
+
yellow: (text) => `\x1b[7m\x1b[33m${text}\x1b[0m`,
|
|
29
|
+
blue: (text) => `\x1b[7m\x1b[34m${text}\x1b[0m`,
|
|
30
|
+
purple: (text) => `\x1b[7m\x1b[35m${text}\x1b[0m`,
|
|
31
|
+
cyan: (text) => `\x1b[7m\x1b[36m${text}\x1b[0m`
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const underline = {
|
|
35
|
+
red: (text) => `\x1b[4m\x1b[31m${text}\x1b[0m`,
|
|
36
|
+
green: (text) => `\x1b[4m\x1b[32m${text}\x1b[0m`,
|
|
37
|
+
yellow: (text) => `\x1b[4m\x1b[33m${text}\x1b[0m`,
|
|
38
|
+
blue: (text) => `\x1b[4m\x1b[34m${text}\x1b[0m`,
|
|
39
|
+
purple: (text) => `\x1b[4m\x1b[35m${text}\x1b[0m`,
|
|
40
|
+
cyan: (text) => `\x1b[4m\x1b[36m${text}\x1b[0m`
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const ansi = {
|
|
44
|
+
color,
|
|
45
|
+
variant,
|
|
46
|
+
bold,
|
|
47
|
+
inverse,
|
|
48
|
+
underline
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const terminal = (type = 'info', msg) => {
|
|
52
|
+
const name = ansi.color.cyan('lapikit');
|
|
53
|
+
|
|
54
|
+
if (type === 'error') console.error(name, ansi.bold.red('[error]'), msg);
|
|
55
|
+
else if (type === 'warn') console.warn(name, ansi.bold.yellow('[warn]'), msg);
|
|
56
|
+
else if (type === 'success') console.warn(name, ansi.bold.green('[success]'), msg);
|
|
57
|
+
else if (type === 'none') console.log(msg);
|
|
58
|
+
else console.log(name, ansi.bold.blue('[info]'), msg);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export function getCssPathFromArgs() {
|
|
62
|
+
const args = process.argv.slice(2);
|
|
63
|
+
return args[1] || 'src/app.css';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function envTypescript() {
|
|
67
|
+
const directory = process.cwd();
|
|
68
|
+
try {
|
|
69
|
+
await fs.readFile(path.resolve(directory, 'tsconfig.json'), 'utf-8');
|
|
70
|
+
return true;
|
|
71
|
+
} catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
package/bin/lapikit.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { ansi, terminal, envTypescript } from './helper.js';
|
|
5
|
+
import { preset } from './modules/preset.js';
|
|
6
|
+
import { adapterCSSConfig, adapterViteConfig } from './modules/adapter.js';
|
|
7
|
+
|
|
8
|
+
const [, , command] = process.argv;
|
|
9
|
+
const typescriptEnabled = envTypescript();
|
|
10
|
+
|
|
11
|
+
if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
12
|
+
terminal(
|
|
13
|
+
'info',
|
|
14
|
+
`usage: ${ansi.color.yellow('npx lapikit init {cssPath}')}\n\n ${ansi.variant.bold('options:')}\n
|
|
15
|
+
- {cssPath}: (${ansi.color.cyan('src/app.css')}) customize path on your origin css file.\n\n`
|
|
16
|
+
);
|
|
17
|
+
process.exit(0);
|
|
18
|
+
} else if (command === 'init') {
|
|
19
|
+
console.log(' _ _ _ _ _ ');
|
|
20
|
+
console.log(' | | (_) | (_) | ');
|
|
21
|
+
console.log(' | | __ _ _ __ _| | ___| |_ ');
|
|
22
|
+
console.log(" | | / _` | '_ \\| | |/ / | __|");
|
|
23
|
+
console.log(' | |___| (_| | |_) | | <| | |_ ');
|
|
24
|
+
console.log(' |______\\__,_| .__/|_|_|\\_\\_|\\__|');
|
|
25
|
+
console.log(' | | ');
|
|
26
|
+
console.log(' |_| \n');
|
|
27
|
+
|
|
28
|
+
terminal('none', `${ansi.bold.blue('LAPIKIT')} - Component Library for Svelte\n\n`);
|
|
29
|
+
|
|
30
|
+
const configPath = path.resolve(process.cwd(), 'lapikit.config.js');
|
|
31
|
+
try {
|
|
32
|
+
await fs.writeFile(configPath, preset.trim() + '\n', 'utf8');
|
|
33
|
+
terminal('success', `has create lapikit.config.js on your project.`);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
terminal('error', `failed to create configuration file:\n\n ${error}`);
|
|
36
|
+
terminal(
|
|
37
|
+
'warn',
|
|
38
|
+
`you can create lapikit.config.js manually, please visite https://localhost:3000/docs for more information`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
await adapterViteConfig(typescriptEnabled);
|
|
43
|
+
await adapterCSSConfig();
|
|
44
|
+
|
|
45
|
+
terminal(
|
|
46
|
+
'info',
|
|
47
|
+
`${ansi.bold.blue('Thank to use lapikit, discover all posibility with lapikit on https://localhost:3000/docs')}\n\n`
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
console.log('Github: https://github.com/nycolaide/lapikit');
|
|
51
|
+
console.log('Support the developement: https://buymeacoffee.com/nycolaide');
|
|
52
|
+
} else {
|
|
53
|
+
terminal('error', `Command not recognized. Try 'npx lapikit -h'`);
|
|
54
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getCssPathFromArgs, terminal } from '../helper.js';
|
|
4
|
+
|
|
5
|
+
const importLapikitVite = `import { lapikit } from 'lapikit/vite';`;
|
|
6
|
+
const importLapikitCss = `@import 'lapikit/css';`;
|
|
7
|
+
|
|
8
|
+
export async function adapterViteConfig(typescript) {
|
|
9
|
+
const viteConfigPath = path.resolve(process.cwd(), `vite.config.${typescript ? 'ts' : 'js'}`);
|
|
10
|
+
try {
|
|
11
|
+
let viteConfig = await fs.readFile(viteConfigPath, 'utf8');
|
|
12
|
+
|
|
13
|
+
if (!viteConfig.includes(`${importLapikitVite}`))
|
|
14
|
+
viteConfig = `${importLapikitVite}\n` + viteConfig;
|
|
15
|
+
|
|
16
|
+
const pluginsRegex = /plugins:\s*\[([^\]]*)\]/;
|
|
17
|
+
const match = viteConfig.match(pluginsRegex);
|
|
18
|
+
|
|
19
|
+
if (match && !match[1].includes('lapikit()')) {
|
|
20
|
+
const updatedPlugins = match[1].trim() ? `${match[1].trim()}, lapikit()` : `lapikit()`;
|
|
21
|
+
|
|
22
|
+
viteConfig = viteConfig.replace(pluginsRegex, `plugins: [${updatedPlugins}]`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await fs.writeFile(viteConfigPath, viteConfig, 'utf8');
|
|
26
|
+
|
|
27
|
+
terminal('success', 'lapikit() has added on vite.config.(js|ts) successfully');
|
|
28
|
+
} catch (error) {
|
|
29
|
+
terminal(
|
|
30
|
+
'error',
|
|
31
|
+
`lapikit() encountered a problem while editing vite.config.(js|ts):\n ${error}.\n\n`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function adapterCSSConfig() {
|
|
37
|
+
const cssPath = getCssPathFromArgs();
|
|
38
|
+
const resolvedPath = path.resolve(process.cwd(), cssPath);
|
|
39
|
+
try {
|
|
40
|
+
await fs.access(resolvedPath);
|
|
41
|
+
let appCssContent = await fs.readFile(resolvedPath, 'utf8');
|
|
42
|
+
appCssContent = `${importLapikitCss}\n\n` + appCssContent;
|
|
43
|
+
await fs.writeFile(resolvedPath, appCssContent, 'utf8');
|
|
44
|
+
|
|
45
|
+
terminal('success', `lapikit/css has added on ${cssPath}.`);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
terminal(
|
|
48
|
+
'error',
|
|
49
|
+
`lapikit/css encountered a problem while editing ${cssPath}:\n ${error.message}.\n\n`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lapikit",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"publishConfig": {
|
|
5
6
|
"access": "public"
|
|
6
7
|
},
|
|
@@ -23,13 +24,19 @@
|
|
|
23
24
|
"test": "npm run test:unit -- --run"
|
|
24
25
|
},
|
|
25
26
|
"files": [
|
|
27
|
+
"bin",
|
|
26
28
|
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE",
|
|
27
31
|
"!dist/**/*.test.*",
|
|
28
32
|
"!dist/**/*.spec.*"
|
|
29
33
|
],
|
|
30
34
|
"sideEffects": [
|
|
31
35
|
"**/*.css"
|
|
32
36
|
],
|
|
37
|
+
"bin": {
|
|
38
|
+
"lapikit": "bin/lapikit.js"
|
|
39
|
+
},
|
|
33
40
|
"svelte": "./dist/index.js",
|
|
34
41
|
"types": "./dist/index.d.ts",
|
|
35
42
|
"type": "module",
|