sinto 1.3.1 → 1.5.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/README.md CHANGED
@@ -24,7 +24,7 @@ mkdir app01
24
24
  cd app01
25
25
  ```
26
26
 
27
- Generate default directories and files:
27
+ Generate default web directories and files:
28
28
 
29
29
  ```cmd
30
30
  sin init
@@ -58,6 +58,7 @@ This command is generate public directory from src directory.
58
58
  * sin api - Generate fake REST API with hai-server
59
59
  * sin webpack - Generate Webpack project
60
60
  * sin pup - Generate Puppeteer test with Mocha
61
+ * sin rmno - Delete node_modules directory
61
62
 
62
63
  The Default task manager is gulp. Development serve is browser-sync.
63
64
 
@@ -112,16 +113,18 @@ app01/
112
113
 
113
114
  ## Puppeteer test with Mocha
114
115
 
115
- The sin pup command generate a Puppeteer test with Mocha default test file.
116
+ The **sin pup** command generate a Puppeteer test with Mocha default test file.
117
+
118
+ The **sin pup** command does not install the dependencies, it just writes them into the package.json file. Install the dependencies with the **npm i** or **pnpm i** command.
116
119
 
117
120
  Using:
118
121
 
119
122
  ```cmd
120
123
  sin pup
121
- npm install --save-dev puppeteer mocha
124
+ npm i
122
125
  ```
123
126
 
124
- Generated directories and files:
127
+ Generated directoriy and file:
125
128
 
126
129
  ```txt
127
130
  app01/
@@ -129,17 +132,23 @@ app01/
129
132
  `-apptest.js
130
133
  ```
131
134
 
132
- Add to package.json file a script:
135
+ Automatically adds the test script and dependencies to the package.json file.
133
136
 
134
137
  ```json
135
138
  {
136
139
  "scripts": {
137
140
  "test": "mocha"
141
+ },
142
+ "devDependencies": {
143
+ "mocha": "^x.y.z",
144
+ "puppeteer": "^x.y.z"
138
145
  }
139
146
  }
140
147
  ```
141
148
 
142
- Run the test:
149
+ The version numbers are updated.
150
+
151
+ Write the tests in test directory and run the tests:
143
152
 
144
153
  ```cmd
145
154
  npm test
package/build/build.js ADDED
@@ -0,0 +1,7 @@
1
+ const { exec } = require('child_process');
2
+
3
+ const build = (argv) => {
4
+ exec('npx gulp')
5
+ }
6
+
7
+ module.exports.build = build;
@@ -1,16 +1,44 @@
1
1
  const { createFile, createDirectory } = require('../tools/tools.js');
2
- const puppeteerTestContent = require('./testPupContent')
2
+ const puppeteerTestContent = require('./testPupContent');
3
+ const jsonfile = require('jsonfile');
4
+ const path = require('path');
5
+ const { exec } = require('child_process');
6
+ const { addDevDep } = require('../tools/dep.js');
3
7
 
