Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

ngx-deploy-npm

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-deploy-npm - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

engine/utils/fs-async.js

6

deploy/schema.json
{
"id": "Schema",
"title": "schema",
"description": "Deployment/Publishment of Angular CLI applications to NPM",
"description": "Publish your angular packages to npm by just run `npm deploy your-packages`",
"properties": {
"packageVersion": {
"type": "string",
"description": "The version that your package is going to be published. Ex: '1.3.5' '2.0.0-next.0'"
},
"tag": {

@@ -7,0 +11,0 @@ "type": "string",

46

engine/engine.js

@@ -10,7 +10,13 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const exec_async_1 = __importDefault(require("./utils/exec-async"));
const path = __importStar(require("path"));
const fs = __importStar(require("./utils/fs-async"));
const exec_async_1 = require("./utils/exec-async");
const defaults_1 = require("./defaults");

@@ -20,12 +26,16 @@ function run(dir, options, logger) {

try {
options = exports.prepareOptions(options, logger);
const commandToPublish = `npm publish ${dir} ${exports.getOptionsString(options)}`;
const { stdout, stderr } = yield exec_async_1.default(commandToPublish);
options = prepareOptions(options, logger);
if (options.packageVersion && !options.dryRun) {
yield setPackageVersion(dir, options);
}
const npmOptions = extractOnlyNPMOptions(options);
const commandToPublish = `npm publish ${dir} ${getOptionsString(npmOptions)}`;
const { stdout, stderr } = yield exec_async_1.execAsync(commandToPublish);
logger.info(stdout);
logger.info(stderr);
if (options.dryRun) {
yield logger.info('The options are:');
yield logger.info(JSON.stringify(options, null, 1));
logger.info('The options are:');
logger.info(JSON.stringify(options, null, 1));
}
yield logger.info('πŸš€ Successfully published via ngx-deploy-npm! Have a nice day!');
logger.info('πŸš€ Successfully published via ngx-deploy-npm! Have a nice day!');
}

@@ -39,2 +49,18 @@ catch (error) {

exports.run = run;
function setPackageVersion(dir, options) {
return __awaiter(this, void 0, void 0, function* () {
let packageContent = yield fs.readFileAsync(path.join(dir, 'package.json'), { encoding: 'utf8' });
let packageObj = JSON.parse(packageContent);
packageObj.version = options.packageVersion;
yield fs.writeFileAsync(path.join(dir, 'package.json'), JSON.stringify(packageObj, null, 4), { encoding: 'utf8' });
});
}
function extractOnlyNPMOptions({ access, tag, otp, dryRun }) {
return {
access,
tag,
otp,
dryRun
};
}
function prepareOptions(origOptions, logger) {

@@ -47,3 +73,2 @@ const options = Object.assign({}, defaults_1.defaults, origOptions);

}
exports.prepareOptions = prepareOptions;
function getOptionsString(options) {

@@ -62,3 +87,2 @@ return (Object.keys(options)

}
exports.getOptionsString = getOptionsString;
//# sourceMappingURL=engine.js.map

@@ -13,27 +13,62 @@ "use strict";

const defaults_1 = require("./defaults");
jest.mock('./utils/exec-async');
const execAsync = __importStar(require("./utils/exec-async"));
const exec = __importStar(require("./utils/exec-async"));
const fs = __importStar(require("./utils/fs-async"));
describe('engine', () => {
describe('getOptionsString', () => {
let options;
let expectedCmdStringOptions;
beforeEach(() => {
options = {
justAnExample: 'example',
anotherExample: 'example',
hello: 'hallo',
justAnUndefined: undefined
};
expectedCmdStringOptions =
'--just-an-example example --another-example example --hello hallo';
let dir;
let options;
afterEach(() => {
jest.clearAllMocks();
});
beforeEach(() => {
jest.spyOn(exec, 'execAsync').mockImplementation(() => Promise.resolve({
stdout: 'package published',
stderr: undefined
}));
});
beforeEach(() => {
dir = 'customDir';
});
it('should call NPM Publish with the right options', done => {
options = {
access: defaults_1.npmAccess.restricted,
tag: 'next',
otp: 'someValue',
configuration: 'stageConfig',
dryRun: true
};
const optionsOnCMD = `--access ${options.access} --tag ${options.tag} --otp ${options.otp} --dry-run ${options.dryRun}`;
engine
.run(dir, options, dev_kit_logger_1.logging)
.then(() => {
expect(exec.execAsync).toHaveBeenCalledWith(`npm publish ${dir} ${optionsOnCMD}`);
done();
})
.catch(err => fail('should be completed' + err));
});
it('should indicate that an error occurred when there is an error publishing the package', done => {
const customErr = 'custom err';
jest
.spyOn(exec, 'execAsync')
.mockImplementation(() => Promise.reject(customErr));
engine
.run(dir, options, dev_kit_logger_1.logging)
.then(() => fail('should enter in the catch section'))
.catch(err => {
expect(customErr).toEqual(err);
done();
});
it('should transform the camelCase options to CMD options', () => {
const transformedOptions = engine.getOptionsString(options);
expect(transformedOptions).toEqual(expectedCmdStringOptions);
});
describe('Options Management', () => {
it('should set the default options', done => {
const options = {};
const optionsOnCMD = `--access public`;
engine
.run(dir, options, dev_kit_logger_1.logging)
.then(() => {
expect(exec.execAsync).toHaveBeenCalledWith(`npm publish ${dir} ${optionsOnCMD}`);
done();
})
.catch(err => fail('should be completed' + err));
});
});
describe('prepareOptions', () => {
let options;
let expectedOptions;
it('should overwrite the default option dry-run', () => {
it('should overwrite the default option dry-run', done => {
const options = {

@@ -44,14 +79,13 @@ otp: 'random-text',

};
const expectedOptions = {
otp: 'random-text',
dryRun: true,
tag: 'random-tag',
access: defaults_1.npmAccess.public
};
const processedOptions = engine.prepareOptions(options, dev_kit_logger_1.logging);
expect(processedOptions).toEqual(expectedOptions);
const optionsOnCMD = `--access public --tag ${options.tag} --otp ${options.otp} --dry-run true`;
engine
.run(dir, options, dev_kit_logger_1.logging)
.then(() => {
expect(exec.execAsync).toHaveBeenCalledWith(`npm publish ${dir} ${optionsOnCMD}`);
done();
})
.catch(err => fail('should be completed' + err));
});
it('should overwrite the default option dry-run and access', () => {
it('should overwrite the default option dry-run and access', done => {
const options = {
otp: 'random-text',
dryRun: true,

@@ -61,54 +95,87 @@ tag: 'random-tag',

};
const expectedOptions = {
otp: 'random-text',
dryRun: true,
tag: 'random-tag',
access: defaults_1.npmAccess.restricted
};
const processedOptions = engine.prepareOptions(options, dev_kit_logger_1.logging);
expect(processedOptions).toEqual(expectedOptions);
const optionsOnCMD = `--access ${defaults_1.npmAccess.restricted} --tag ${options.tag} --dry-run true`;
engine
.run(dir, options, dev_kit_logger_1.logging)
.then(() => {
expect(exec.execAsync).toHaveBeenCalledWith(`npm publish ${dir} ${optionsOnCMD}`);
done();
})
.catch(err => fail('should be completed' + err));
});
});
describe('run', () => {
let customOptions;
let customOptionsCMD;
let dir;
let prepareOptionsSpy;
let getOptionsStringSpy;
describe('Package.json Feature', () => {
let myPackageJSON;
let expectedPackage;
let version;
let options;
beforeEach(() => {
customOptions = {
customOptions: 'random'
jest
.spyOn(fs, 'readFileAsync')
.mockImplementation(() => Promise.resolve(JSON.stringify(myPackageJSON)));
jest
.spyOn(fs, 'writeFileAsync')
.mockImplementation(() => Promise.resolve());
});
beforeEach(() => {
version = '1.0.1-next0';
myPackageJSON = {
name: 'ngx-deploy-npm',
version: 'boilerPlate',
description: 'Publish your angular packages to npm by just run `npm deploy your-packages`',
main: 'index.js'
};
customOptionsCMD = '--custom-options random';
dir = 'customDir';
prepareOptionsSpy = jest
.spyOn(engine, 'getOptionsString')
.mockReturnValue('');
getOptionsStringSpy = jest
.spyOn(engine, 'getOptionsString')
.mockReturnValue(customOptionsCMD);
expectedPackage = Object.assign({}, myPackageJSON, { version });
options = {
packageVersion: version
};
});
afterEach(function () {
jest.clearAllMocks();
});
it('should execute the command correctly', (done) => {
it('should write the version of the sent on the package.json', done => {
engine
.run(dir, customOptions, dev_kit_logger_1.logging)
.run(dir, options, dev_kit_logger_1.logging)
.then(() => {
expect(execAsync.default).toHaveBeenCalledWith(`npm publish ${dir} ${customOptionsCMD}`);
expect(fs.writeFileAsync).toHaveBeenCalledWith(`${dir}/package.json`, JSON.stringify(expectedPackage, null, 4), { encoding: 'utf8' });
done();
})
.catch(err => fail('should be completed' + err));
execAsync.resolve('npm output');
});
it('should throw an error if the command fail', (done) => {
const customErr = 'custom err';
it('should not write the version of the sent on the package.json if is on dry-run mode', done => {
options.dryRun = true;
engine
.run(dir, customOptions, dev_kit_logger_1.logging)
.then(() => fail('should enter in the catch section'))
.catch(err => {
expect(customErr).toEqual(err);
.run(dir, options, dev_kit_logger_1.logging)
.then(() => {
expect(fs.writeFileAsync).not.toHaveBeenCalled();
done();
})
.catch(err => fail('should be completed' + err));
});
describe('Errors', () => {
afterEach(() => {
jest.clearAllMocks();
});
execAsync.reject(customErr);
it('should throw an error if there is an error reading the package.json', done => {
const customErr = 'custom err';
jest
.spyOn(fs, 'readFileAsync')
.mockImplementation(() => Promise.reject(customErr));
engine
.run(dir, options, dev_kit_logger_1.logging)
.then(() => fail('should enter in the catch section'))
.catch(err => {
expect(customErr).toEqual(err);
done();
});
});
it('should throw an error if there is an error writing the package.json', done => {
const customErr = 'custom err';
jest
.spyOn(fs, 'writeFileAsync')
.mockImplementation(() => Promise.reject(customErr));
engine
.run(dir, options, dev_kit_logger_1.logging)
.then(() => fail('should enter in the catch section'))
.catch(err => {
expect(customErr).toEqual(err);
done();
});
});
});

@@ -115,0 +182,0 @@ });

@@ -8,4 +8,3 @@ "use strict";

const child_process_1 = require("child_process");
const execAsync = util_1.default.promisify(child_process_1.exec);
exports.default = execAsync;
exports.execAsync = util_1.default.promisify(child_process_1.exec);
//# sourceMappingURL=exec-async.js.map
{
"name": "ngx-deploy-npm",
"version": "1.1.1",
"version": "1.2.0",
"description": "Publish your angular packages to npm by just run `npm deploy your-packages`",

@@ -8,2 +8,3 @@ "main": "index.js",

"build": "rimraf dist && json2ts deploy/schema.json > deploy/schema.d.ts && tsc && copyfiles README.md builders.json collection.json package.json ngx-deploy-npm deploy/schema.json dist",
"link": "npm run build && cd dist && npm link && cd ..",
"test": "jest",

@@ -10,0 +11,0 @@ "test:debug": "node --inspect-brk=0.0.0.0 node_modules/.bin/jest --runInBand",

@@ -20,2 +20,3 @@ # ngx-deploy-npm πŸš€

- [--configuration](#--configuration)
- [--package-version](#--package-version)
- [--tag](#--tag)

@@ -41,3 +42,3 @@ - [--access](#--access)

This quick start assumes that you already an existing Angular project with a publishable package created and you already are logged in in npm using `npm login`
This quick start assumes that you already have an existing Angular project with a publishable package created and you already are logged in on npm using `npm login`

@@ -77,4 +78,4 @@ 1. Add `ngx-deploy-npm` to your project. It will configure all your publishable libraries present in the project

- Create a step with `run: npx ng deploy YOUR_LIBRARY`
- **NOTE:** You may want to execute an script that execute some pre steps before publishing and inside that script execute `ng deploy YOUR_LIBRARY`. If you want to make that script on JavaScript and put it on the package.json, **execute it using `npm` not with yarn**, there is an [issue](https://github.com/yarnpkg/yarn/issues/5683) associated with that
5. Enjoy your just released package πŸŽ‰πŸ“¦
- **NOTE:** You may want to execute a script that executes some pre-steps before publishing and inside that script execute `ng deploy YOUR_LIBRARY`. If you want to make that script on JavaScript and put it on the package.json, **execute it using `npm` not with yarn**, there is an [issue](https://github.com/yarnpkg/yarn/issues/5683) associated with that
5. **Enjoy your just released package πŸŽ‰πŸ“¦**

@@ -114,2 +115,11 @@ The job full example is

#### --package-version
- **optional**
- Default: Doesn't have any default value [string]
- Example:
- `ng deploy --package-version 2.3.4`
It's going to put that version on your `package.json` and publish the library with that version on NPM.
#### --tag

@@ -130,3 +140,3 @@

Tells the registry whether this package should be published as public or restricted. Only applies to scoped packages, which default to restricted. If you don’t have a paid account, you must publish with --access public to publish scoped packages.
Tells the registry whether this package should be published as public or restricted. It only applies to scoped packages, which default to restricted. If you don’t have a paid account, you must publish with --access public to publish scoped packages.

@@ -136,3 +146,3 @@ #### --otp

- **optional**
- Default: `public` (string)
- Default: Doesn't have any default value (string)
- Example:

@@ -159,2 +169,3 @@ - `ng deploy --otp TOKEN`

- dryRun
- packageVersion
- otp

@@ -190,3 +201,3 @@ - tag

### README, LICENCE and CHANGELOG
### README, LICENCE, and CHANGELOG

@@ -201,3 +212,3 @@ Those files must be in the root of the library. They are being copied by the builder at the moment of deployment.

This deployer do not bumps or creates a new version of the package, it just build the **package/library**, take the package.json as it and **publish** it.
This deployer doesn't bump or generates a new version of the package, it just builds the **package/library**, take the package.json as it and **publish** it. You can use [`--package-version`](#--package-version) option to change it.

@@ -230,6 +241,4 @@ ### Only publishable libraries are being configured

This take special context in [NX](https://nx.dev) environment.
This takes a special context on a [NX](https://nx.dev) environment.
**You must take care about the version by yourself. Maybe using a script that sets the version**
## 🏁 Next milestones <a name="next-milestones"></a>

@@ -245,3 +254,3 @@

- Add all the RFC proposals of [ngx-deploy-starter](https://github.com/angular-schule/ngx-deploy-starter)
- Custom README, LICENCE and CHANGELOG paths
- Custom README, LICENCE, and CHANGELOG paths

@@ -248,0 +257,0 @@ Your feature that's not on the list yet?

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc