Compare commits
No commits in common. "dde41c085ebaa7ba770f85c6d4ebca5b043ea1ab" and "c0c2881020de9414e3c624e3e521f255677e4ea0" have entirely different histories.
dde41c085e
...
c0c2881020
@ -13,10 +13,8 @@ async function apply_template (
|
|||||||
destination: string
|
destination: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const dst = path.join (process.cwd (), destination);
|
const dst = path.join (process.cwd (), destination);
|
||||||
if (!await fs.pathExists (dst)) {
|
if (!await fs.pathExists (dst))
|
||||||
await fs.mkdirp (path.dirname (dst));
|
|
||||||
await fs.writeFile (dst, contents);
|
await fs.writeFile (dst, contents);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type JSONMutator = {
|
type JSONMutator = {
|
||||||
@ -45,13 +43,22 @@ async function modify_json (
|
|||||||
*
|
*
|
||||||
* @param {string} command command to run
|
* @param {string} command command to run
|
||||||
* @param {string} folder folder to run in
|
* @param {string} folder folder to run in
|
||||||
|
* @returns {Promise<void>} promise
|
||||||
*/
|
*/
|
||||||
function run_command (command: string, folder = ''): void {
|
function run_command (command: string, folder = ''): Promise<void> {
|
||||||
// eslint-disable-next-line no-sync
|
return new Promise ((res) => {
|
||||||
child_process.execSync (
|
child_process.exec (
|
||||||
command,
|
command,
|
||||||
{ cwd: path.join (process.cwd (), folder), stdio: 'inherit' }
|
{ cwd: path.join (process.cwd (), folder) },
|
||||||
|
(err, stdout, stderr) => {
|
||||||
|
if (err)
|
||||||
|
throw err;
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log (stdout + stderr);
|
||||||
|
res ();
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export { modify_json, apply_template, run_command };
|
export { modify_json, apply_template, run_command };
|
||||||
|
11
lib/asset.d.ts
vendored
Normal file
11
lib/asset.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* 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>, April 2020
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare module '*.asset' {
|
||||||
|
const content: any;
|
||||||
|
export default content;
|
||||||
|
}
|
@ -1,102 +0,0 @@
|
|||||||
/* eslint-disable max-len */
|
|
||||||
|
|
||||||
const general = { jenkinsfile: '' };
|
|
||||||
const node = { jenkinsfile: '', js: '' };
|
|
||||||
|
|
||||||
general.jenkinsfile = `pipeline {
|
|
||||||
agent any
|
|
||||||
|
|
||||||
environment {
|
|
||||||
VERSION = VersionNumber([
|
|
||||||
versionNumberString:
|
|
||||||
'\${BUILDS_ALL_TIME}',
|
|
||||||
versionPrefix: '1.0.',
|
|
||||||
worstResultForIncrement: 'SUCCESS'
|
|
||||||
])
|
|
||||||
publish = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
stages {
|
|
||||||
stage('Setup') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
currentBuild.displayName = env.VERSION
|
|
||||||
}
|
|
||||||
echo 'Setting up test environment'
|
|
||||||
sh 'echo setup'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
post {
|
|
||||||
success {
|
|
||||||
script {
|
|
||||||
publish = sh script: "git log -1 | grep '\\\\[no publish\\\\]'", returnStatus: true
|
|
||||||
if (publish != 0) {
|
|
||||||
echo 'Deploying'
|
|
||||||
sh 'echo deploy'
|
|
||||||
} else {
|
|
||||||
echo 'Build successful, Commit not marked for deploying'
|
|
||||||
currentBuild.result = "UNSTABLE"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
node.jenkinsfile = `pipeline {
|
|
||||||
agent any
|
|
||||||
|
|
||||||
environment {
|
|
||||||
VERSION = VersionNumber([
|
|
||||||
versionNumberString:
|
|
||||||
'\${BUILDS_ALL_TIME}',
|
|
||||||
versionPrefix: '1.0.',
|
|
||||||
worstResultForIncrement: 'SUCCESS'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
stages {
|
|
||||||
stage('Building') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
currentBuild.displayName = env.VERSION
|
|
||||||
}
|
|
||||||
sh 'yarn ci \${VERSION}'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
node.js = `/* eslint-disable no-process-exit */
|
|
||||||
/* eslint-disable no-console */
|
|
||||||
/* eslint-disable no-sync */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const fs = require ('fs');
|
|
||||||
const child_process = require ('child_process');
|
|
||||||
|
|
||||||
const pkg = JSON.parse (fs.readFileSync ('package.json', 'utf-8'));
|
|
||||||
[
|
|
||||||
,, pkg.version
|
|
||||||
] = process.argv;
|
|
||||||
fs.writeFileSync ('package.json', JSON.stringify (pkg, null, 2));
|
|
||||||
|
|
||||||
child_process.execSync ('yarn lint', { stdio: 'inherit' });
|
|
||||||
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.test === 'string')
|
|
||||||
child_process.execSync ('yarn test', { stdio: 'inherit' });
|
|
||||||
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.compile === 'string')
|
|
||||||
child_process.execSync ('yarn compile', { stdio: 'inherit' });
|
|
||||||
|
|
||||||
child_process.exec ('git log -1 | grep \\'\\\\[no publish\\\\]\\'')
|
|
||||||
.addListener ('exit', (code) => {
|
|
||||||
if (code === 0) {
|
|
||||||
console.log ('build not marked for deployment');
|
|
||||||
process.exit (1);
|
|
||||||
}
|
|
||||||
else { child_process.execSync ('yarn publish'); }
|
|
||||||
});
|
|
||||||
`;
|
|
||||||
|
|
||||||
export { general, node };
|
|
@ -9,9 +9,11 @@ import { Confirm } from 'enquirer';
|
|||||||
import { Snippet } from '../../Snippet';
|
import { Snippet } from '../../Snippet';
|
||||||
import { apply_template, modify_json } from '../../Helper';
|
import { apply_template, modify_json } from '../../Helper';
|
||||||
|
|
||||||
import { general, node } from './Assets';
|
import node_js from './template/node/jenkins.js.asset';
|
||||||
|
import node_jenkinsfile from './template/node/Jenkinsfile.asset';
|
||||||
|
import general_jenkinsfile from './template/general/Jenkinsfile.asset';
|
||||||
|
|
||||||
export default class Jenkins implements Snippet {
|
export class Jenkins implements Snippet {
|
||||||
public async start (): Promise<void> {
|
public async start (): Promise<void> {
|
||||||
const is_node = await new Confirm ({
|
const is_node = await new Confirm ({
|
||||||
message: 'is the current project using nodejs?',
|
message: 'is the current project using nodejs?',
|
||||||
@ -20,8 +22,8 @@ export default class Jenkins implements Snippet {
|
|||||||
.run ();
|
.run ();
|
||||||
|
|
||||||
if (is_node) {
|
if (is_node) {
|
||||||
await apply_template (node.js, 'jenkins.js');
|
await apply_template (node_js, 'jenkins.js');
|
||||||
await apply_template (node.jenkinsfile, 'Jenkinsfile');
|
await apply_template (node_jenkinsfile, 'Jenkinsfile');
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
await modify_json ((obj: any): any => {
|
await modify_json ((obj: any): any => {
|
||||||
obj.scripts.ci = 'yarn && node jenkins.js';
|
obj.scripts.ci = 'yarn && node jenkins.js';
|
||||||
@ -29,7 +31,7 @@ export default class Jenkins implements Snippet {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await apply_template (general.jenkinsfile, 'Jenkinsfile');
|
await apply_template (general_jenkinsfile, 'Jenkinsfile');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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>, April 2020
|
||||||
|
*/
|
||||||
|
|
||||||
/* eslint-disable no-process-exit */
|
/* eslint-disable no-process-exit */
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
/* eslint-disable no-sync */
|
/* eslint-disable no-sync */
|
@ -1,31 +0,0 @@
|
|||||||
const eslintrc = `module.exports = {
|
|
||||||
env: {
|
|
||||||
commonjs: true,
|
|
||||||
es6: true,
|
|
||||||
node: true
|
|
||||||
},
|
|
||||||
extends: [
|
|
||||||
'@scode'
|
|
||||||
],
|
|
||||||
globals: {
|
|
||||||
Atomics: 'readonly',
|
|
||||||
SharedArrayBuffer: 'readonly'
|
|
||||||
},
|
|
||||||
parserOptions: {
|
|
||||||
ecmaVersion: 2018
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const gitignore = `/node_modules/
|
|
||||||
/dist/
|
|
||||||
/.nyc_output/
|
|
||||||
/coverage/
|
|
||||||
`;
|
|
||||||
|
|
||||||
const index = '';
|
|
||||||
|
|
||||||
const npmrc = `@scode:registry=https://npm.scode.ovh
|
|
||||||
`;
|
|
||||||
|
|
||||||
export { eslintrc, gitignore, index, npmrc };
|
|
@ -11,9 +11,12 @@ import { Snippet } from '../../Snippet';
|
|||||||
import { apply_template, modify_json, run_command } from '../../Helper';
|
import { apply_template, modify_json, run_command } from '../../Helper';
|
||||||
|
|
||||||
|
|
||||||
import { eslintrc, gitignore, index, npmrc } from './Assets';
|
import eslintrc from './template/eslintrc.asset';
|
||||||
|
import npmrc from './template/npmrc.asset';
|
||||||
|
import index from './template/index.asset';
|
||||||
|
import gitignore from './template/gitignore.asset';
|
||||||
|
|
||||||
export default class Node implements Snippet {
|
export class Node implements Snippet {
|
||||||
public async start (): Promise<void> {
|
public async start (): Promise<void> {
|
||||||
const folder = await new Input (
|
const folder = await new Input (
|
||||||
{ message: 'project name (leave empty for current folder):' }
|
{ message: 'project name (leave empty for current folder):' }
|
||||||
@ -25,9 +28,9 @@ export default class Node implements Snippet {
|
|||||||
await apply_template (index, path.join (folder, 'index.js'));
|
await apply_template (index, path.join (folder, 'index.js'));
|
||||||
await apply_template (gitignore, path.join (folder, '.gitignore'));
|
await apply_template (gitignore, path.join (folder, '.gitignore'));
|
||||||
|
|
||||||
run_command ('git init', folder);
|
await run_command ('git init', folder);
|
||||||
run_command ('yarn init -y', folder);
|
await run_command ('yarn init -y', folder);
|
||||||
run_command (
|
await run_command (
|
||||||
'yarn add --dev @scode/eslint-config eslint nyc ava',
|
'yarn add --dev @scode/eslint-config eslint nyc ava',
|
||||||
folder
|
folder
|
||||||
);
|
);
|
||||||
|
24
lib/snippets/node/template/eslintrc.asset
Normal file
24
lib/snippets/node/template/eslintrc.asset
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* 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>, April 2020
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
commonjs: true,
|
||||||
|
es6: true,
|
||||||
|
node: true
|
||||||
|
},
|
||||||
|
extends: [
|
||||||
|
'@scode'
|
||||||
|
],
|
||||||
|
globals: {
|
||||||
|
Atomics: 'readonly',
|
||||||
|
SharedArrayBuffer: 'readonly'
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 2018
|
||||||
|
}
|
||||||
|
}
|
4
lib/snippets/node/template/gitignore.asset
Normal file
4
lib/snippets/node/template/gitignore.asset
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
/node_modules/
|
||||||
|
/dist/
|
||||||
|
/.nyc_output/
|
||||||
|
/coverage/
|
7
lib/snippets/node/template/index.asset
Normal file
7
lib/snippets/node/template/index.asset
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* 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>, April 2020
|
||||||
|
*/
|
||||||
|
|
1
lib/snippets/node/template/npmrc.asset
Normal file
1
lib/snippets/node/template/npmrc.asset
Normal file
@ -0,0 +1 @@
|
|||||||
|
@scode:registry=https://npm.scode.ovh
|
@ -16,16 +16,15 @@
|
|||||||
"url": "git@git.scode.ovh:timo/snippeteer"
|
"url": "git@git.scode.ovh:timo/snippeteer"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"/dist/",
|
"/snippets/",
|
||||||
"/assets/",
|
|
||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"author": "Timo Hocker",
|
"author": "Timo Hocker",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@scode/eslint-config-ts": "^1.0.21",
|
"@scode/eslint-config-ts": "^1.0.19",
|
||||||
"@types/fs-extra": "^8.1.0",
|
"@types/fs-extra": "^8.1.0",
|
||||||
"@types/node": "^13.13.0",
|
"@types/node": "^13.11.1",
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user