Compare commits

...

3 Commits

Author SHA1 Message Date
214b113865 complete feature 2020-06-27 19:50:34 +02:00
336edb84b1 fix 2020-06-27 19:42:46 +02:00
d7d30fd417 carry previous date string 2020-06-27 19:36:46 +02:00
11 changed files with 104 additions and 38 deletions

21
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\index.js",
"outFiles": [
"${workspaceFolder}/**/*.js"
],
"console": "externalTerminal"
}
]
}

18
CHANGELOG.md Normal file
View File

@ -0,0 +1,18 @@
# Changelog
## 1.3.0
Copyright function: carry previous creation date to prevent unnecessary modifications
## 1.2.0
- Fully interactive snippets
- db migration generator removed (new snipped in development)
## 1.1.0
Knex database migration generator
## 1.0.0
initial version

2
Jenkinsfile vendored
View File

@ -5,7 +5,7 @@ pipeline {
VERSION = VersionNumber([ VERSION = VersionNumber([
versionNumberString: versionNumberString:
'${BUILDS_ALL_TIME}', '${BUILDS_ALL_TIME}',
versionPrefix: '1.2.', versionPrefix: '1.3.',
worstResultForIncrement: 'SUCCESS' worstResultForIncrement: 'SUCCESS'
]) ])
} }

View File

@ -1,6 +1,6 @@
# @sapphirecode/snippeteer # @sapphirecode/snippeteer
version: 1.2.x version: 1.3.x
macros for setting up projects or project parts macros for setting up projects or project parts

View File

@ -1,3 +1,10 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, June 2020
*/
'use strict'; 'use strict';
const https = require ('https'); const https = require ('https');

View File