4
- const createPuppeteerTest = () => {
8
+ const createPuppeteerTest = async () => {
5
9
  const dir = process.cwd();
6
10
  createDirectory(`${dir}/test`);
7
11
  createFile(`${dir}/test/apptest.js`, puppeteerTestContent);
8
- console.log('\n')
9
- console.log('Install the dependencies:')
10
- console.log(' npm install --save-dev puppeteer mocha')
11
- console.log('Add start script to package.json:')
12
- console.log(' \"test\": \"mocha\"')
13
- console.log('\n')
12
+
13
+ await writeTestScriptInPackageJson();
14
+ }
15
+
16
+ async function writeTestScriptInPackageJson() {
17
+ const dir = process.cwd();
18
+ const filePath = dir + '/package.json'
19
+ jsonfile.readFile(filePath, async (err, obj) => {
20
+ if(err) {
21
+ console.error('Error! Failed to read package.json file.', err);
22
+ return;
23
+ }
24
+ obj.scripts = obj.scripts || {};
25
+ obj.scripts["test"] = "mocha";
26
+
27
+ jsonfile.writeFile(filePath, obj, { spaces: 2 }, async (err) => {
28
+ if(err) {
29
+ console.error('Error! Failed to write package.json file!')
30
+ }else {
31
+ console.log('The package.json updated');
32
+ await writePuppeteerDependencies(['mocha', 'puppeteer']);
33
+ }
34
+ });
35
+ });
36
+ }
37
+
38
+ const writePuppeteerDependencies = async (packageNames) => {
39
+ const dir = process.cwd();
40
+ const filePath = dir + '/package.json';
41
+ await addDevDep(filePath, packageNames);
14
42
  }
15
43
 
16
44
  module.exports.createPuppeteerTest = createPuppeteerTest;
package/gents/gents.js ADDED
@@ -0,0 +1,36 @@
1
+ const tsconfigContent = require('./tsconfigContent');
2
+ const { createFile } = require('../tools/tools.js');
3
+ const jsonfile = require('jsonfile');
4
+ const { addDevDep } = require('../tools/dep.js');
5
+
6
+ const supplementTypescript = () => {
7
+ writeConfigFile();
8
+ showMsg();
9
+ addDependencies();
10
+ }
11
+
12
+ const writeConfigFile = () => {
13
+ const dir = process.cwd();
14
+ const path = `${dir}/tsconfig.json`;
15
+ jsonfile.writeFileSync(path, tsconfigContent, { spaces: 2 });
16
+ }
17
+
18
+ const showMsg = () => {
19
+ console.log(`
20
+ Proposal:
21
+ In the tsconfig.json file, leave the module value
22
+ at commonjs for a NodeJS project. In the case of
23
+ an ES project, rewrite it to, for example, ES6.
24
+
25
+ Install dependencies:
26
+ pnpm install
27
+ `);
28
+ }
29
+
30
+ const addDependencies = () => {
31
+ const dir = process.cwd();
32
+ const path = `${dir}/package.json`;
33
+ addDevDep(path, ['typescript']);
34
+ }
35
+
36
+ module.exports.supplementTypescript = supplementTypescript;
@@ -0,0 +1,14 @@
1
+
2
+ const tsconfigContent =
3
+ {
4
+ "compilerOptions": {
5
+ "target": "ES6",
6
+ "module": "commonjs",
7
+ "outDir": "./app",
8
+ "strict": true,
9
+ "esModuleInterop": true
10
+ }
11
+ }
12
+
13
+
14
+ module.exports = tsconfigContent;
@@ -0,0 +1,66 @@
1
+ const {debug} = require('../config.json');
2
+ const jsonfile = require('jsonfile');
3
+ const fsExtra = require('fs-extra');
4
+
5
+ const defaultPackageContent = require('../genweb/generators/genPackage');
6
+ const defaultHtmlContent = require('../genweb/generators/genHtml');
7
+ const defaultGulpfileContent = require('../genweb/generators/genGulpfile');
8
+ const defaultBsconfigContent = require('../genweb/generators/genBsconfig');
9
+
10
+ const {
11
+ createDirectory,
12
+ createFile
13
+ } = require('../tools/tools');
14
+
15
+ const createWeb = () => {
16
+ const currentDirectory = process.cwd();
17
+
18
+ createDirectory(`${currentDirectory}/src`);
19
+ createDirectory(`${currentDirectory}/assets`);
20
+
21
+ createFile(`${currentDirectory}/src/style.css`, '');
22
+ createFile(`${currentDirectory}/src/app.js`, '');
23
+ createFile(`${currentDirectory}/README.md`, '# Sinto Project');
24
+
25
+ createPackageJsonFile(currentDirectory);
26
+ createIndexHtmlFile(currentDirectory);
27
+ createGulpfileJsFile(currentDirectory);
28
+ createBsconfigFile(currentDirectory);
29
+
30
+ console.log('Base directories and files created.');
31
+ };
32
+
33
+ const createPackageJsonFile = (directory) => {
34
+ const packageJsonPath = `${directory}/package.json`;
35
+ jsonfile.writeFileSync(packageJsonPath, defaultPackageContent, { spaces: 2 });
36
+ if(debug) {
37
+ console.log('package.json file created.');
38
+ }
39
+ }
40
+
41
+ const createIndexHtmlFile = (directory) => {
42
+ const indexHtmlPath = `${directory}/src/index.html`;
43
+ fsExtra.writeFileSync(indexHtmlPath, defaultHtmlContent);
44
+ if(debug)
45
+ console.log('index.html file created');
46
+ }
47
+
48
+ const createGulpfileJsFile = (directory) => {
49
+ const gulpfileJsPath = `${directory}/gulpfile.js`;
50
+ fsExtra.writeFileSync(gulpfileJsPath, defaultGulpfileContent);
51
+ if(debug)
52
+ console.log('gulpfile.js file created.');
53
+ }
54
+
55
+ const createBsconfigFile = (directory) => {
56
+ const bsconfigPath = `${directory}/bs-config.json`;
57
+ jsonfile.writeFileSync(bsconfigPath, defaultBsconfigContent, { spaces: 2 });
58
+ if(debug)
59
+ console.log('bs-config.json file created.');
60
+ }
61
+
62
+ module.exports.createWeb = createWeb;
63
+ module.exports.createPackageJsonFile = createPackageJsonFile;
64
+ module.exports.createIndexHtmlFile = createIndexHtmlFile;
65
+ module.exports.createGulpfileJsFile = createGulpfileJsFile;
66
+ module.exports.createBsconfigFile = createBsconfigFile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinto",
3
- "version": "1.3.1",
3
+ "version": "1.5.0",
4
4
  "description": "Website project development manager",
5
5
  "bin": {
6
6
  "sin": "sin.js"
@@ -12,8 +12,10 @@
12
12
  "license": "MIT",
13
13
  "dependencies": {
14
14
  "browser-sync": "^3.0.2",
15
+ "commander": "^12.1.0",
15
16
  "fs-extra": "^11.2.0",
16
17
  "gulp": "^5.0.0",
18
+ "jsonfile": "^6.1.0",
17
19
  "yargs": "^17.7.2"
18
20
  },
19
21
  "keywords": [
package/rmno/rmno.js ADDED
@@ -0,0 +1,13 @@
1
+ const fs = require('node:fs');
2
+
3
+ const rmno = () => {
4
+ const dir = 'node_modules';
5
+ fs.rm(dir,{ recursive: true, force: true } ,err => {
6
+ if (err) {
7
+ throw err;
8
+ }
9
+ console.log(`${dir} is deleted!`);
10
+ });
11
+ }
12
+
13
+ module.exports.rmno = rmno;
package/sin.js CHANGED
@@ -1,70 +1,78 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const {debug} = require('./config.json')
4
- const { exec } = require('child_process');
5
-
6
- const cli = require('./cli');
7
- const serve = require('./server');
3
+ const { Command } = require('commander');
4
+ const { createWeb } = require('./genweb/genweb');
5
+ const { server } = require('./startserver/server');
6
+ const { build } = require('./build/build');
7
+ const { rmno } = require('./rmno/rmno');
8
8
  const { createApi } = require('./haiserver/apigen');
9
9
  const { createWebpack } = require('./webpack/generate');
10
10
  const { createPuppeteerTest } = require('./gentest/generate');
11
+ const { supplementTypescript } = require('./gents/gents');
11
12
 
12
- const {
13
- createDirectory,
14
- createFile,
15
- createPackageJsonFile,
16
- createIndexHtmlFile,
17
- createGulpfileJsFile,
18
- createBsconfigFile
19
- } = require('./tools/tools');
13
+ const program = new Command();
20
14
 
15
+ program
16
+ .name('sin')
17
+ .description('Project handler')
18
+ .version('1.5.0');
21
19
 
22
- const init = () => {
23
- const currentDirectory = process.cwd();
20
+ program
21
+ .command('init')
22
+ .description('Initialize the web project')
23
+ .action(() => {
24
+ createWeb();
25
+ });
24
26
 
25
- createDirectory(`${currentDirectory}/src`);
26
- createDirectory(`${currentDirectory}/assets`);
27
+ program
28
+ .command('serve')
29
+ .description('Start develop server')
30
+ .option('-p, --port [port]', 'Server port number')
31
+ .action((options) => {
32
+ server(options);
33
+ });
27
34
 
28
- createFile(`${currentDirectory}/src/style.css`, '');
29
- createFile(`${currentDirectory}/src/app.js`, '');
30
- createFile(`${currentDirectory}/README.md`, '# Sinto Project');
31
-
32
- createPackageJsonFile(currentDirectory);
33
- createIndexHtmlFile(currentDirectory);
34
- createGulpfileJsFile(currentDirectory);
35
- createBsconfigFile(currentDirectory);
35
+ program
36
+ .command('build')
37
+ .description('Start build with Gulp')
38
+ .action(() => {
39
+ build();
40
+ });
36
41
 
37
- console.log('Base directories and files created.');
38
- };
42
+ program
43
+ .command('rmno')
44
+ .description('Delete node_modules directory')
45
+ .action(() => {
46
+ rmno();
47
+ });
39
48
 
40
- const build = (argv) => {
41
- exec('npx gulp')
42
- }
49
+ program
50
+ .command('api')
51
+ .description('REST API with hai-server')
52
+ .action(() => {
53
+ createApi();
54
+ });
43
55
 
44
- const rmno = (argv) => {
45
- console.log('Not implemented...')
46
- }
56
+ program
57
+ .command('webpack')
58
+ .description('Webpack client')
59
+ .action(() => {
60
+ createWebpack();
61
+ });
47
62
 
48
- const serverOptions = (yargs) => {
49
- return yargs.option('p', {
50
- alias: 'port',
51
- describe: 'Server port number'
52
- })
53
- }
63
+ program
64
+ .command('pup')
65
+ .description('Puppeteer test')
66
+ .action(async () => {
67
+ await createPuppeteerTest();
68
+ })
54
69
 
55
- cli.command('init', 'Initilize the project', {}, init);
56
- cli.command('serve', 'Start develop server', serverOptions, serve);
57
- cli.command('build', 'Start build with gulp', {}, build);
58
- cli.command('rmno', 'Delete node_modules directory', {}, rmno);
59
- cli.command('api', 'REST API with hai-server', {}, createApi);
60
- cli.command('webpack', 'Webpack client', {}, createWebpack);
61
- cli.command('pup', 'Puppeteer test', {}, createPuppeteerTest);
70
+ program
71
+ .command('ts')
72
+ .description('Supplement with TypeScript')
73
+ .action(() => {
74
+ supplementTypescript();
75
+ })
62
76
 
63
- const main = () => {
64
- argv = cli.parse();
65
- if (!argv._[0]) {
66
- console.log('Használja a "sin init" vagy a "sin serve" parancsot!');
67
- }
68
- };
69
77
 
70
- main();
78
+ program.parse();
@@ -29,10 +29,11 @@ const serve = (argv) => {
29
29
  readConfigFile(configFilePath, (error, config) => {
30
30
  if(error) {
31
31
  console.error('Error! The configuration file cannot be read!')
32
+ console.error(error)
32
33
  return;
33
34
  }
34
35
  initializeServer(argv, config)
35
36
  })
36
37
  };
37
38
 
38
- module.exports = serve;
39
+ module.exports.server = serve;
package/tools/dep.js ADDED
@@ -0,0 +1,77 @@
1
+ const {debug} = require('../config.json');
2
+ const jsonfile = require('jsonfile');
3
+ const util = require('util');
4
+ const exec = util.promisify(require('child_process').exec);
5
+
6
+ const addDep = async (filePath, packageNames) => {
7
+ await writeDependencies(filePath, packageNames, false);
8
+ }
9
+
10
+ const addDevDep = async (filePath, packageNames) => {
11
+ await writeDependencies(filePath, packageNames, true);
12
+ }
13
+
14
+ async function writeDependencies(filePath, packageNames, devDep) {
15
+ var obj = await readJsonFile(filePath);
16
+ obj = await addDependencies(obj, packageNames, devDep);
17
+ await writeJsonFile(filePath, obj);
18
+ }
19
+
20
+ async function readJsonFile(filePath) {
21
+ try {
22
+ const obj = await jsonfile.readFile(filePath);
23
+ if(debug) {
24
+ console.log(`Readed JSON file`);
25
+ }
26
+ return obj;
27
+ } catch (err) {
28
+ console.error(`Error! Failed to read ${filePath}`);
29
+ console.error(err);
30
+ }
31
+ }
32
+
33
+ async function addDependencies(obj, packageNames, devDep) {
34
+ for(const packageName of packageNames) {
35
+ try {
36
+ const newDependency = await getPackageInfo(packageName);
37
+ if(devDep) {
38
+ await Object.assign(obj.devDependencies, newDependency);
39
+ }else {
40
+ await Object.assign(obj.dependencies, newDependency);
41
+ }
42
+
43
+ } catch (err) {
44
+ console.error(`Error! Failed add packages!`);
45
+ console.error(err);
46
+ }
47
+ }
48
+ return obj;
49
+ }
50
+
51
+ async function getPackageInfo(packageName) {
52
+ try {
53
+ const { stdout, stderr } = await exec(`npm view ${packageName} version`);
54
+ if (stderr) {
55
+ throw new Error(`Error! Retrieving the version of package named ${packageName} failed: ${stderr}`);
56
+ }
57
+ const version = stdout.trim();
58
+ return { [packageName]: `^${version}` };
59
+ } catch (err) {
60
+ throw new Error(err.message);
61
+ }
62
+ }
63
+
64
+ async function writeJsonFile(path, obj) {
65
+ try {
66
+ await jsonfile.writeFile(path, obj, { spaces: 2});
67
+ if(debug) {
68
+ console.log(`Added new depencies`);
69
+ }
70
+ } catch (err) {
71
+ console.error('Error! Failed to write package.json:');
72
+ console.error(err);
73
+ }
74
+ }
75
+
76
+ module.exports.addDep = addDep;
77
+ module.exports.addDevDep = addDevDep;
package/tools/tools.js CHANGED
@@ -1,12 +1,5 @@
1
1
  const {debug} = require('../config.json');
2
2
  const fsExtra = require('fs-extra');
3
- const jsonfile = require('jsonfile');
4
- const fs = require('fs');
5
-
6
- const defaultPackageContent = require('../generators/genPackage');
7
- const defaultHtmlContent = require('../generators/genHtml');
8
- const defaultGulpfileContent = require('../generators/genGulpfile');
9
- const defaultBsconfigContent = require('../generators/genBsconfig');
10
3
 
11
4
  const createDirectory = (path) => {
12
5
  if (!fsExtra.existsSync(path)) {
@@ -20,38 +13,5 @@ const createFile = (path, content) => {
20
13
  }
21
14
  }
22
15
 
23
- const createPackageJsonFile = (directory) => {
24
- const packageJsonPath = `${directory}/package.json`;
25
- jsonfile.writeFileSync(packageJsonPath, defaultPackageContent, { spaces: 2 });
26
- if(debug) {
27
- console.log('package.json file created.');
28
- }
29
- }
30
-
31
- const createIndexHtmlFile = (directory) => {
32
- const indexHtmlPath = `${directory}/src/index.html`;
33
- fsExtra.writeFileSync(indexHtmlPath, defaultHtmlContent);
34
- if(debug)
35
- console.log('index.html file created');
36
- }
37
-
38
- const createGulpfileJsFile = (directory) => {
39
- const gulpfileJsPath = `${directory}/gulpfile.js`;
40
- fsExtra.writeFileSync(gulpfileJsPath, defaultGulpfileContent);
41
- if(debug)
42
- console.log('gulpfile.js file created.');
43
- }
44
-
45
- const createBsconfigFile = (directory) => {
46
- const bsconfigPath = `${directory}/bs-config.json`;
47
- jsonfile.writeFileSync(bsconfigPath, defaultBsconfigContent, { spaces: 2 });
48
- if(debug)
49
- console.log('bs-config.json file created.');
50
- }
51
-
52
16
  module.exports.createDirectory = createDirectory;
53
17
  module.exports.createFile = createFile;
54
- module.exports.createPackageJsonFile = createPackageJsonFile;
55
- module.exports.createIndexHtmlFile = createIndexHtmlFile;
56
- module.exports.createGulpfileJsFile = createGulpfileJsFile;
57
- module.exports.createBsconfigFile = createBsconfigFile;
package/cli.js DELETED
@@ -1,7 +0,0 @@
1
-
2
- const yargs = require('yargs/yargs')
3
- const { hideBin } = require('yargs/helpers')
4
-
5
- const cli = yargs(hideBin(process.argv));
6
-
7
- module.exports = cli;
File without changes
File without changes