@ -9,13 +9,18 @@ import { CopyrightOptions } from './copyright_options';
export class CopyrightGenerator { export class CopyrightGenerator {
public static get_copyright_notice ( public static get_copyright_notice (
opt: CopyrightOptions opt: CopyrightOptions,
date_str?: string
): string { ): string {
let notice = ''; let notice = '';
let date_string = date_str;
if (typeof date_str === 'undefined') {
const date = (new Date); const date = (new Date);
const dtf = new Intl.DateTimeFormat ('en', { month: 'long' }); const dtf = new Intl.DateTimeFormat ('en', { month: 'long' });
const year = date.getFullYear (); const year = date.getFullYear ();
const month = dtf.format (date); const month = dtf.format (date);
date_string = `${month} ${year}`;
}
if (opt.has_license) { if (opt.has_license) {
notice = `${'/*'} notice = `${'/*'}
@ -23,7 +28,7 @@ export class CopyrightGenerator {
* This file is part of ${opt.software} which is released under ${ * This file is part of ${opt.software} which is released under ${
opt.license}. opt.license}.
* See file 'LICENSE' for full license details. * See file 'LICENSE' for full license details.
* Created by ${opt.author} <${opt.email}>, ${month} ${year} * Created by ${opt.author} <${opt.email}>, ${date_string}
*/ */
`; `;
@ -31,7 +36,7 @@ export class CopyrightGenerator {
else { else {
notice = `${'/*'} notice = `${'/*'}
* Copyright (C) ${opt.company || opt.author} - All Rights Reserved * Copyright (C) ${opt.company || opt.author} - All Rights Reserved
* Created by ${opt.author} <${opt.email}>, ${month} ${year} * Created by ${opt.author} <${opt.email}>, ${date_string}
*/ */
`; `;

View File

@ -42,9 +42,7 @@ export default class Copyright implements Snippet {
await modify_json ((json) => { await modify_json ((json) => {
json.author = `${options.author} <${options.email}>`; json.author = `${options.author} <${options.email}>`;
json.license = options.has_license json.license = options.has_license ? options.license : 'UNLICENSED';
? options.license
: 'UNLICENSED';
return json; return json;
}); });
@ -59,11 +57,14 @@ export default class Copyright implements Snippet {
); );
} }
if (!this._loaded_from_config && await new Confirm ( if (
!this._loaded_from_config
&& (await new Confirm (
{ message: 'should those settings be saved for the next run?' } { message: 'should those settings be saved for the next run?' }
) )
.run () .run ()
.catch (DialogHandler.catch)) .catch (DialogHandler.catch))
)
this.save_options_file (); this.save_options_file ();
} }
@ -81,10 +82,9 @@ export default class Copyright implements Snippet {
this._options.software = await new Input ({ message: 'software name' }) this._options.software = await new Input ({ message: 'software name' })
.run () .run ()
.catch (DialogHandler.catch); .catch (DialogHandler.catch);
this._options.has_license = await new Confirm ({ this._options.has_license = await new Confirm (
message: { message: 'would you like to specify a license?' }
'would you like to specify a license?' )
})
.run () .run ()
.catch (DialogHandler.catch); .catch (DialogHandler.catch);
if (this._options.has_license) { if (this._options.has_license) {
@ -104,9 +104,7 @@ export default class Copyright implements Snippet {
this._options = null; this._options = null;
if (await fs.pathExists (file_path)) { if (await fs.pathExists (file_path)) {
const options = JSON.parse ( const options = JSON.parse (await fs.readFile (file_path, 'utf-8'));
await fs.readFile (file_path, 'utf-8')
);
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log (`author: ${options.author} console.log (`author: ${options.author}
@ -135,21 +133,23 @@ license: ${options.license}`);
); );
} }
private fix_file_license ( private fix_file_license (data: string, filename: string): string | null {
data: string, // eslint-disable-next-line max-len
filename: string const regex = /\/\*\s+\*\sCopyright[\s\S]*?(?:Created by.*?, (?<date>[a-z]+ [0-9]+)[\s\S]*?|\s)\*\/\n{0,2}/gui;
): string | null {
const regex = /\/\*\s+\*\sCopyright[\s\S]*?\*\/\n{0,2}/gu;
const shebang = /^#!.*?\n\n/gu; const shebang = /^#!.*?\n\n/gu;
const shebang_line = shebang.exec (data); const shebang_line = shebang.exec (data);
if (!(/\.(?:js|ts|mjs)$/u).test (filename) && !regex.test (data)) if (!(/\.(?:js|ts|mjs)$/u).test (filename) && !regex.test (data))
return null; return null;
return (shebang_line ? shebang_line[0] : '') const res = regex.exec (data);
return (
(shebang_line ? shebang_line[0] : '')
+ CopyrightGenerator.get_copyright_notice ( + CopyrightGenerator.get_copyright_notice (
this._options as CopyrightOptions this._options as CopyrightOptions,
res?.groups?.date
) )
+ data.replace (regex, '') + data.replace (regex, '')
.replace (shebang, ''); .replace (shebang, '')
);
} }
} }

View File

@ -1,3 +1,10 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, June 2020
*/
/* eslint-disable max-len */ /* eslint-disable max-len */
export function get_readme ( export function get_readme (
software: string, software: string,

View File

@ -1,3 +1,10 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, June 2020
*/
import { Confirm } from 'enquirer'; import { Confirm } from 'enquirer';
import { Snippet } from '../../Snippet'; import { Snippet } from '../../Snippet';
import { modify_json, apply_template } from '../../Helper'; import { modify_json, apply_template } from '../../Helper';

View File

@ -18,6 +18,7 @@
}, },
"files": [ "files": [
"/dist/", "/dist/",
"/lib/",
"LICENSE" "LICENSE"
], ],
"author": "Timo Hocker <timo@scode.ovh>", "author": "Timo Hocker <timo@scode.ovh>",

View File

@ -8,9 +8,9 @@
// "allowJs": true, /* Allow javascript files to be compiled. */ // "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */ // "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */ "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */ "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */ // "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist", /* Redirect output structure to the directory. */ "outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": "./lib", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ "rootDir": "./lib", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */